ESP Now - Wrong data in structure
Posted: Wed Mar 20, 2024 8:08 am
Hi there,
I'm about to build my own whether station and so on and multiple controllers should communicate with each other. So I'm now starting to use the ESP-NOW protocol.
To my problem the sender (Wemos D1 Mini) sends the data which is received in a "normal" ESP8266.
The data is packed into a structure, which is declared in both CPUs
Here some code snippets from sender and receiver and the corresponding Serial Monitor output
The sender (D1 Mini)
Following code is in the Monitor:
Nevertheless the same data is interpreted on receiver side in a different way.
Is there any different memory setting between Wemos D1 and "normal" ESP8266 or can something be configured in Arduino IDE?
I'm running out of ideas and assume there is any byteswap, memory gap or similar.
I'm about to build my own whether station and so on and multiple controllers should communicate with each other. So I'm now starting to use the ESP-NOW protocol.
To my problem the sender (Wemos D1 Mini) sends the data which is received in a "normal" ESP8266.
The data is packed into a structure, which is declared in both CPUs
Code: Select all
typedef struct dht_message{
uint8_t id;
float temp;
float humi;
} dht_message;
The sender (D1 Mini)
Code: Select all
dht_message dhtData;
dhtData.id = 1;
dhtData.temp = DhtValues::temp;
dhtData.humi = DhtValues::humi;
uint8_t debugData[sizeof(dht_message)+1];
memcpy(&debugData, &dhtData, sizeof(dht_message));
for (int i=0; i< sizeof(dht_message); i++) {Serial.print(debugData[i]);} Serial.println();
Serial.println(String(dhtData.id) + " ; " + String(dhtData.temp) + " ; " + String(dhtData.humi) );
esp_now_send(loggerAddress, (uint8_t *) &dhtData, sizeof(dht_message));
On the receiver side (ESP8266)08:43:01.068 -> 10001541531696551518366
08:43:01.068 -> 1 ; 21.20 ; 52.80
Code: Select all
void espnowReceived(uint8_t * mac, uint8_t *incomingData, uint8_t len){
dht_message recData;
Serial.println("Message length:" + String(len));
for (int i=0; i<len; i++){ Serial.print(incomingData[i]);}
Serial.println();
memcpy(&recData, incomingData, sizeof(incomingData));
if (recData.id <2){
SensorValues::temp[recData.id]= recData.temp;
SensorValues::humi[recData.id]= recData.humi;
Serial.println ("ID: " + String(recData.id) + " | Temp: "+ String(recData.temp) + " | Humi: " + String(recData.humi) );
As far as I can see the communication is running as it should also the raw data is transfered successful.08:43:01.075 -> Message length:12
08:43:01.075 -> 10001541531696551518366
08:43:01.149 -> ID: 1 | Temp: 2.00 | Humi: 2.00
Nevertheless the same data is interpreted on receiver side in a different way.
Is there any different memory setting between Wemos D1 and "normal" ESP8266 or can something be configured in Arduino IDE?
I'm running out of ideas and assume there is any byteswap, memory gap or similar.