-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding the option to start/keep running the portals in the background after connecting #1327
Comments
I actually built this out a bit with a full example of how I'd be using it: |
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? |
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. |
Both of these should not happen.
These might be bugs or badly tested/overlooked scenarios.. |
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) |
I could not reproduce saves breaking saved creds |
I'm using the master commit: It 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: #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
WiFiManager wm;
WiFiManagerParameter custom_field; // global param ( for non blocking w params )
void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// put your setup code here, to run once:
Serial.begin(115200);
//reset settings - wipe credentials for testing
//wm.resetSettings();
// test custom html(radio)
const char* custom_radio_str = "<br/><label for='customfieldid'>Custom Field Label</label><input type='radio' name='customfieldid' value='1' checked> One<br><input type='radio' name='customfieldid' value='2'> Two<br><input type='radio' name='customfieldid' value='3'> Three";
new (&custom_field) WiFiManagerParameter(custom_radio_str); // custom html input
wm.addParameter(&custom_field);
wm.setConfigPortalBlocking(false);
//automatically connect using saved credentials if they exist
//If connection fails it starts an access point with the specified name
if(wm.autoConnect("AutoConnectAP")){
Serial.println("connected...yeey :)");
}
else {
Serial.println("Configportal running");
}
wm.startConfigPortal();
}
void loop() {
wm.process();
} 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!
|
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?? |
I still cannot understand your pr to test as it has code style changes diffs |
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. |
Well you probably want to be using Just add a check and if wifi is connected startwebportal
And there is also always Now 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 |
Sure, though I don't think autoconnect is the issue here. It's still an issue with this example: #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
WiFiManager wm;
void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// put your setup code here, to run once:
Serial.begin(115200);
wm.setConfigPortalBlocking(false);
wm.startWebPortal();
wm.startConfigPortal();
}
void loop() {
wm.process();
} I suppose the alternative to the feature I'm requesting would be something like: #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
WiFiManager wm;
void setup() {
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// put your setup code here, to run once:
Serial.begin(115200);
wm.setConfigPortalBlocking(false);
wm.startWebPortal();
wm.startConfigPortal();
}
void loop() {
wm.process();
// For a real example would probably want to add a delay between calls to this check
if (!wm.getConfigPortalActive()) {
wm.startConfigPortal();
}
} |
startConfigPortal includes webportal
Like I said you are essentially trying to do Cause this is very unstable |
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. |
My application has a screen that indicates how you should connect to it, so it's obvious to the user which to use. |
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 |
check this example See how the startap option works
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) |
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 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();
}
} 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. |
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 /**
* check if wifi has a saved ap or not
* @since $dev
* @access public
* @return bool true if a saved ap config exists
*/
bool WiFiManager::getWiFiIsSaved(){
return WiFi_hasAutoConnect();
} |
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. |
Sorry I was working on some other stuff, arduino 2.0 testing etc |
@tablatronix I know this is off topic but the discord link in the main readme has expired. |
|
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: 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() { |
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 |
Do you want to access via the website or the ap? |
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:
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
—
Reply to this email directly, view it on GitHub
<#1327 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFQCYWVIQS644IAA6NDITQLYFPUGRAVCNFSM5KYQVSN2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBRHE4TQOJSHE4Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
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.setblocking = false; loop 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 |
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:
Yeah thats literally how this works, not sure why its clearing your
credentials unless you are doing it in your code..
—
Reply to this email directly, view it on GitHub
<#1327 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFQCYWXHBRLQVNAJRLTD473YFQI43AVCNFSM5KYQVSN2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBSGAYTEOBSGM4Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Yeah there is a spiffs/little fs example for storing params. But here is the SUPER
|
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:
Yeah there is a spiffs/little fs example for storing params.
https://github.com/tzapu/WiFiManager/blob/master/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino
// TEST OPTION FLAGS
bool TEST_CP = false; // always start the configportal, even if ap found
int TESP_CP_TIMEOUT = 90; // test cp timeout
—
Reply to this email directly, view it on GitHub
<#1327 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFQCYWRNDXKGJSEYRBH53G3YFQKMRAVCNFSM5KYQVSN2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBSGAYTGNRYGY4Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Ah you do not have the latest git version, are you using arduino or platformio? |
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:
Ah you do not have the latest git version, are you using arduino or
platformio?
This was updated
—
Reply to this email directly, view it on GitHub
<#1327 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFQCYWTOW7CJBCMVWZLS5FDYFTIKPAVCNFSM5KYQVSN2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBSGEZDINBTGU2A>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
the library manager in arduino is showing 2.0.16-rc.2
…On Tue, Nov 21, 2023 at 11:22 AM Shawn A ***@***.***> wrote:
Ah you do not have the latest git version, are you using arduino or
platformio?
This was updated
—
Reply to this email directly, view it on GitHub
<#1327 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFQCYWTOW7CJBCMVWZLS5FDYFTIKPAVCNFSM5KYQVSN2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBSGEZDINBTGU2A>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
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:
Ah you do not have the latest git version, are you using arduino or
platformio?
This was updated
—
Reply to this email directly, view it on GitHub
<#1327 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFQCYWTOW7CJBCMVWZLS5FDYFTIKPAVCNFSM5KYQVSN2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBSGEZDINBTGU2A>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Yeah you would need the git dev version, you can just delete those errors for now, they are not important lines |
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:
Yeah you would need the git dev version
—
Reply to this email directly, view it on GitHub
<#1327 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFQCYWSKGX5A6T4NFDET2PDYFUFSDAVCNFSM5KYQVSN2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBSGE3DGMZSGAZA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I think there is a guide here somewhere to load dev version git version of arduino libraries manually |
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.
The text was updated successfully, but these errors were encountered: