Qrome / printer-monitor

OctoPrint 3D Printer Monitor using Wemos D1 Mini ESP8266
MIT License
479 stars 164 forks source link

Consider removing WiFi.disconnect(true); from the WifiManager autoConnect(...) timeout #123

Open sprior opened 3 years ago

sprior commented 3 years ago

In the existing code: if (!wifiManager.autoConnect((const char *)hostname.c_str())) {// new addition delay(3000); WiFi.disconnect(true); ESP.reset(); delay(5000); }

The WiFi.disconnect(true) causes the ESP8266 to forget the previously configured SSID/password if AP connection fails and the config mode portal times out. This might not be desireable in the following situation (that happened to me a lot):

1) device is configured via the config portal to connect to an access point 2) there is a power failure. 3) When power is restored the ESP8266 boots faster than the wifiaccess point. 4) The ESP8266 boots, doesn't see the configured AP, goes into the config portal, doesn't get connected to and times out, then wipes the connection settings. 5) The original access point then finishes booting but the ESP8266 no longer tries to connect to it and needs to be reconfigured manually again.

If the Wifi.disconnect(true) is commented out then even after doing a few config portal timeout cycles if the original wifi access point becomes available again the ESP will eventually reconnect and be happy again with no intervention.

This might not sound like a big deal, but I used this code as an example base for some personal projects and set up more than 10 devices with that code, then had a bunch of power failures in my house and would spend a half an hour reconfiguring all the devices. Oops.

vKnmnn commented 2 years ago

What happens when you change your wifi deliberately?

We need the device to reset in order to be able to configure it again in such a case

sprior commented 2 years ago

I guess it's a matter of which situation happens more often and is a pain point. For a while we were having a lot of power failures and every single time I ended up reconfiguring a bunch of devices because they all reset their settings because they came up faster than the wifi access point. If you know in advance you are going to change wifi access points you can use the web interface to clear the settings. Of course the ultimate way to do this would be to hook up a reset button, but that adds to the bill of materials.