tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.62k stars 1.98k forks source link

Non blocking AP mode #379

Closed git-tiger closed 5 years ago

git-tiger commented 7 years ago

I have a project that requires the ESP8266 to startup in access point mode, but the remaining code is blocked till the access point is configured. Is there any way to continue with the code, and still have access point available in the background?

synfinatic commented 7 years ago

I've got the same requirement and from what I can tell, there isn't a way to do this in the current code today.

ANASOMARY commented 6 years ago

Hi Guys,

Is this feature added? am really in bad need for this.

tablatronix commented 6 years ago

development branch

    //if this is set, portal will be blocking and wait until save or exit,  
    // is false user must manually `process()` to handle config portal
    void          setConfigPortalBlocking(boolean shouldBlock);

example https://github.com/tzapu/WiFiManager/issues/379#issuecomment-405046137

500

ANASOMARY commented 6 years ago

Hi, Really appreciate your reply. I did not get the process() part , but if I wanted the code to continue to the loop even after going into AP mode, then should I set setConfigPortalBlocking(false); ?? and in this case I will still get the portal but at the same time the code will continue to the loop function. right?

wifiManager.setAPStaticIPConfig(ip, gateway, subnet); wifiManager.setAPCallback(configModeCallback); setConfigPortalBlocking(false); wifiManager.setSTAStaticIPConfig(lip, lgateway, lsubnet); if (mdns.begin("STR_Master8004", WiFi.softAPIP())); if (!wifiManager.autoConnect(const_cast<char>(mySsid.c_str()), const_cast<char>(myPassword.c_str()))) { Serial.println("failed to connect and hit timeout"); connectionFailed = 1; ESP.reset(); delay(1000); }

tablatronix commented 6 years ago

yes and process() in your loop

ANASOMARY commented 6 years ago

void loop() { process(); HandleSwitch(); server.handleClient(); delay(10); }

Thats it??? Oh god thanks Shawn, you really saved my @$$. 💯

tablatronix commented 6 years ago

Yeah I mean its development, and hardly tested...

ANASOMARY commented 6 years ago

Oh snap image

tablatronix commented 6 years ago

https://github.com/tzapu/WiFiManager/issues/500

ANASOMARY commented 6 years ago

Thanks Shawn,

does it support generic esp8266? am using a sonoff, and am getting the following when I compile: image

tablatronix commented 6 years ago

It should, what board?

ANASOMARY commented 6 years ago

Sonoff Basic

tablatronix commented 6 years ago

I mean what esp board?

ANASOMARY commented 6 years ago

esp8266

tablatronix commented 6 years ago

esp8266 which one? esp01? esp12e?

ANASOMARY commented 6 years ago

ESP8266 V4.1

ANASOMARY commented 6 years ago

Hi Shawn, my mistake, instead of Process() I should have put wifiManager.process(); same for setConfigPortalBlocking It is compiling with no errors now. Thanks again.

ANASOMARY commented 6 years ago

Am Sorry Shawn, But I was using the wrong library, am still getting the same compilation error for generic esp8266 image

ANASOMARY commented 6 years ago

This is strange... I tried compiling for a different board, and am getting the same error! image

Update: it is not compiling for any board now. Please help!

tablatronix commented 6 years ago

You are gonna have to turn on verbose compilation warnings or whatever adruino has to show some actual info

tablatronix commented 6 years ago

https://github.com/tzapu/WiFiManager/issues/524

hassasian commented 6 years ago

@ANASOMARY you should update your board software from board manager. You should use 2.4.1 or newer one.

hassasian commented 6 years ago

@tablatronix thx for ur help. But I have one more question. Our esp connected to an router. After that I close the router. Then as suppose our esp come back to AP mode. When I connected ap of esp, it cannot handle http requests. Sorry for bad eng.

tablatronix commented 6 years ago

not sure i understand

hassasian commented 6 years ago

Give me one more shot to explain it :) I have a esp8266 module. I'm using wifimanager development branch for nonblocking ap mode. its working great. Congrats. My problem is that ; when esp cannot access the router which esp connected before it come back to access mode as expected. And I connect the AutoConnectAP with my computer to configure my esp for another router. But esp cannot answer my http request.

hassasian commented 6 years ago

in addition if you reset your router which esp connected. Esp disconnected from router and enabling its ap. After your router started. Esp connect the router succesfully but esp dont close its ap. Briefly if you restart your router, your esp will enable its ap mode. After your router come back esp will connect it but dont close its ap.

