mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 09:05:56 +03:00
[GH-ISSUE #1305] Autoconect non blocking problem #1122
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#1122
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sebosfato on GitHub (Oct 27, 2021).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1305
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 commented on GitHub (Oct 28, 2021):
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) {
// //Serial.println("Button Pressed, Starting Config Portal");
// wm.setConfigPortalBlocking(true);
wm.setBreakAfterConfig(true);
wm.setWiFiAPChannel(7);
wm.startConfigPortal("Portal");
wm.stopConfigPortal();
ESP.restart();
}
]
@sebosfato commented on GitHub (Oct 28, 2021):
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 commented on GitHub (Oct 29, 2021):
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 commented on GitHub (Oct 29, 2021):
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
@tablatronix commented on GitHub (Oct 30, 2021):
Esp8266 or esp32?
@sebosfato commented on GitHub (Nov 1, 2021):
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("block config portal false");
wm.setWiFiAPChannel(7);
wm.autoConnect("Portal");
}
if ((wm.getWiFiIsSaved()==0) && (memoria == false)) {
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
}
}
}
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());
}
@tablatronix commented on GitHub (Nov 1, 2021):
Esp8266 is supposed to autoconnect so this is odd are you setting wifi mode sta?
@sebosfato commented on GitHub (Nov 1, 2021):
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 commented on GitHub (Nov 2, 2021):
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..
@tablatronix commented on GitHub (Nov 2, 2021):
Yeah someone said there was a bug in non blocking that timeout doesn't work.. there is an open issue I think
@19eighties commented on GitHub (Feb 10, 2022):
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.
@WMTaylor2Degrees commented on GitHub (Nov 5, 2024):
Sorry to pull this from the depths of time. I'm seeing the same issue with an ESP32 while using the non-blocking code. If WiFi AP turns off and then on again, the ESP32 won't attempt to reconnect to the WiFi once it's in portal mode.
@tablatronix (love your work here btw) you mentioned ESP8266 is supposed to auto reconnect, is there something extra that needs doing for ESP32? I've attempted to manually call WiFi.reconnect() every 10 seconds while in the loop, but it doesn't appear to have helped.
I've attached a sample of code below. Anyones thoughts would be appreciated: