[GH-ISSUE #511] Cannot reconnect to saved Wifi network after WiFi.disconnect() without first rebooting #427

Open
opened 2026-02-28 01:25:14 +03:00 by kerem · 4 comments
Owner

Originally created by @horendus on GitHub (Feb 10, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/511

I'm finding that if I call WiFi.disconnect() and then try to reconnect with wifiManager.autoConnectNoConfigPortal() or wifiManager.autoConnect I fail to reconnect to the same wifi network again.

The connection result are
*WM: Connection timed out
*WM: Connection result:
*WM: 0

If I reboot my ESP8266 which calls wifiManager.autoConnectNoConfigPortal() at startup it connects without issue, so the wifi details are being stored.

If I call WiFi.begin(SSID,PWD) AFTER a WiFi.disconnect() I am able to connect without issue, but as you see I have had to specify the SSID and PWD instead of using the saved ones from WiFiManager.

If I run WiFi.disconnect() and then print the Wifi details to serial I can see the SSID and PSK are blank. But like I have mentioned, if I power cycle the ESP8266 the details are back.
Serial.print(F("SSID:"));Serial.println(WiFi.SSID());
Serial.print(F("PWD:"));Serial.println(WiFi.psk());

Does anyone have a work around for this? My project needs to be able to enabled/disable wifi within the code and rebooting every time I want to reconnect isnt a good solution for this project.

Originally created by @horendus on GitHub (Feb 10, 2018). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/511 I'm finding that if I call WiFi.disconnect() and then try to reconnect with wifiManager.autoConnectNoConfigPortal() or wifiManager.autoConnect I fail to reconnect to the same wifi network again. The connection result are *WM: Connection timed out *WM: Connection result: *WM: 0 If I reboot my ESP8266 which calls wifiManager.autoConnectNoConfigPortal() at startup it connects without issue, so the wifi details are being stored. If I call WiFi.begin(SSID,PWD) AFTER a WiFi.disconnect() I am able to connect without issue, but as you see I have had to specify the SSID and PWD instead of using the saved ones from WiFiManager. If I run WiFi.disconnect() and then print the Wifi details to serial I can see the SSID and PSK are blank. But like I have mentioned, if I power cycle the ESP8266 the details are back. Serial.print(F("SSID:"));Serial.println(WiFi.SSID()); Serial.print(F("PWD:"));Serial.println(WiFi.psk()); Does anyone have a work around for this? My project needs to be able to enabled/disable wifi within the code and rebooting every time I want to reconnect isnt a good solution for this project.
Author
Owner

@tablatronix commented on GitHub (Feb 10, 2018):

wifi.disconnect wipes config in esp8266

<!-- gh-comment-id:364655118 --> @tablatronix commented on GitHub (Feb 10, 2018): wifi.disconnect wipes config in esp8266
Author
Owner

@tablatronix commented on GitHub (Feb 10, 2018):

also try development branch

<!-- gh-comment-id:364655218 --> @tablatronix commented on GitHub (Feb 10, 2018): also try development branch
Author
Owner

@horendus commented on GitHub (Feb 13, 2018):

Changed WiFi.disconnect() to WiFi.mode(WIFI_OFF)

Seems to allow me to disconnect wifi without loosing details, then re connect with wifiManager.autoConnect

So far have had no issues during testing doing it this way, thoughts? Bad idea?

<!-- gh-comment-id:365186441 --> @horendus commented on GitHub (Feb 13, 2018): Changed WiFi.disconnect() to WiFi.mode(WIFI_OFF) Seems to allow me to disconnect wifi without loosing details, then re connect with wifiManager.autoConnect So far have had no issues during testing doing it this way, thoughts? Bad idea?
Author
Owner

@tablatronix commented on GitHub (Feb 13, 2018):

You can do pesistent(false); WiFi.disconnect()

maybe I will add a public method to wifimanager to help non persistent disconnects, It already exists.

<!-- gh-comment-id:365281792 --> @tablatronix commented on GitHub (Feb 13, 2018): You can do pesistent(false); WiFi.disconnect() maybe I will add a public method to wifimanager to help non persistent disconnects, It already exists.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#427
No description provided.