WiFi state machine and timings ...

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

WiFi state machine and timings ...

Postby kolban » Wed Jan 18, 2017 6:48 pm

Ive been fighting "weirdness" in a WiFi based app .. the logic of my app had been:

Code: Select all

tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA);
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo);
esp_wifi_set_mode(WIFI_MODE_STA);
esp_wifi_set_config(WIFI_IF_STA, &sta_config);
esp_wifi_start();
esp_wifi_connect();
Something I've done dozens of times. However this time it wasn't working. I examined the APIs and couldn't see any changes I had made that would cause a problem. The symptom was that at the call to "esp_wifi_set_mode" I saw a message stating:

Code: Select all

I (8062) wifi: rx_ba=1 tx_ba=1

I (8062) wifi: mode : sta (24:0a:c4:00:00:94)
D (8062) event: SYSTEM_EVENT_STA_START
V (8062) event: enter default callback
But then no further ESP32 messages. My own app log was showing that the routine had come to an end. I copied and pasted the code to another program and it worked perfectly. I couldn't for the life of me figure out what what was going on. On a wild hunch, I added a 2 second vTaskDelay() between each of these API calls .... and it started working. It "feels" like I have a race condition at play .... if I were to guess, the esp_wifi_start() hadn't "completed" before the call to "esp_wifi_connect()". This is all WAY above my paygrade ... does anyone have any thoughts on this? Do we have to wait for the completion of a SYSTEM_EVENT_STA_START before calling start or connect?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: WiFi state machine and timings ...

Postby kolban » Wed Jan 18, 2017 7:21 pm

I have a feeling that "something may have changed" relatively recently as this is a new symptom ... your messages match exactly what I saw before adding the delays.
Last edited by kolban on Wed Jan 18, 2017 7:27 pm, edited 1 time in total.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: WiFi state machine and timings ...

Postby kolban » Wed Jan 18, 2017 7:28 pm

Did adding the delays help ... as a workaround perhaps? (I'm gonna be on calls all day ... feel free to raise an issue or else I can when the evening is here).
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: Baidu [Spider] and 143 guests