ESP-NOW continue to send data if it fails
Posted: Wed Jun 21, 2023 5:18 pm
I am using 3 ESP32's and talking between the three of them. I am only sending sensor data, but sometimes it isn't received.
I tried to use the "result == ESP_OK" to determine if the message was received, if not, continue to send until it is received, but that doesn't seem to work. Am I missing something? Or am I better off just sending continuously? That doesn't seem to be the best way to do things.
Here is a chunk of my code that verifies if a variable changes so I know if the data sent was received.
if(myData.g != Oldg){
esp_err_t result = esp_now_send(Tower_ESP, (uint8_t *) &myData, sizeof(myData));
if (result == ESP_OK) {
Oldg = myData.g;
Serial.println("Sending confirmed-4.5");
}
else {
Serial.println("Sending error-4.5");
}
}
It seems no matter what I do it will only send the data once, even when I know it wasn't received, so is the ESP==OK only saying that the data was sent whether or not it was received?
Do I need to send a confirmation from the receive ESP to verify it got the data? If that's the case, then I think I will just send constantly, this is getting messy the way it is.
I was going to put the ESP in Long Range mode, hopefully that will help with the packet loss, but I haven't found much information about how much better that works, or simple code to set it up. What little I found had drastically different code.
Thanks for any help.
I tried to use the "result == ESP_OK" to determine if the message was received, if not, continue to send until it is received, but that doesn't seem to work. Am I missing something? Or am I better off just sending continuously? That doesn't seem to be the best way to do things.
Here is a chunk of my code that verifies if a variable changes so I know if the data sent was received.
if(myData.g != Oldg){
esp_err_t result = esp_now_send(Tower_ESP, (uint8_t *) &myData, sizeof(myData));
if (result == ESP_OK) {
Oldg = myData.g;
Serial.println("Sending confirmed-4.5");
}
else {
Serial.println("Sending error-4.5");
}
}
It seems no matter what I do it will only send the data once, even when I know it wasn't received, so is the ESP==OK only saying that the data was sent whether or not it was received?
Do I need to send a confirmation from the receive ESP to verify it got the data? If that's the case, then I think I will just send constantly, this is getting messy the way it is.
I was going to put the ESP in Long Range mode, hopefully that will help with the packet loss, but I haven't found much information about how much better that works, or simple code to set it up. What little I found had drastically different code.
Thanks for any help.