how to see ESPNOW send error code?

wjquigs
Posts: 7
Joined: Fri Aug 11, 2023 9:41 pm

how to see ESPNOW send error code?

Postby wjquigs » Wed Jun 19, 2024 4:49 am

Two questions: first, I am sending a small (12 byte) struct from one ESP32 to another, and returning an ack. The exchange frequently fails. The esp_now_send() never fails, and always returns ESP_OK. However, the send callback returns failure most of the time. When I check the status in the callback, it's either ESP_NOW_SEND_SUCCESS (occasionally) or ESP_NOW_SEND_FAIL (usually).
In esp_now.h, there are a lot of specific error codes for different conditions. How do I get access to the error code causing my failure? The send always returns success, and then the failed callback doesn't give any useful information.

Second question: I'm hosting a small web site for device/sensor status (sent via SSE/Javascript), as well as OTA updates and Webserial. I suspect there's too much TCP/HTTP traffic going out and the ESPNOW packets are squashed. Are there any good ways to broker traffic between ESPNOW and everything else? Obviously I can shut off the web service but I would like to have both. And I can switch ESPNOW to raw UDP or TCP, but I would like the two devices to be able to communicate even when they are not connected to wifi (the devices will go on a boat where there may sometimes be wifi and frequently there will not but they still need to communicate). I could switch to TCP when connected to a network and switch back to ESPNOW otherwise, but that's a lot of additional work. It would be nice if they could coexist.

Environment: VS Code + PIO + Arduino.

MicroController
Posts: 1734
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: how to see ESPNOW send error code?

Postby MicroController » Wed Jun 19, 2024 1:59 pm

wjquigs wrote:
Wed Jun 19, 2024 4:49 am
The esp_now_send() never fails, and always returns ESP_OK. However, the send callback returns failure most of the time. When I check the status in the callback, it's either ESP_NOW_SEND_SUCCESS (occasionally) or ESP_NOW_SEND_FAIL (usually).
In esp_now.h, there are a lot of specific error codes for different conditions. How do I get access to the error code causing my failure? The send always returns success, and then the failed callback doesn't give any useful information.
Seems like that's all the information you get. ESP-NOW works asynchronously, i.e. you enqueue data to be sent via esp_now_send(), transmission and re-transmission happen 'in the background', and you are notified via callback about the outcome when it's done.
If you get ESP_NOW_SEND_FAIL in the callback, https://docs.espressif.com/projects/esp ... p-now-data applies:
Several reasons can lead to ESP-NOW fails to send data. For example, the destination device does not exist; the channels of the devices are not the same; the action frame is lost when transmitting on the air, etc.
I suspect there's too much TCP/HTTP traffic going out and the ESPNOW packets are squashed.
I don't think that's the issue.

wjquigs
Posts: 7
Joined: Fri Aug 11, 2023 9:41 pm

Re: how to see ESPNOW send error code?

Postby wjquigs » Fri Jun 21, 2024 6:38 pm

Thanks, that was helpful. It looks like my problem is more about channel selection on my mesh network.

MicroController
Posts: 1734
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: how to see ESPNOW send error code?

Postby MicroController » Fri Jun 21, 2024 7:09 pm

wjquigs wrote:
Fri Jun 21, 2024 6:38 pm
It looks like my problem is more about channel selection on my mesh network.
IIRC, ESP-NOW uses whatever channel the WiFi is currently using, so yes, controlling the WiFi channel is required for successful ESP-NOW communication.

Who is online

Users browsing this forum: No registered users and 181 guests