WiFiManager
WiFiManager copied to clipboard
wifi reconnect doesn't seem to work on ESP32 multithread environment
Basic Infos
Hardware
WiFimanager Branch/Release: Master
Esp8266/Esp32:
Hardware: ESP32
Core Version: 2.4.0, staging
Description
Problem description Hi, I'm using your great library in a number of ESP32 devices and they lose wifi connection; sometimes after a few days, sometimes after just a few minutes. the code is multithread, the 'loop' section is empty. It seems that the reconnect-mechanism is not successful. The problem can be avoided by manually adding a reconnect routine in the 'loop' section:
void loop() {
if ((WiFi.status() != WL_CONNECTED) ) {
Serial.print(millis());
Serial.println("Reconnecting to WiFi...");
WiFi.disconnect();
WiFi.reconnect();
}
delay(2000);
}
The setup is:
WiFiManager wm;
void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
//WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE, INADDR_NONE); // required to set hostname properly
//WiFi.setHostname("LF2battery");
//WiFiManager wm;
//wm.resetSettings(); //reset settings - wipe credentials for testing
// Automatically connect using saved credentials,
// if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
// if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
// then goes into a blocking loop awaiting configuration and will return success result
bool res;
// res = wm.autoConnect(); // auto generated AP name from chipid
// res = wm.autoConnect("AutoConnectAP"); // anonymous ap
//wm.setConfigPortalBlocking(false);
wm.setHostname("myHost");
wm.setCleanConnect(true);
wm.setTimeout(3);
wm.setConnectRetries(10);
res = wm.autoConnect("myAP","password"); // password protected ap
if(!res) {
Serial.println("Failed to connect");
// ESP.restart();
}
else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
myIP=WiFi.localIP();
}
}
Settings in IDE
Module: doitV1
Additional libraries: pubsubclient, ESPmDNS,
Is there a way to let the reconnect be handled correctly by the library? thank you