Wifimanager: Cannot automatically reconnect after router power cycle

Created on 17 Dec 2016  路  9Comments  路  Source: tzapu/WiFiManager

The wifi manager works well for the most part. I've encountered a strange issue though. If the router is reset while a device is connected to it, the device is unable to remember the credentials previously used. The device must be restarted and it will set up an Autoconnect network to configure the SSID and password. I haven't been able to solve this. Any ideas?

Question

Most helpful comment

Good work, looks like you spent quite a bit of time troubleshooting this. I'm tracking your issue #272 . Hopefully we can get something working here. Having all of the devices lose connection and have to be manually reset is such a pain.

All 9 comments

How do you know that the device has "forgotten" the credentials and just can't reconnect? I'm troubleshooting something similar and was just wondering how you've been able to troubleshoot this. Thanks!

So the device seems to be stuck after the router power cycle. I don't detect the device on my server and it does not set up an access point. I've also had it connected to my computer during this process and I don't see any serial printouts after the router power cycle,

To fix this I have I go to the ESP8266 device and disconnect it and reset the power. After the ESP8266 powers back up, it will set up a webserver - "Autoconnect" which sets up when it can't connect with other credentials. So that is why I say it "forgot" the credentials. It has no recollection of being previously connected.

If the ESP device is not powered up during this router power cycle. These will be fine and connect to the network the next time the ESP device powers on. It only affects the devices that are currently connected to the network.

That's all I've figured so far.. let me know if you find more!!

@reynolga Thanks for the info. While surfing for ESP8266 and disconnect/reconnect code, I saw so many examples--some of which worked and some that didn't. I also came across this issue with the ESP8266 Wifi library itself which suggests that the latest version could have some quirks, too: https://github.com/esp8266/Arduino/issues/2174

I've added a suggestion for @tzapu that we somehow encapsulate reconnection code to make it dead-simple for sketch programmers to call within their loop() code. See issue #272

Good work, looks like you spent quite a bit of time troubleshooting this. I'm tracking your issue #272 . Hopefully we can get something working here. Having all of the devices lose connection and have to be manually reset is such a pain.

The esp reconnects by itself, there is no code required in loop. The only thing it does is what your sketch tells it to. if you have autoconnect on startup and it cannot connect, it will start configportal, if you have a timeout set it will exit automatically and continue to retry ( the esp sdk does this internally )

I am not sure how this loss of connection is happening but it is hard to pin in on this library , i have been trying to reproduce.

you guys also do not mention anything you are using, what sdk, what branches?
what code ?

@tablatronix I'm using this project.

I have 0.96" screen attached to my ESP. Sometimes when there is a power outage at home, all devices are turned off and on at the same time. WIFI router boot time takes longer than ESP, and then I see the following message on the ESP screen: "Wifi manager, please connect to xxxxx". It behaves like it requires initial setup.

Once power on the ESP reset manually, it's successfully connected to WIFI AP.

Are you using setconfigportaltimout ?
Do you have a large enough timeout for autoconnect?

Are you losing wifi credentials also ?

To anyone encountering the same issue in the future, this is my WiFi connection method which works well.
Before using delay(1200); it did not work and stalled on WiFi.status() != WL_CONNECTED.

void connectWiFi() {
  WiFi.disconnect();
  delay(1200);
  WiFi.mode(WIFI_STA);
  Serial.println(F("connectWiFi"));
  WiFi.begin(ssid, password);

  // wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }

  Serial.println(F(""));
  Serial.print(F("Connected to "));
  Serial.println(ssid);
  Serial.print(F("IP address: "));
  Serial.println(WiFi.localIP());
}

Adding a delay of about 2 min before initializing auto connect should solve the issue as nearly every router would be able to turn on in the given duration after power comes back. Not an issue with WifiManager.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

e-music picture e-music  路  8Comments

au190 picture au190  路  7Comments

SeanBannister picture SeanBannister  路  10Comments

tarzan115 picture tarzan115  路  7Comments

anharismail picture anharismail  路  14Comments