Chat freely about anything...

User avatar
By panoss
#80918 This code uses WiFiManager. (it's the WiFiManager 's AutoConnectWithTimeOut example(I have removed the comments))
But what if my router is down, for any reason, and the ESP cannot connect to WiFi?
I suppose it gets stuck at ' if(!wifiManager.autoConnect', right?
Code: Select all#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

  WiFiManager wifiManager;
  wifiManager.setTimeout(180);

  //and goes into a blocking loop awaiting configuration
  if(!wifiManager.autoConnect("AutoConnectAP")) {
    Serial.println("failed to connect and hit timeout");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(5000);
  }

  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");
 
}

void loop() {
  // put your main code here, to run repeatedly:

}


What I want is this:
-at setup, try to connect to wifi
-if succeeds ok no problem If fails, again no problem, BUT don't get stucked here, continue to main loop and.
-while at main loop, try at sometime to reconnect to wifi

I 've been told that the solution is 'setConfigPortalTimeout'.
But nothing more. :(
So, how can I make it work the way I want with the 'setConfigPortalTimeout'?