Why is it not good practice to call esp_wifi_connect() after esp_wifi_disconnect()?

maria36
Posts: 1
Joined: Sun Mar 24, 2024 3:09 pm

Re: Why is it not good practice to call esp_wifi_connect() after esp_wifi_disconnect()?

Postby maria36 » Sun Mar 24, 2024 3:15 pm

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.

ESP_Sprite
Posts: 9052
Joined: Thu Nov 26, 2015 4:08 am

Re: Why is it not good practice to call esp_wifi_connect() after esp_wifi_disconnect()?

Postby ESP_Sprite » Mon Mar 25, 2024 2:41 am

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.

Who is online

Users browsing this forum: Bing [Bot] and 219 guests