[GH-ISSUE #1514] Terminating WiFiManager's web portal #1291

Open
opened 2026-02-28 01:29:27 +03:00 by kerem · 4 comments
Owner

Originally created by @ambarusa on GitHub (Oct 28, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1514

Basic Infos

Hardware

WiFimanager Branch/Release: Master

Esp8266:

Hardware: ESP-12e,

Core Version: 2.4.0, staging

Description

Hi all. I'm having troubles with terminating WiFiManager's web portal, and starting my own. I know... there were issues opened before regarding this, but this case is different, because it's used in non-blocking mode, and a reset() would change the behavior in the system.

Briefly, after the software connects to the Wi-Fi, I want to change the webservers in the WiFiEventStationModeGotIP callback function. First I got exceptions, and it turned out because stopConfigPortal() was called by me, and later on by wm.process(). I solved this by setting wm.setDisableConfigPortal(false); which stops the process() function to care about closing the webserver.

But still, it seems like after calling the wm.stopWebPortal(); the webserver doesn't close, however the wm.getWebPortalActive() tells the opposite. I could put in a loop my AsyncWebServer's begin() function, but I'm not sure if it's handled by the library, and there's no API go get it's status.

So, what do you suggest I should terminate the WiFiManager's web portal?
Thanks in advance

Settings in IDE

Module: Wemos D1 Mini

Additional libraries: SPAsyncWebServer

Sketch

#include <Arduino.h>

WiFiEventHandler wifiConnectHandler;

void onWifiConnect(const WiFiEventStationModeGotIP &event)
{
   wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
   MDNS.begin(hostname);
   OTA_init();
   wm.stopWebPortal();
   Webserver_start();
   Mqtt_init();
   Mqtt_connect();
}

void setup() {
   Webserver_init();
   Clock_init();
   wm.setDebugOutput(false);
   wm.setConfigPortalBlocking(false);
   WiFi.setAutoReconnect(true);
   wm.setHostname(hostname);
   wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
   if (!wm.autoConnect(hostname))
   {
      Set_clock_state(CLOCK_STATE_AP);
   }
}

void 100_ms_task() {
   wm.process();
}
#END
Originally created by @ambarusa on GitHub (Oct 28, 2022). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1514 ### Basic Infos #### Hardware WiFimanager Branch/Release: Master Esp8266: Hardware: ESP-12e, Core Version: 2.4.0, staging ### Description Hi all. I'm having troubles with terminating WiFiManager's web portal, and starting my own. I know... there were issues opened before regarding this, but this case is different, because it's used in non-blocking mode, and a reset() would change the behavior in the system. Briefly, after the software connects to the Wi-Fi, I want to change the webservers in the `WiFiEventStationModeGotIP` callback function. First I got exceptions, and it turned out because `stopConfigPortal()` was called by me, and later on by `wm.process()`. I solved this by setting `wm.setDisableConfigPortal(false);` which stops the `process()` function to care about closing the webserver. But still, it seems like after calling the `wm.stopWebPortal();` the webserver doesn't close, however the `wm.getWebPortalActive()` tells the opposite. I could put in a loop my AsyncWebServer's `begin()` function, but I'm not sure if it's handled by the library, and there's no API go get it's status. So, what do you suggest I should terminate the WiFiManager's web portal? Thanks in advance ### Settings in IDE Module: Wemos D1 Mini Additional libraries: SPAsyncWebServer ### Sketch ```cpp #include <Arduino.h> WiFiEventHandler wifiConnectHandler; void onWifiConnect(const WiFiEventStationModeGotIP &event) { wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect); MDNS.begin(hostname); OTA_init(); wm.stopWebPortal(); Webserver_start(); Mqtt_init(); Mqtt_connect(); } void setup() { Webserver_init(); Clock_init(); wm.setDebugOutput(false); wm.setConfigPortalBlocking(false); WiFi.setAutoReconnect(true); wm.setHostname(hostname); wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect); if (!wm.autoConnect(hostname)) { Set_clock_state(CLOCK_STATE_AP); } } void 100_ms_task() { wm.process(); } #END ```
Author
Owner

@tablatronix commented on GitHub (Nov 28, 2022):

I have never figured this out, No matter how I try to stop and free the webserver, i can never start it back on the same port..

<!-- gh-comment-id:1329806718 --> @tablatronix commented on GitHub (Nov 28, 2022): I have never figured this out, No matter how I try to stop and free the webserver, i can never start it back on the same port..
Author
Owner

@inoffice commented on GitHub (Dec 12, 2022):

Hi and good day
Sorry by my newie in WifiManager, and sorry if item comment before, but not found any. ambarusa say "terminating WiFiManager's web portal, and starting my own" How?... i try this, redirect to my own portal after Wifimanager conect to some Wifi, and redirecto my own Webserver create in my ESP32 D1 mini. I agree some info!! THANKS

<!-- gh-comment-id:1346926781 --> @inoffice commented on GitHub (Dec 12, 2022): Hi and good day Sorry by my newie in WifiManager, and sorry if item comment before, but not found any. ambarusa say "terminating WiFiManager's web portal, and starting my own" How?... i try this, redirect to my own portal after Wifimanager conect to some Wifi, and redirecto my own Webserver create in my ESP32 D1 mini. I agree some info!! THANKS
Author
Owner

@delcioDEV commented on GitHub (Apr 26, 2023):

To terminate the WiFiManager web portal, you can use the stopConfigPortal() function. However, as you mentioned, calling this function will also stop the web server created by the WiFiManager library, which is not what you want.

To solve this issue, you can call stopWebPortal() instead of stopConfigPortal(). This function will stop the WiFiManager web portal, but it will not stop the web server created by the WiFiManager library. You can then start your own web server using the Webserver_start() function.

<!-- gh-comment-id:1523793925 --> @delcioDEV commented on GitHub (Apr 26, 2023): To terminate the WiFiManager web portal, you can use the stopConfigPortal() function. However, as you mentioned, calling this function will also stop the web server created by the WiFiManager library, which is not what you want. To solve this issue, you can call stopWebPortal() instead of stopConfigPortal(). This function will stop the WiFiManager web portal, but it will not stop the web server created by the WiFiManager library. You can then start your own web server using the Webserver_start() function.
Author
Owner

@tablatronix commented on GitHub (Sep 8, 2023):

Found this today, hints at the same issue

https://github.com/me-no-dev/ESPAsyncWebServer/issues/777

<!-- gh-comment-id:1712035335 --> @tablatronix commented on GitHub (Sep 8, 2023): Found this today, hints at the same issue https://github.com/me-no-dev/ESPAsyncWebServer/issues/777
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#1291
No description provided.