tablatronix commented 6 years ago

Yeah the ap stays running, the portal only runs if you reboot. The ap is not supposed to stay running, thats probably a bug

hassasian commented 6 years ago

Hmm so that means if our router stop working we need to restart our esp physically? Or can we understand that esp disconnected from router. For restarting programmatically.

tablatronix commented 6 years ago

The esp should reconnect by itself , that is part of esp library, not wm

hassasian commented 6 years ago

I got it I mean do we have a callback function for understanding when it connects a router?

tablatronix commented 6 years ago

No, but you can use the esp events

imsyf commented 6 years ago

@tablatronix

The esp should reconnect by itself , that is part of esp library, not wm

How do we break from WiFiManager::startConfigPortal loop when the board successfully reconnected to Wi-Fi by itself due to ESP8266 library's funtionality as you implied?

Because in my experience, I'm able to identify when it actually happens thanks to WiFiEvent callback, but the process wouldn't immediately escape to loop funtion, not until WiFiManager timeout

tablatronix commented 6 years ago

I do not think this is handled automatically, since when in configportal usually STA mode is disabled so AP mode works properly.

It is not wise, to do so ( leave sta mode on ) , and has been updated in hotfixes branch and development as such. If STA is failing it makes AP mode very unstable.

But if you wanted to, in development branch , (if you hardcode channel for stability and leave sta on), you can call stopConfigPortal at any time.

Kirk-1 commented 6 years ago

Hi @tablatronix, Thanks for all your work on this. I had AutoConnect working in non-blocking mode beautifully for a while. Now I am having an issue with: W (84) wifi: wifi nvs_open fail ret=4353 E (84) wifi: wifi_init 1410 ret=4353

So now it seems it wont save the ssid and password once entered in the portal. I am wondering if you could shed any light on this. Perhaps nvs_init() needs to be called somewhere..?

Any help greatly appreciated!

Cheers,

Kirkland

tablatronix commented 6 years ago

Is this an esp32 or eps8266?

Kirk-1 commented 6 years ago

ESP32 Wrover

tablatronix commented 6 years ago

Try erasing nvs, there was a bug in esp32 lib a while ago. You can find instructions in esp32 issues.

Kirk-1 commented 6 years ago

Tried using pytool to erase. Tried using nvs_erase in sketch. Tried nvs_init at start of setup. Tried updating esp libraries. Tried the specific Webserver library recommended. I use wifimanager.process() until I have a connection, then I swap over to serving a web page from within the sketch. So I have an instance of WiFi client, mdns and webserver in the sketch also. Perhaps this is the source of the problem. It was working fine but now this nvs issue. I will keep hunting... Thankyou. Cheers, Kirk

tablatronix commented 6 years ago

You can try enabling debug compile flags.

tablatronix commented 6 years ago

You might be calling something before wifi_init gets called. Are you doing a printdiag() or anything ?

Kirk-1 commented 6 years ago

Thanks again. It seems the problem occurs when I declare an instance of WiFiManager globally. I need to use wifiManager.process() in my loop and so it wont compile unless I declare wifiManager in the loop. But declaring and redeclaring wifiManager continuously in the loop isn't going to work either. I noticed that the same error occurs in the "OnDemandConfigPortal" example because, it would seem, the WiFiManager is declared globally. I am using the development version of WIFiManager.

Kirk-1 commented 6 years ago

Can I enable debug compile flags easily using Arduino?

tablatronix commented 6 years ago

I think there is a menu in board settings debug level

tablatronix commented 6 years ago

ok I think I know what the problem might be. I assume you are using the latest esp32 also ?

tablatronix commented 6 years ago

esp32 introduced some new bugs, I just fixed them ( or rather worked around them ) Give it a try now.

The wifimanager constructor calls getmode (causing the nvs_open failure error ) and persistent(false) which when called before esp32 calls wifiLowLevelInit(_persistent) now turns off flash storage of persistent, even if you change it later.

Kirk-1 commented 6 years ago

That did it! Thank you very much!

xserg commented 6 years ago

@tablatronix Hi! Can you pls add some example for non- blocking case?

tablatronix commented 6 years ago

You can check the ondemandwebportal example

xserg commented 6 years ago

Have an issue with wifisave - it crashes esp on develop branch, on master it ok. tested on Nodemcu esp12 and D1 R1 mini wifisave page time outed, credentials not saved

tablatronix commented 6 years ago

what esp version? Which example?