Why is it not good practice to call esp_wifi_connect() after esp_wifi_disconnect()?
Re: Why is it not good practice to call esp_wifi_connect() after esp_wifi_disconnect()?
Calling esp_wifi_connect() immediately after esp_wifi_disconnect() can lead to unpredictable behavior and potential conflicts in the Wi-Fi connection process. It's important to allow sufficient time for the disconnection process to complete before initiating a new connection to ensure stability and avoid potential race conditions or resource conflicts.
-
- Posts: 9727
- Joined: Thu Nov 26, 2015 4:08 am
Re: Why is it not good practice to call esp_wifi_connect() after esp_wifi_disconnect()?
Because esp_wifi_disconnect() doesn't disconnect WiFi and then return; rather it tells the WiFi stack to initiate a disconnect. The WiFi stack will then in the background go through all things needed to disconnect gracefully (e.g. inform the AP that the connection is broken) and will finally return an event telling you the ESP is actually disconnected. If you call esp_wifi_connect() directly after esp_wifi_disconnect() (without waiting for that event), the disconnect procedure might still be underway and results will be unpredictable.
Re: Why is it not good practice to call esp_wifi_connect() after esp_wifi_disconnect()?
@ESP_Sprite - so what is an appropriate amount of time to allow for esp_wifi_disconnect() and corresponding code to work its magic before calling esp_wifi_connect() again? I ask because I've waited as long as 5 minutes (which I think is long enough) after calling esp_wifi_disconnect() before re-trying esp_wifi_connect(), and the alternating success/failure/success ... pattern described in my earlier post persists.
Also, what event is emitted once the wifi disconnection is completed so that we can prevent esp_wifi_connect() from happening again till this event is emitted?
Also, what event is emitted once the wifi disconnection is completed so that we can prevent esp_wifi_connect() from happening again till this event is emitted?
-
- Posts: 9727
- Joined: Thu Nov 26, 2015 4:08 am
Re: Why is it not good practice to call esp_wifi_connect() after esp_wifi_disconnect()?
Specifically the WIFI_EVENT_STA_DISCONNECTED event. See e.g. this WiFi example for an illustration on how to reconnect after a disconnect.karunt wrote: ↑Fri May 10, 2024 1:44 pm@ESP_Sprite - so what is an appropriate amount of time to allow for esp_wifi_disconnect() and corresponding code to work its magic before calling esp_wifi_connect() again? I ask because I've waited as long as 5 minutes (which I think is long enough) after calling esp_wifi_disconnect() before re-trying esp_wifi_connect(), and the alternating success/failure/success ... pattern described in my earlier post persists.
Also, what event is emitted once the wifi disconnection is completed so that we can prevent esp_wifi_connect() from happening again till this event is emitted?
Who is online
Users browsing this forum: Bing [Bot], Gaston1980 and 89 guests