how to check that the wifi is idle?

eyaleb
Posts: 31
Joined: Sun May 14, 2017 6:54 am

how to check that the wifi is idle?

Postby eyaleb » Sat Jun 03, 2017 5:01 am

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?

edmund-huber
Posts: 15
Joined: Wed Apr 12, 2017 8:30 pm

Re: how to check that the wifi is idle?

Postby edmund-huber » Sat Jun 03, 2017 6:47 am

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?

eyaleb
Posts: 31
Joined: Sun May 14, 2017 6:54 am

Re: how to check that the wifi is idle?

Postby eyaleb » Sun Jun 04, 2017 2:01 pm

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

edmund-huber
Posts: 15
Joined: Wed Apr 12, 2017 8:30 pm

Re: how to check that the wifi is idle?

Postby edmund-huber » Sun Jun 04, 2017 8:48 pm

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:

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 ..);
}
Anyway, this stuff is locked away in the closed source libraries so we can only speculate how we might add something to it.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: how to check that the wifi is idle?

Postby WiFive » Sun Jun 04, 2017 10:28 pm

Try opening an issue on github, more likely to get a fix.

Who is online

Users browsing this forum: No registered users and 129 guests