WiFiManager icon indicating copy to clipboard operation
WiFiManager copied to clipboard

Autoconect non blocking problem

Open sebosfato opened this issue 2 years ago • 11 comments

i identified a little issue with the autoconect using along with nonblocking config portal...

it work pretty well if the internet source (modem router.. ) is on before the esp try to connect...

it even will never lost connection even if the modem restart (because if it first connected well it will try to reconnect forever (i think)
however if it takes too long for the modem to restart after a power failure the lib is doing the following

First it attempt to connect and it fails

after setconnect timeout it enter into config portal

after config portal set time out it simply dont try to reconnect again...

it may be simple to solve, maybe calling autoconect again if certain condition is reported by the wifimanager?

im going to put the relevant code im using here

im not sure how to check if the autoconnect is connected =( so i could try to add a way to handle this...

Did you already had this problem? is there any simple solution?

i tried to add wm.process() to the loop too no work

[

if (wm.getWiFiIsSaved() == 1) { Serial.println("I have a saved network"); Serial.println("set time out"); wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(10); wm.setConnectTimeout(10); wm.setAPStaticIPConfig(apIP, apIP, netMsk); wm.autoConnect("Portal"); }

WiFi.softAPConfig(apIP, apIP, netMsk); delay(500); WiFi.softAP(ssid,password,6,hiden);

](url)

sebosfato avatar Oct 27 '21 18:10 sebosfato

Im still trying here...

i came up with the following for now but i would have two questions..

First is how to stop autoconect if it fail so i can start an access point instead...

I ask this because it get stuck in trying to connect and i cannot get to my webserver

if im using the wm.setConfigPortalBlocking(false);

i tried to use wm.stopWebPortal() wm.disconnect();

and many different configurations...

one success is to run the config portal first time if nowifiissaved this makes it user friendly so the first uses until save wifi and something in memory it will run the captive config portal once before start...

like this: [ if (wm.getWiFiIsSaved()==0 && memoria==false) {

 wm.setTimeout(300);//5min

// //Serial.println("Button Pressed, Starting Config Portal"); // wm.setConfigPortalBlocking(true); wm.setBreakAfterConfig(true); wm.setWiFiAPChannel(7); wm.startConfigPortal("Portal"); wm.stopConfigPortal();

ESP.restart();

}

]

sebosfato avatar Oct 28 '21 07:10 sebosfato

But if wifi is saved and it get no connection for example my goal would best be to provide the AP so i can access the server and after some minutes try autoconect() again...

im not very experienced so i hope you may have a hint how can i do it?

im trying this if (WiFi.status() != WL_CONNECTED){ wm.disconnect();

//WiFi.disconnect(true); //wm.startWebPortal(); //WiFi.mode(WIFI_STA); //WiFi.softAP(ssid,password,6,hiden); //WiFi.softAPConfig(apIP, apIP, netMsk); // delay(500);

//IPAddress myIP = WiFi.softAPIP(); // Serial.print("AP IP address: "); // Serial.println(myIP);

wm.stopWebPortal(); //wm.disconnect(); //WiFi.disconnect(true); delay(500); WiFi.mode(WIFI_AP_STA); WiFi.softAP(ssid,password,6,hiden); WiFi.softAPConfig(apIP, apIP, netMsk); delay(500); WiFi.begin(); // Serial.print("wm.getConfigPortalActive()"); //Serial.println(wm.getConfigPortalActive()); //Serial.print("wm.getWebPortalActive()") ; //Serial.println(wm.getWebPortalActive()) ; }

sebosfato avatar Oct 28 '21 07:10 sebosfato

I guess i solved by calling the webportal on demand by setting a timer for if its not connected (if local ip is == IPUnset) than it send a variable to execute like if were pressing the button

it supose to wake the config portal but is doing what i need.

i post the code later

sebosfato avatar Oct 29 '21 19:10 sebosfato

the only problem now is that the SSID of the start web portal seems limited to the ESP74847 like instead of custom name the startwebportal dont seem to allow seting a name for the ap

sebosfato avatar Oct 29 '21 19:10 sebosfato

Esp8266 or esp32?

tablatronix avatar Oct 30 '21 00:10 tablatronix

Hi tablatronix its ESP8266

I managed to improove the usability but i still missing how to set the country to BR it only allow me to set it to US JP orCN i even tried to substitute on wifimanager.cpp the JP for BR to see if it worked hhaaha not

Setting to BR sometimes apear as X2 as CN or BR on my mac wifi info

Can you help me how to set the BR?

alrerady tried // wifi.setcountry({country="BR", start_ch=1, end_ch=11, policy=wifi.COUNTRY_AUTO}); no wifi declared or something...

here is what im doing

setup 👍 wm.setCountry("BR");

if (wm.getWiFiIsSaved()==1) {

Serial.println("I have a saved network");
wm.setConnectTimeout(30);
wm.setConfigPortalTimeout(60);  ///se entrou no portal é pq nao esta conseguindo conectar
Serial.println("set time out");

Serial.println("block config portal false"); wm.setWiFiAPChannel(7); wm.autoConnect("Portal"); }

if ((wm.getWiFiIsSaved()==0) && (memoria == false)) {

 wm.setConfigPortalTimeout(180);
wm.setConfigPortalBlocking(true);

wm.setWiFiAPChannel(7); wm.startConfigPortal("Portal"); wm.stopWebPortal(); wm.stopConfigPortal(); notconect=true;

if (wm.getWiFiIsSaved()==0) wm.disconnect(); delay(500);

}

WiFi.softAPConfig(apIP, apIP, netMsk); WiFi.softAP(ssid, password, 7, hiden);

////here i can call the config portal from the AP from a link server.on("/WIFICONFIG", HTTP_GET, { server.send(205);//, "text/plain", ""+versao); //205 serve para nao redirecionar WiFi.mode(WIFI_STA); dnsServer.stop(); server.stop(); if (startAP) { wm.setTimeout(180); //Serial.println("Button Pressed, Starting Config Portal"); wm.setConfigPortalBlocking(true); wm.setBreakAfterConfig(true); wm.setWiFiAPChannel(7); wm.startConfigPortal("Portal"); ESP.restart(); } } );

void doWiFiManager() {

// is auto timeout portal running if (portalRunning) { wm.process(); if ((millis() - startTime) > (timeout * 1000)) { Serial.println("portaltimeout"); portalRunning = false; if (startAP) { wm.stopConfigPortal(); } else { // wm.stopWebPortal(); ////// disabled the stop webportal if disable this timeout it gives a ERROR 28 } } }

// is configuration portal requested?

if(notconect == true && (!portalRunning)) { notconect == false; if(startAP){ WiFi.softAP(ssid, password, 6, hiden); Serial.println("Starting Config Portal"); wm.setConfigPortalBlocking(false); wm.startConfigPortal("AP"); }
else{ WiFi.softAP(ssid, password, 6, hiden); Serial.println("Starting Web Portal"); wm.startWebPortal(); }
portalRunning = true; startTime = millis(); }

}

//here is a scheduler every 65 seconds repeat //this is what saved the day as it kind of detect the wifi is not connected and try if anything blocked void t1Callback() { // programa Task t1(65000, TASK_FOREVER, &t1Callback);

wifiatempt++; // if((iplocal.toString()=="(IP unset)") &&(wm.getWiFiIsSaved() == 1) && wifiatempt>1){ if (wm.getWiFiIsSaved() == 0) {

}else{ if(((iplocal.toString()=="(IP unset)") || !wm.autoConnect()) && wifiatempt>1){ Serial.println("IP unset ou !autoconect tendo wifi salvo e passado 130segundos "); Serial.print("autoconectagain"); //Serial.println(wm.autoConnect());

notconect=true; wifiatempt=0; //reconecttt();

}else{ notconect=false; }} // //Serial.println(timeClient.getSeconds()); }

sebosfato avatar Nov 01 '21 19:11 sebosfato

Esp8266 is supposed to autoconnect so this is odd are you setting wifi mode sta?

tablatronix avatar Nov 01 '21 22:11 tablatronix

i set it sta in the setup

it connects automatically but if the modem takes too long to setup the wifi connection i was getting it to hang on the portal non blocking... so i changed to blocking and so if didnt connected and have wifi saved it will keep trying every two minutes few times.....

i did all this to be able to let the ap available if it didnt connected, but still keep trying.. it seems to be working perfectly this way... not sure behind the scene what is happening however...

sebosfato avatar Nov 01 '21 23:11 sebosfato

HEy i came up with another question, have you ever managed to come up with a solution for opening a link direct from the captive portal to a google chrome or defaut browser?

Captive portal seems to not handle javascript very well for some reason... so i would like to redirect where it should work...

window prompts dont work on captive and at the mac is little worst..

sebosfato avatar Nov 02 '21 00:11 sebosfato

Yeah someone said there was a bug in non blocking that timeout doesn't work.. there is an open issue I think

tablatronix avatar Nov 02 '21 04:11 tablatronix

Is this issue still open? (non-blocking mode) If I shut off the wifi radio on my router and turn it back on, the ESP8266 won't reconnect. Also, if the wifi radio is off before and after the initial setup and then I turn the radio on, the ESP8266 doesn't connect while in the main loop. Basically simulating power loss to router and the delay it takes to get situated or if the router's radio temporarily goes down for whatever reason.

19eighties avatar Feb 10 '22 07:02 19eighties