From eaba8294b336051a7fac9b7da26676aecd0e702e Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 14 Jul 2024 16:23:46 -0500 Subject: [PATCH] Conformed SpanPoint to small change in ESP-NOW in Arduino-ESP32 version 3 Reflects small change to ESP-NOW data receive callback function. Also updated examples to use Network instead of WiFi to obtain MAC address prior to WiFi being setup/used. --- .../RemoteSensors/RemoteDevice/RemoteDevice.ino | 4 ++-- .../RemoteSensors/RemoteTempSensor/RemoteTempSensor.ino | 2 +- src/HomeSpan.cpp | 5 +++-- src/HomeSpan.h | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/Other Examples/RemoteSensors/RemoteDevice/RemoteDevice.ino b/examples/Other Examples/RemoteSensors/RemoteDevice/RemoteDevice.ino index 7dba05b..8cfb203 100644 --- a/examples/Other Examples/RemoteSensors/RemoteDevice/RemoteDevice.ino +++ b/examples/Other Examples/RemoteSensors/RemoteDevice/RemoteDevice.ino @@ -57,12 +57,12 @@ void setup() { Serial.begin(115200); delay(1000); - Serial.printf("\n\nThis is a REMOTE Device with MAC Address = %s\n",WiFi.macAddress().c_str()); + Serial.printf("\n\nThis is a REMOTE Device with MAC Address = %s\n",Network.macAddress().c_str()); Serial.printf("NOTE: This MAC Address must be entered into the corresponding SpanPoint() call of the MAIN Device.\n\n"); // In the line below, replace the MAC Address with that of your MAIN HOMESPAN DEVICE - mainDevice=new SpanPoint("84:CC:A8:11:B4:84",sizeof(float),0); // create a SpanPoint with send size=sizeof(float) and receive size=0 + mainDevice=new SpanPoint("AC:67:B2:77:42:20",sizeof(float),0); // create a SpanPoint with send size=sizeof(float) and receive size=0 homeSpan.setLogLevel(1); } diff --git a/examples/Other Examples/RemoteSensors/RemoteTempSensor/RemoteTempSensor.ino b/examples/Other Examples/RemoteSensors/RemoteTempSensor/RemoteTempSensor.ino index 63d5931..0a0cf46 100644 --- a/examples/Other Examples/RemoteSensors/RemoteTempSensor/RemoteTempSensor.ino +++ b/examples/Other Examples/RemoteSensors/RemoteTempSensor/RemoteTempSensor.ino @@ -70,7 +70,7 @@ void setup() { homeSpan.setLogLevel(1); Serial.begin(115200); delay(1000); - Serial.printf("Starting Remote Temperature Sensor. MAC Address of this device = %s\n",WiFi.macAddress().c_str()); + Serial.printf("Starting Remote Temperature Sensor. MAC Address of this device = %s\n",Network.macAddress().c_str()); #endif // In the line below, replace the MAC Address with that of your MAIN HOMESPAN DEVICE diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 383930a..02b289a 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -2711,8 +2711,9 @@ boolean SpanPoint::send(const void *data){ /////////////////////////////// -//void SpanPoint::dataReceived(const uint8_t *mac, const uint8_t *incomingData, int len){ -void SpanPoint::dataReceived(const esp_now_recv_info *mac, const uint8_t *incomingData, int len){ +void SpanPoint::dataReceived(const esp_now_recv_info *info, const uint8_t *incomingData, int len){ + + const uint8_t *mac=info->src_addr; auto it=SpanPoints.begin(); for(;it!=SpanPoints.end() && memcmp((*it)->peerInfo.peer_addr,mac,6)!=0; it++); diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 58f9e71..1b95977 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -807,7 +807,7 @@ class SpanPoint { static QueueHandle_t statusQueue; // queue for communication between SpanPoint::dataSend and SpanPoint::send static nvs_handle pointNVS; // NVS storage for channel number (only used for remote devices) - static void dataReceived(const esp_now_recv_info *mac, const uint8_t *incomingData, int len); + static void dataReceived(const esp_now_recv_info *info, const uint8_t *incomingData, int len); static void init(const char *password="HomeSpan"); static void setAsHub(){isHub=true;} static uint8_t nextChannel();