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?