mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 00:55:52 +03:00
[GH-ISSUE #1327] Adding the option to start/keep running the portals in the background after connecting #1138
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#1138
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 @axlan on GitHub (Dec 26, 2021).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1327
This is a really simple feature request. I'd like to use this project both for it's Wifi management, but also as a general configuration page. To do this I run the class in non-blocking mode, and I want the config portal to keep running even after the WiFi connection completes successfully. I've made a simple PR to support this for my own use, but you may be interested in merging it upstream.
@axlan commented on GitHub (Dec 28, 2021):
I actually built this out a bit with a full example of how I'd be using it:
https://github.com/axlan/extended-wifimanager
@tablatronix commented on GitHub (Dec 28, 2021):
This feature is not needed due to non blocking mode already existing, ondemand webportal existing, and this would only work on enableconfigportal and autoconnect failure. So I do not see the utility here, as opposed to manually starting configportal or webportal manually.
I have other requests for leaving cp open after save, which makes a bit more sense to me.
Maybe I am misunderstanding this entirely?
Non blocking should not close, maybe this is a bug?
@axlan commented on GitHub (Dec 28, 2021):
I initially hit this before I realized that the settings could be shown on their own page. In that usage mode saving the settings closes the web portal. It was also hard to enter settings in that mode since they would clear the WiFi credentials.
In non-blocking mode with the settings on their own page, I don't think this issue is relevant. I guess you can consider changing the behavior for the case with non-blocking mode, but the settings share the WiFi config page.
@tablatronix commented on GitHub (Dec 28, 2021):
Both of these should not happen.
These might be bugs or badly tested/overlooked scenarios..
@tablatronix commented on GitHub (Jan 20, 2022):
do you happen to have logs of this ?
Are you wanting to run the webportal in sta mode or run sta+ap and webportal (thats a bit tough, sometimes it works sometimes not, depends on enviroment and wifi channels)
@tablatronix commented on GitHub (Jan 22, 2022):
I could not reproduce saves breaking saved creds
@axlan commented on GitHub (Jan 22, 2022):
I'm using the master commit:
810f144It looks like the main issue (clearing the credentials on an empty save) is fixed.
The configuration portal still closes on connection, which is what I originally proposed a setting to disable.
Here are the logs I captured in testing.
Here's an example main.cc I'm using for reference:
Issue 1: The web configuration closes on initial connection:
Issue 2: The web configuration is cleared when only setting the user parameters:
This appears to be fixed in this commit!
@tablatronix commented on GitHub (Jan 22, 2022):
Yeah but the first condition only occurs if conx fails so you have to manually do it anyway right. Also how can you keep it open if you are saving new wifi, it has to connect to the ap so it has to close softap.
also if you are on wifi you only want the webportal running you cant have the configportal running and be in sta mode, sta+ap is unstable.
you want the softap running all the time and be connected to your network??
@tablatronix commented on GitHub (Jan 22, 2022):
I still cannot understand your pr to test as it has code style changes diffs
@axlan commented on GitHub (Jan 22, 2022):
Sorry, the PR pulled in further changes I made to that branch for my own application. I created a new issue for the other bug I found, and I'll close it since you already addressed the main issue.
The remaining issue can be summarized as: "When running in the background, I'd like the configuration portal (the web server) to be available regardless of changes to connectivity". Since I'm using the portal for general configuration it avoids needing to restart the board after the initial Wifi configuration. I first access the configuration page through the captive portal, and after the initial configuration it can be accessed at the IP address reservation.
For the PR I had made, it seemed sufficient to just modify the logic not to close the configuration portal. I admit I'm not super familiar with how the web servers are managed, so it's possible to get this to work across different platforms the server might need to be stopped and restarted.
This is admittedly not the main use case of the Wifi manager, so it's understandable if you don't want this behavior.
@tablatronix commented on GitHub (Jan 22, 2022):
Well you probably want to be using
startWebPortal()and have proper control over it and not rely on autoconnect other than actual wifi failure recovery
Just add a check and if wifi is connected startwebportal
And there is also always
setEnableConfigPortal(boolean enable);to use autoconnect without configportal and start it manually if you want, or have no wifi conxNow all this has not been tested with saving new wifi creds, not sure if things will break after switching wifi modes and all that, I will try to do some tests
@axlan commented on GitHub (Jan 22, 2022):
Sure, though I don't think autoconnect is the issue here. It's still an issue with this example:
I suppose the alternative to the feature I'm requesting would be something like:
@tablatronix commented on GitHub (Jan 22, 2022):
startConfigPortal includes webportal
Like I said you are essentially trying to do
WiFi.setMode(WIFI_STA_AP);is this what you want?you want your softap running all the time when connected to wifi ?
Cause this is very unstable
@axlan commented on GitHub (Jan 22, 2022):
No, I want the webserver running all the time regardless of the Wifi status or changes to the Wifi. That way I can always access the settings and update the settings either though the IP or the AP.
@axlan commented on GitHub (Jan 22, 2022):
My application has a screen that indicates how you should connect to it, so it's obvious to the user which to use.
@tablatronix commented on GitHub (Jan 22, 2022):
Yeah thats how i use it and why non blocking was created.
If you are connected to wifi just use startWebPortal(), you don't want the ap running
@tablatronix commented on GitHub (Jan 22, 2022):
check this example
https://github.com/tzapu/WiFiManager/blob/master/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino
See how the startap option works
https://github.com/tzapu/WiFiManager/blob/master/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino#L24
you can also add a wifi check and decide that way, or add some kind of checker now and then etc (its usually easier to reboot though)
@axlan commented on GitHub (Jan 22, 2022):
I do want the AP to run for the initial setup. The transition from AP to STA is the case I'm trying to handle here. I think I had
startWebPortalandstartConfigPortalconfused in my previous example, but it still seems like:would be needed to accomplish this. I could also probably handle similar logic in the callbacks, but that's the basic behavior. I was able to avoid this with an additional setting.
It seems like this is what you're suggesting with your example, except it's triggered by a specific event, and not just running all the time.
@tablatronix commented on GitHub (Jan 22, 2022):
oh yeah its an ondemand example, but you would just change that to if connected or something else.
How do you plan on doing initial setup ? wifi.ssid=null ?
I think i have a helper function in there
EDIT
@tablatronix commented on GitHub (Jan 22, 2022):
crap, I didn't click comment and lost previous post, feel free to hit up discord ill check it later, I am also working on something atm that will be doing this same behavior with smarter ap starting to deal with power failures and sleep, so I have been thinking about this usage, so I am curious, I will try to test the PR tomorrow
I have no problem with a single toggle , but I need to make sure it handles all failure modes and when saving we can keep the http and dns without having to restart it, i highly doubt this will work ok all the time as its a bit finicky.
@tablatronix commented on GitHub (Feb 3, 2022):
Sorry I was working on some other stuff, arduino 2.0 testing etc
@tavdog commented on GitHub (Aug 24, 2022):
@tablatronix I know this is off topic but the discord link in the main readme has expired.
@tablatronix commented on GitHub (Sep 8, 2023):
@scudrunner commented on GitHub (Nov 20, 2023):
I am joining late, but have a similar use case I am looking at. I want to be able to easily access saved settings on power up, without overwriting them with the default that is hardcoded in. I really like the captive portal aspect where the user does not need a website, it just opens.
I found that:
The setconfigportal loads the default values.
the autoconnect goes straight to the saved network, and I can not update values
I tried the code below from the above post, and it is not saving my parameters when I catch it in the loop. I also would prefer not to have to know the IP address of the device when connected.
void loop() {
wm.process();
// For a real example would probably want to add a delay between calls to this check
if (!wm.getWebPortalActive()) {
wm.startWebPortal();
}
}
@scudrunner commented on GitHub (Nov 20, 2023):
I updated the code to read the JSON, and change the defaults to previously saved values. I am still lost on how to force a connection later without a button. I would like a period of time on initial boot that I can access the parameters, and after that period of time, the main wifi will be joined. since there is no real trigger, having it in loop seemed very clumsy - but kind of worked. I was re-writing the JSON each loop to make sure it was saved, and this just seemed to sloppy and a waste
@tablatronix commented on GitHub (Nov 20, 2023):
Do you want to access via the website or the ap?
You can add a configportal timeout and startconfigportal, and when it closes you can autoconnect. Not sure exactly what you are looking for
@scudrunner commented on GitHub (Nov 21, 2023):
I am making a controller for a light to change color based on blood sugar
for a diabetic, and I want to make it easy for people to configure if
someone wants to simply reuse code.
Once initially configured I want to access parameters to change behavior.
Ex: change the trigger point for when to turn color or change the color of
the leds without the need to reburn the chip, or disconnect the house
wifi….
Optimally I would have 1 minute to change settings before it decided to
autoconnect. When I tried the forced portal, it cleared the wifi, and I
want the wifi to stay.
Second best would be to open a web page on the esp while it is connected to
wifi. I am going to explore that route unless there is a good way to get
wifimanager to do what I want.
Again, what i would like is a delay on the config page with the esp
network before it connects to the saved wifi. I would not need to remember
an ip address, or write anything that is not already in this awesome code
base.
Thanks
Jeff
On Mon, Nov 20, 2023 at 6:51 PM Shawn A @.***> wrote:
@tablatronix commented on GitHub (Nov 21, 2023):
Yeah thats literally how this works, those things are what it is made for, not sure why its clearing your credentials unless you are doing it in your code..
wm.setConfigportalTimeout(120);
wm.startConfigPortal();
autoconnect();
wm.setblocking = false;
startWebPortal();
loop
process()
This is all in the examples, check the SUPER for every single option
feel free to open a new issue with your actual code etc
@scudrunner commented on GitHub (Nov 21, 2023):
I will try a simpler version of my code tomorrow. To be clear - what
example should I follow? I did have lots of code snippets running around
as got it all working, but I was being careful on this one.
I did find out how to read the json, and overwrite the default values on
boot up, and that may be a nice add as an example in case someone else
wants it. It ended up being easy enough once I went through the code, but
an example may help others.
Thank you for the response, it is definitely appreciated
On Mon, Nov 20, 2023 at 9:47 PM Shawn A @.***> wrote:
@tablatronix commented on GitHub (Nov 21, 2023):
Yeah there is a spiffs/little fs example for storing params.
But here is the SUPER
https://github.com/tzapu/WiFiManager/blob/master/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino
@scudrunner commented on GitHub (Nov 21, 2023):
I tried with the CPTEST set to true and false, and did not get the access
point to come up either time.
I tried running the example you pointed to and get the following errors.
Running on a 8266 wemos D1 clone
C:\Users...sketch_nov21a\sketch_nov21a.ino:92:21: error: 'void
WiFiManager::handleNotFound()' is private within this context
92 | wm.handleNotFound();
| ^
In file included from C:\Users....sketch_nov21a\sketch_nov21a.ino:6:
c:\Users....Arduino\libraries\WiFiManager/WiFiManager.h:655:19: note:
declared private here
655 | void handleNotFound();
| ^~~~~~~~~~~~~~
C:\Users..sketch_nov21a\sketch_nov21a.ino: In function 'void setup()':
C:\Users..Temp.arduinoIDE-unsaved20231021-19320-7kuv5w.zvso9\sketch_nov21a\sketch_nov21a.ino:125:27:
error: 'WM_DEBUG_DEV' was not declared in this scope; did you mean
'WM_DEBUG_LEVEL'?
125 | wm.setDebugOutput(true, WM_DEBUG_DEV);
| ^~~~~~~~~~~~
| WM_DEBUG_LEVEL
exit status 1
On Mon, Nov 20, 2023 at 10:00 PM Shawn A @.***> wrote:
@tablatronix commented on GitHub (Nov 21, 2023):
Ah you do not have the latest git version, are you using arduino or platformio?
This was updated
@scudrunner commented on GitHub (Nov 21, 2023):
Arduino, and I just loaded it last week. I gave up on platform io, it had
many repositories i was trying to use that would not load properly.
On Tue, Nov 21, 2023 at 11:22 AM Shawn A @.***> wrote:
@scudrunner commented on GitHub (Nov 21, 2023):
the library manager in arduino is showing 2.0.16-rc.2
On Tue, Nov 21, 2023 at 11:22 AM Shawn A @.***> wrote:
@scudrunner commented on GitHub (Nov 21, 2023):
in my library folder, the readme has the link to 2.0.16-rc.2, and the JSON
file also has the same version.
On Tue, Nov 21, 2023 at 11:22 AM Shawn A @.***> wrote:
@tablatronix commented on GitHub (Nov 21, 2023):
Yeah you would need the git dev version, you can just delete those errors for now, they are not important lines
@scudrunner commented on GitHub (Nov 21, 2023):
I see you posted in 2018 with a link for the dev branch at that time, but I
dont know how to get the current Dev Branch....
On Tue, Nov 21, 2023 at 3:31 PM Shawn A @.***> wrote:
@tablatronix commented on GitHub (Nov 21, 2023):
I think there is a guide here somewhere to load dev version git version of arduino libraries manually