I see that if I send a UDP packet, then deep sleep, the message does not arrive (probably was not sent).
Is there a way (similar to 'uart_tx_wait_idle()' for the uart) to check that the wifi is idle?
how to check that the wifi is idle?
-
- Posts: 15
- Joined: Wed Apr 12, 2017 8:30 pm
Re: how to check that the wifi is idle?
Check out "port/netif/wlanif.c". This is the arch-specific implementation of the "wlan" interface for lwip. "low_level_output" is the function that gets called by lwip when lwip has an IP packet to send, such as when your program wants to send a UDP datagram. "esp_wifi_internal_tx" is the function (defined in libnet80211?) that gets called to actually put IP packets into the WiFi driver. As best as I can tell there isn't a corresponding "esp_wifi_internal_*" function that would let you know when the WiFi driver's tx queue is empty.
In your shoes, I would either implement an ACK, or wait an appropriate amount of time.. maybe 100ms?
In your shoes, I would either implement an ACK, or wait an appropriate amount of time.. maybe 100ms?
Re: how to check that the wifi is idle?
Yes @edmund-huber
ATM I am waiting 30ms on the esp8266, 50ms on esp32 (not yet well tuned). Some packets loss is acceptable (well, UDP after all).
I am trying to save every possible ms (it runs on battery) and wasting time by waiting blindly feels bad. I hoped the ESP32 IDF will improve this over the ESP8266 SDK.
cheers
ATM I am waiting 30ms on the esp8266, 50ms on esp32 (not yet well tuned). Some packets loss is acceptable (well, UDP after all).
I am trying to save every possible ms (it runs on battery) and wasting time by waiting blindly feels bad. I hoped the ESP32 IDF will improve this over the ESP8266 SDK.
cheers
-
- Posts: 15
- Joined: Wed Apr 12, 2017 8:30 pm
Re: how to check that the wifi is idle?
One way this (hypothetical) "esp_wifi_internal_tx_is_empty" function could be implemented would be to also have a "esp_internal_tx_mark_bottom" which would set some inconsequential bit in the link layer (if it's possible) or the IP header of the last entry in the tx queue - some bit that is set for no other reason. "esp_wifi_internal_tx_is_empty" would return truthy if no entries in the tx queue have that bit set, or if the tx queue is empty. So it would work like:
Anyway, this stuff is locked away in the closed source libraries so we can only speculate how we might add something to it.
Code: Select all
udp_sendto(..);
// Mark the bottom of the WiFi tx queue. This comes after the udp_sendto() so maybe your datagram has already been sent. Anyway, we'll checkpoint where transmission is at right now.
esp_internal_tx_mark_bottom();
// Wait until the marked tx entry is out of the tx queue. The UDP packet has certainly been sent.
while (!esp_internal_tx_is_empty()) {
vTaskDelay(.. 5ms ..);
}
Re: how to check that the wifi is idle?
Try opening an issue on github, more likely to get a fix.
Who is online
Users browsing this forum: No registered users and 125 guests