[GH-ISSUE #1243] Question: how to avoid connecting to Wifi after saving on config portal? #1064

Closed
opened 2026-02-28 01:28:22 +03:00 by kerem · 21 comments
Owner

Originally created by @debackel on GitHub (Apr 21, 2021).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1243

Hello,
This library is great, many thanks to the development community !!!

I am using the config portal to set up the SSID/password.
But the library automatically tries to connect after saving the wifi parameters.

How can I avoid it (I would like to manage the connection in a specific way in my state machine)?

Many thanks for the help.

Laurent

Originally created by @debackel on GitHub (Apr 21, 2021). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1243 Hello, This library is great, many thanks to the development community !!! I am using the config portal to set up the SSID/password. But the library automatically tries to connect after saving the wifi parameters. How can I avoid it (I would like to manage the connection in a specific way in my state machine)? Many thanks for the help. Laurent
kerem closed this issue 2026-02-28 01:28:22 +03:00
Author
Owner

@tablatronix commented on GitHub (Apr 21, 2021):

hmm we use the native esp.begin to save and connect, nothing is implemented to save directly to flash. It would require a bit of programming, you could use the params/setup page and use custom prompts instead then handle them yourself.

<!-- gh-comment-id:824422787 --> @tablatronix commented on GitHub (Apr 21, 2021): hmm we use the native esp.begin to save and connect, nothing is implemented to save directly to flash. It would require a bit of programming, you could use the params/setup page and use custom prompts instead then handle them yourself.
Author
Owner

@debackel commented on GitHub (Apr 22, 2021):

Many thanks for your response.
If I understand correctly, you are using the esp.begin to do both saving the settings in flash memory and to connect to the AP. Is it correct?
So, if we don't connect, the settings modified by the config portal are not saved to flash memory.

In ESP8266WiFiSTA.cpp , one of the "begin" methods has an optional parameter ("connect") to make the connection optional. couldn't we leverage this? The same exists for esp32 (in WiFiSTA.cpp).

That will make the addition in WiFiManager pretty easy, isn't it?
If so, may I propose my change (commit)?

<!-- gh-comment-id:824564153 --> @debackel commented on GitHub (Apr 22, 2021): Many thanks for your response. If I understand correctly, you are using the esp.begin to do both saving the settings in flash memory and to connect to the AP. Is it correct? So, if we don't connect, the settings modified by the config portal are not saved to flash memory. In ESP8266WiFiSTA.cpp , one of the "begin" methods has an optional parameter ("connect") to make the connection optional. couldn't we leverage this? The same exists for esp32 (in WiFiSTA.cpp). That will make the addition in WiFiManager pretty easy, isn't it? If so, may I propose my change (commit)?
Author
Owner

@tablatronix commented on GitHub (Apr 22, 2021):

ahhh, yeah I forgot about that

<!-- gh-comment-id:824949368 --> @tablatronix commented on GitHub (Apr 22, 2021): ahhh, yeah I forgot about that
Author
Owner

@tablatronix commented on GitHub (Apr 22, 2021):

ok give that a try, I have not tested it, and I am not sure how to handle the save returns, it still returns status, so you will have to also handle that or use breakafterconfig etc.

<!-- gh-comment-id:824975763 --> @tablatronix commented on GitHub (Apr 22, 2021): ok give that a try, I have not tested it, and I am not sure how to handle the save returns, it still returns status, so you will have to also handle that or use breakafterconfig etc.
Author
Owner

@tablatronix commented on GitHub (Apr 22, 2021):

This should only affect saving new/changing creds, saving the same is ignored always anyway..

<!-- gh-comment-id:824978262 --> @tablatronix commented on GitHub (Apr 22, 2021): This should only affect saving new/changing creds, saving the same is ignored always anyway..
Author
Owner

@debackel commented on GitHub (Apr 22, 2021):

Thank you so much !!!!
I'll give it a try as soon as possible.

On your concern about ignoring the same credentials, why is this an issue? why would you want to save the same thing as what is stored in flash already? I probably didn't get the point.

Questions: the way the patch is done, won't you have a "WL_CONNECTED" returned (even without being connected)? Isn't this an issue? Also, the debug output will display "Connect to new AP ...", isn't it?
Shouldn't we output differentiated debug output and return code?

<!-- gh-comment-id:825085277 --> @debackel commented on GitHub (Apr 22, 2021): Thank you so much !!!! I'll give it a try as soon as possible. On your concern about ignoring the same credentials, why is this an issue? why would you want to save the same thing as what is stored in flash already? I probably didn't get the point. Questions: the way the patch is done, won't you have a "WL_CONNECTED" returned (even without being connected)? Isn't this an issue? Also, the debug output will display "Connect to new AP ...", isn't it? Shouldn't we output differentiated debug output and return code?
Author
Owner

@tablatronix commented on GitHub (Apr 22, 2021):

I use the same wificonnect code for all , I would have to refactor this more and do not plan on doing that atm, as I am about cut a beta

Debugging is easy to clean up,

The return will be WL_CONNECTED yes, not sure how else to handle that, I could invert it

<!-- gh-comment-id:825213161 --> @tablatronix commented on GitHub (Apr 22, 2021): I use the same wificonnect code for all , I would have to refactor this more and do not plan on doing that atm, as I am about cut a beta Debugging is easy to clean up, The return will be WL_CONNECTED yes, not sure how else to handle that, I could invert it
Author
Owner

@tablatronix commented on GitHub (Apr 22, 2021):

ok going to try returning idle and added alt debug

<!-- gh-comment-id:825219048 --> @tablatronix commented on GitHub (Apr 22, 2021): ok going to try returning idle and added alt debug
Author
Owner

@debackel commented on GitHub (Apr 23, 2021):

I did a test this morning (not deep testing, but quick validation), this works great on my D1 Mini.
Thank you so much !
This way, I can manage myself the connection cycle.

<!-- gh-comment-id:825385341 --> @debackel commented on GitHub (Apr 23, 2021): I did a test this morning (not deep testing, but quick validation), this works great on my D1 Mini. Thank you so much ! This way, I can manage myself the connection cycle.
Author
Owner

@debackel commented on GitHub (Apr 24, 2021):

I made deeper testing today. The patch is functional. However, the debug output at different levels is not adequate anymore, as the methods were originally designed for connecting (not for only saving credentials). Also, in processConfigPortal, we expect connectWifi to return WL_CONNECTED from the wifi.begin, while now, "idle" can be returned as well.
As a consequence, processConfigPortal goes to the error branch, and the config portal is not shutdown properly. I will debug further and hopefully propose a patch to have all this treated properly.

<!-- gh-comment-id:826046293 --> @debackel commented on GitHub (Apr 24, 2021): I made deeper testing today. The patch is functional. However, the debug output at different levels is not adequate anymore, as the methods were originally designed for connecting (not for only saving credentials). Also, in processConfigPortal, we expect connectWifi to return WL_CONNECTED from the wifi.begin, while now, "idle" can be returned as well. As a consequence, processConfigPortal goes to the error branch, and the config portal is not shutdown properly. I will debug further and hopefully propose a patch to have all this treated properly.
Author
Owner

@tablatronix commented on GitHub (Apr 24, 2021):

Are you using non blocking or blocking?

Did you try using shouldbreakafterconfig ?

<!-- gh-comment-id:826098924 --> @tablatronix commented on GitHub (Apr 24, 2021): Are you using non blocking or blocking? Did you try using shouldbreakafterconfig ?
Author
Owner

@debackel commented on GitHub (Apr 24, 2021):

I am using non blocking mode. No, I don't use shouldbreakafterconfig. Can you tell me what this actually does?

<!-- gh-comment-id:826099404 --> @debackel commented on GitHub (Apr 24, 2021): I am using non blocking mode. No, I don't use shouldbreakafterconfig. Can you tell me what this actually does?
Author
Owner

@tablatronix commented on GitHub (Apr 24, 2021):

It looks like wifi begin returns false also

<!-- gh-comment-id:826099830 --> @tablatronix commented on GitHub (Apr 24, 2021): It looks like wifi begin returns false also
Author
Owner

@debackel commented on GitHub (Apr 24, 2021):

It looks like wifi begin returns false also

I am not sure this is wifi.begin. wifi.begin returns an integer value. But in wifimanager, the return code of wifi.begin is tested like this: if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi begin failed"));
As ret = 1 in case of connection, this is OK. But if you don't connect, it returns another value (idle, I guess), which doesn't pass the boolean type of testing.

<!-- gh-comment-id:826100378 --> @debackel commented on GitHub (Apr 24, 2021): > It looks like wifi begin returns false also I am not sure this is wifi.begin. wifi.begin returns an integer value. But in wifimanager, the return code of wifi.begin is tested like this: if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi begin failed")); As ret = 1 in case of connection, this is OK. But if you don't connect, it returns another value (idle, I guess), which doesn't pass the boolean type of testing.
Author
Owner

@tablatronix commented on GitHub (Apr 24, 2021):

Yeah I just noticed connectWifi returns conres, I missed that, it was kludged a little as I will rewrite it all next version

<!-- gh-comment-id:826100740 --> @tablatronix commented on GitHub (Apr 24, 2021): Yeah I just noticed connectWifi returns conres, I missed that, it was kludged a little as I will rewrite it all next version
Author
Owner

@tablatronix commented on GitHub (Apr 24, 2021):

I tried fixing it but now I am crashing my esp... ugh

<!-- gh-comment-id:826106078 --> @tablatronix commented on GitHub (Apr 24, 2021): I tried fixing it but now I am crashing my esp... ugh
Author
Owner

@debackel commented on GitHub (Apr 24, 2021):

Do you want me to write a patch? You would review it, of course.

<!-- gh-comment-id:826106236 --> @debackel commented on GitHub (Apr 24, 2021): Do you want me to write a patch? You would review it, of course.
Author
Owner

@tablatronix commented on GitHub (Apr 24, 2021):

Somehow this is exposing some bug somewhere else.. or in esp lib
NO clue, I will have to decode this first

*wm:[1] SAVED with no connect to new AP 
*wm:[2] disconnect configportal 
*wm:[2] restoring usermode STA
*wm:[2] wifi status: WL_CONNECTED
*wm:[2] wifi mode: STA

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (28):
epc1=0x4020c35b epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000050 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffc40 end: 3fffffc0 offset: 0190
3ffffdd0:  00000000 4bc6a7f0 0000cac0 3ffe8831  
<!-- gh-comment-id:826107470 --> @tablatronix commented on GitHub (Apr 24, 2021): Somehow this is exposing some bug somewhere else.. or in esp lib NO clue, I will have to decode this first ```php *wm:[1] SAVED with no connect to new AP *wm:[2] disconnect configportal *wm:[2] restoring usermode STA *wm:[2] wifi status: WL_CONNECTED *wm:[2] wifi mode: STA --------------- CUT HERE FOR EXCEPTION DECODER --------------- Exception (28): epc1=0x4020c35b epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000050 depc=0x00000000 >>>stack>>> ctx: cont sp: 3ffffc40 end: 3fffffc0 offset: 0190 3ffffdd0: 00000000 4bc6a7f0 0000cac0 3ffe8831 ```
Author
Owner

@tablatronix commented on GitHub (Apr 24, 2021):

all I changed was

        if (connectWifi(_ssid, _pass, _connectonsave) == WL_CONNECTED || (!_connectonsave)) {
<!-- gh-comment-id:826107622 --> @tablatronix commented on GitHub (Apr 24, 2021): all I changed was ```C++ if (connectWifi(_ssid, _pass, _connectonsave) == WL_CONNECTED || (!_connectonsave)) { ```
Author
Owner

@tablatronix commented on GitHub (Apr 24, 2021):

Ok I added some fixes, if this doesn't work, I will have to reimplement the state machine as this has been kludged too much

<!-- gh-comment-id:826123086 --> @tablatronix commented on GitHub (Apr 24, 2021): Ok I added some fixes, if this doesn't work, I will have to reimplement the state machine as this has been kludged too much
Author
Owner

@debackel commented on GitHub (Apr 25, 2021):

Many thanks.
Re tested today, seems OK, I think we can close it. This is great stuff, thank you once again !!!

<!-- gh-comment-id:826352161 --> @debackel commented on GitHub (Apr 25, 2021): Many thanks. Re tested today, seems OK, I think we can close it. This is great stuff, thank you once again !!!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1064
No description provided.