[GH-ISSUE #595] OnDemandWebPortal example missing information on what happens when NOT in config mode? #496

Closed
opened 2026-02-28 01:25:35 +03:00 by kerem · 6 comments
Owner

Originally created by @schweini on GitHub (Apr 19, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/595

Maybe I'm being denser than usual, but neither the examples for the on-demand config portals or the documentation as such explain what happens if the user is NOT in config mode.

I need to try to connect to the last successful network. If this doesn't work, then I only want to start the config mode when certain criteria are met (e.g. button press).

How am I supposed to connect to the last known working wifi network, and only start the config mode on failure?

I would try using the standard WiFi / WiFiMulti methods, but how can I pass them the last known SSID and password, gathered by WifiManger?

Originally created by @schweini on GitHub (Apr 19, 2018). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/595 Maybe I'm being denser than usual, but neither the examples for the on-demand config portals or the documentation as such explain what happens if the user is NOT in config mode. I need to try to connect to the last successful network. If this doesn't work, then I only want to start the config mode when certain criteria are met (e.g. button press). How am I supposed to connect to the last known working wifi network, and only start the config mode on failure? I would try using the standard WiFi / WiFiMulti methods, but how can I pass them the last known SSID and password, gathered by WifiManger?
kerem closed this issue 2026-02-28 01:25:35 +03:00
Author
Owner

@tablatronix commented on GitHub (Apr 20, 2018):

besides using the standard code wifi.status() == wl_connected loop ?
What do you mean when not in config mode ?

the esp automatically connects to the last network by itself, you dont need wm to do that, but you CAN call autoconnect() if you wanted to and with the configportal disabled, you can manually handle it however you want, or you can manually restart it whatever

How familiar are you with the actual esp library itself ?

you should know you can just call WiFi.begin() to reconnect

<!-- gh-comment-id:382918944 --> @tablatronix commented on GitHub (Apr 20, 2018): besides using the standard code wifi.status() == wl_connected loop ? What do you mean when not in config mode ? the esp automatically connects to the last network by itself, you dont need wm to do that, but you CAN call autoconnect() if you wanted to and with the configportal disabled, you can manually handle it however you want, or you can manually restart it whatever How familiar are you with the actual esp library itself ? you should know you can just call WiFi.begin() to reconnect
Author
Owner

@schweini commented on GitHub (Apr 20, 2018):

Thanks for your quick reply!

Ideally, I'd like to use WifiMulti (seems to be the standard way of manually connecting nowadays?) to connect to some Wifi networks. Only if there is none of the predefined networks available, I'd like to use WifiManger to start the Config Portal, and configure the connection details using the web interface.

What I don't understand is how I can get the ESP32 to 'know' when it has been configured using WifiManager, and use this information instead of WifiMulti afterwards?

In pseudo-code, I guess what I'm looking for is how to do this:

if ( wifiManger.connectionSuccessful() ) 
{
  connected = true;
}
elsif ( WifiMulti.connectionSuccessful() )
{
  connected = true
}
else
{
  if (button_pressed)
  {
  wifiManager.startConfigPortal("OnDemandAP")
  }
}

<!-- gh-comment-id:382923346 --> @schweini commented on GitHub (Apr 20, 2018): Thanks for your quick reply! Ideally, I'd like to use WifiMulti (seems to be the standard way of manually connecting nowadays?) to connect to some Wifi networks. Only if there is none of the predefined networks available, I'd like to use WifiManger to start the Config Portal, and configure the connection details using the web interface. What I don't understand is how I can get the ESP32 to 'know' when it has been configured using WifiManager, and use this information instead of WifiMulti afterwards? In pseudo-code, I guess what I'm looking for is how to do this: ``` if ( wifiManger.connectionSuccessful() ) { connected = true; } elsif ( WifiMulti.connectionSuccessful() ) { connected = true } else { if (button_pressed) { wifiManager.startConfigPortal("OnDemandAP") } } ```
Author
Owner

@tablatronix commented on GitHub (Apr 20, 2018):

Wifi multi is for connecting to mutiple aps, and it only stores the last successful one to flash, so its not really the greatest thing,unless you are actually connecting to mutiple aps.

The connection status is the return value of autoconnect.

There is no way to differentiate what saved the ssid in memory though.

<!-- gh-comment-id:382926303 --> @tablatronix commented on GitHub (Apr 20, 2018): Wifi multi is for connecting to mutiple aps, and it only stores the last successful one to flash, so its not really the greatest thing,unless you are actually connecting to mutiple aps. The connection status is the return value of autoconnect. There is no way to differentiate what saved the ssid in memory though.
Author
Owner

@schweini commented on GitHub (Apr 20, 2018):

But even I were not to use WifiMulti and just regular Wifi.begin(), how can I tell wifiManger to attempt to connect using its stored credentials, and if unsuccessful, return control to my program, so that I can decide when to call startConfigPortal()?

As far as I can see, I only have the option of calling autoConnect() (which attempts the connection, and starts the Config Portal if unsuccessful), or to not connect at all, and start the Config Portal manually.

Because of you mention of ....

Oooops. Just re-read your other comment, and the mention of Wifi.begin() without arguments. Will try that!

<!-- gh-comment-id:382928178 --> @schweini commented on GitHub (Apr 20, 2018): But even I were not to use WifiMulti and just regular Wifi.begin(), how can I tell wifiManger to attempt to connect using its stored credentials, and if unsuccessful, return control to my program, so that I can decide when to call startConfigPortal()? As far as I can see, I only have the option of calling autoConnect() (which attempts the connection, and starts the Config Portal if unsuccessful), or to not connect at all, and start the Config Portal manually. Because of you mention of .... Oooops. Just re-read your other comment, and the mention of Wifi.begin() without arguments. Will try that!
Author
Owner

@tablatronix commented on GitHub (Apr 20, 2018):

Are you using development branch?

<!-- gh-comment-id:382928824 --> @tablatronix commented on GitHub (Apr 20, 2018): Are you using development branch?
Author
Owner

@tablatronix commented on GitHub (Apr 20, 2018):

If so
wm.setEnableConfigPortal(false) before calling autoconnect

<!-- gh-comment-id:382929830 --> @tablatronix commented on GitHub (Apr 20, 2018): If so `wm.setEnableConfigPortal(false)` before calling autoconnect
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#496
No description provided.