diff --git a/lib/WiFiManager/include/WiFiManager.h b/lib/WiFiManager/include/WiFiManager.h index 7f671dd..381fe80 100644 --- a/lib/WiFiManager/include/WiFiManager.h +++ b/lib/WiFiManager/include/WiFiManager.h @@ -256,11 +256,11 @@ class WiFiManager boolean autoConnect(char const *apName, char const *apPassword = NULL); //manually start the config portal, autoconnect does this automatically on connect failure - boolean startConfigPortal(); // auto generates apname - boolean startConfigPortal(char const *apName, char const *apPassword = NULL); + void startConfigPortal(); // auto generates apname + void startConfigPortal(char const *apName, char const *apPassword = NULL); - //manually stop the config portal if started manually, stop immediatly if non blocking, flag abort if blocking - bool stopConfigPortal(); + //manually stop the config portal - immediately shuts down the portal + void stopConfigPortal(); //manually start the web portal, autoconnect does this automatically on connect failure void startWebPortal(); @@ -268,7 +268,7 @@ class WiFiManager //manually stop the web portal if started manually void stopWebPortal(); - // Run webserver processing, if setConfigPortalBlocking(false) + // Run webserver processing - must be called periodically when config portal is active boolean process(); // get the AP name of the config portal, so it can be used in the callback @@ -328,7 +328,7 @@ class WiFiManager //sets timeout before AP,webserver loop ends and exits even if there has been no setup. //useful for devices that failed to connect at some point and got stuck in a webserver loop - //in seconds setConfigPortalTimeout is a new name for setTimeout, ! not used if setConfigPortalBlocking + //in seconds setConfigPortalTimeout is a new name for setTimeout void setConfigPortalTimeout(unsigned long seconds); void setTimeout(unsigned long seconds); // @deprecated, alias @@ -364,11 +364,6 @@ class WiFiManager //if this is set, it will exit after config, even if connection is unsuccessful. void setBreakAfterConfig(boolean shouldBreak); - // if this is set, portal will be blocking and wait until save or exit, - // is false user must manually `process()` to handle config portal, - // setConfigPortalTimeout is ignored in this mode, user is responsible for closing configportal - void setConfigPortalBlocking(boolean shouldBlock); - //add custom html at inside for all pages void setCustomHeadElement(const char* html); @@ -639,7 +634,7 @@ class WiFiManager bool _aggresiveReconn = false; // use an agrressive reconnect strategy, WILL delay conxs // on some conn failure modes will add delays and many retries to work around esp and ap bugs, ie, anti de-auth protections // https://github.com/tzapu/WiFiManager/issues/1067 - bool _allowExit = true; // allow exit in nonblocking, else user exit/abort calls will be ignored including cptimeout + bool _allowExit = true; // allow exit/abort calls - if false, user exit/abort calls will be ignored including cptimeout #ifdef ESP32 wifi_event_id_t wm_event_id = 0; @@ -657,7 +652,6 @@ class WiFiManager boolean _removeDuplicateAPs = true; // remove dup aps from wifiscan boolean _showPassword = false; // show or hide saved password on wifi form, might be a security issue! boolean _shouldBreakAfterConfig = false; // stop configportal on save failure - boolean _configPortalIsBlocking = true; // configportal enters blocking loop boolean _enableCaptivePortal = true; // enable captive portal redirection boolean _userpersistent = true; // users preffered persistence to restore boolean _wifiAutoReconnect = true; // there is no platform getter for this, we must assume its true and make it so @@ -849,9 +843,6 @@ protected: // if we decide to support this, these checks will need to be replaced with something client aware to check if client origin is ap or web // These state checks are critical and used for internal function checks boolean webPortalActive = false; - boolean portalTimeoutResult = false; - - boolean portalAbortResult = false; boolean storeSTAmode = true; // option store persistent STA mode in connectwifi int timer = 0; // timer for debug throttle for numclients, and portal timeout messages diff --git a/lib/WiFiManager/src/WiFiManager.cpp b/lib/WiFiManager/src/WiFiManager.cpp index 5b231e1..d70b5f7 100644 --- a/lib/WiFiManager/src/WiFiManager.cpp +++ b/lib/WiFiManager/src/WiFiManager.cpp @@ -386,8 +386,8 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { } // not connected start configportal - bool res = startConfigPortal(apName, apPassword); - return res; + startConfigPortal(apName, apPassword); + return false; // Config portal started, but not connected yet } bool WiFiManager::setupHostname(bool restart){ @@ -735,9 +735,9 @@ void WiFiManager::setupConfigPortal() { if(_preloadwifiscan) WiFi_scanNetworks(true); // preload wifiscan (async) } -boolean WiFiManager::startConfigPortal() { +void WiFiManager::startConfigPortal() { String ssid = getDefaultAPName(); - return startConfigPortal(ssid.c_str(), NULL); + startConfigPortal(ssid.c_str(), NULL); } /** @@ -747,14 +747,14 @@ boolean WiFiManager::startConfigPortal() { * @param {[type]} char const *apPassword [description] * @return {[type]} [description] */ -boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) { +void WiFiManager::startConfigPortal(char const *apName, char const *apPassword) { _begin(); if(configPortalActive){ #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Starting Config Portal FAILED, is already running")); #endif - return false; + return; } //setup AP @@ -767,7 +767,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo if(_apName == "") _apName = getDefaultAPName(); - if(!validApPassword()) return false; + if(!validApPassword()) return; // HANDLE issues with STA connections, shutdown sta if not connected, or else this will hang channel scanning and softap will not respond if(_disableSTA || (!WiFi.isConnected() && _disableSTAConn)){ @@ -787,8 +787,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // init configportal globals to known states configPortalActive = true; - bool result = connect = abort = false; // loop flags, connect true success, abort true break - uint8_t state; + connect = abort = false; // loop flags, connect true success, abort true break _configPortalStart = millis(); @@ -819,59 +818,10 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo setupDNSD(); - if(!_configPortalIsBlocking){ - #ifdef WM_DEBUG_LEVEL - DEBUG_WM(WM_DEBUG_VERBOSE,F("Config Portal Running, non blocking (processing)")); - if(_configPortalTimeout > 0) DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds")); - #endif - return result; // skip blocking loop - } - - // enter blocking loop, waiting for config - #ifdef WM_DEBUG_LEVEL - DEBUG_WM(WM_DEBUG_VERBOSE,F("Config Portal Running, blocking, waiting for clients...")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Config Portal Running (call process() periodically)")); if(_configPortalTimeout > 0) DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds")); #endif - - while(1){ - - // if timed out or abort, break - if(configPortalHasTimeout() || abort){ - #ifdef WM_DEBUG_LEVEL - DEBUG_WM(WM_DEBUG_DEV,F("configportal loop abort")); - #endif - shutdownConfigPortal(); - result = abort ? portalAbortResult : portalTimeoutResult; // false, false - if (_configportaltimeoutcallback != NULL) { - #ifdef WM_DEBUG_LEVEL - DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] config portal timeout callback")); - #endif - _configportaltimeoutcallback(); // @CALLBACK - } - break; - } - - state = processConfigPortal(); - - // status change, break - // @todo what is this for, should be moved inside the processor - // I think.. this is to detect autoconnect by esp in background, there are also many open issues about autoreconnect not working - if(state != WL_IDLE_STATUS){ - result = (state == WL_CONNECTED); // true if connected - DEBUG_WM(WM_DEBUG_DEV,F("configportal loop break")); - break; - } - - if(!configPortalActive) break; - - yield(); // watchdog - } - - #ifdef WM_DEBUG_LEVEL - DEBUG_WM(WM_DEBUG_NOTIFY,F("config portal exiting")); - #endif - return result; } /** @@ -923,7 +873,7 @@ boolean WiFiManager::process(){ _scanRequested = false; } - if(webPortalActive || (configPortalActive && !_configPortalIsBlocking)){ + if(webPortalActive || configPortalActive){ // if timed out or abort, break if(_allowExit && (configPortalHasTimeout() || abort)){ #ifdef WM_DEBUG_LEVEL @@ -1018,20 +968,10 @@ uint8_t WiFiManager::processConfigPortal(){ if(_disableConfigPortal) shutdownConfigPortal(); return WL_CONNECT_FAILED; // CONNECT FAIL } - else if(_configPortalIsBlocking){ - // clear save strings - _ssid = ""; - _pass = ""; - // if connect fails, turn sta off to stabilize AP - WiFi_Disconnect(); - WiFi_enableSTA(false); - #ifdef WM_DEBUG_LEVEL - DEBUG_WM(WM_DEBUG_VERBOSE,F("Processing - Disabling STA")); - #endif - } else{ + // Portal remaining open #ifdef WM_DEBUG_LEVEL - DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal is non blocking - remaining open")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal remaining open")); #endif } } @@ -2561,7 +2501,7 @@ String WiFiManager::getInfoData(String id){ } /** - * HTTPD CALLBACK exit, closes configportal if blocking, if non blocking undefined + * HTTPD CALLBACK exit - schedules config portal shutdown on next process() call */ void WiFiManager::handleExit(AsyncWebServerRequest *request) { #ifdef WM_DEBUG_LEVEL @@ -2780,14 +2720,13 @@ void WiFiManager::reportStatus(String &page){ /** * [stopConfigPortal description] - * @return {[type]} [description] */ -bool WiFiManager::stopConfigPortal(){ - if(_configPortalIsBlocking){ - abort = true; - return true; +void WiFiManager::stopConfigPortal(){ + // Immediately shutdown the config portal + if(configPortalActive) { + abort = true; // Set abort flag for any in-flight async operations + shutdownConfigPortal(); } - return shutdownConfigPortal(); } /** @@ -3185,18 +3124,6 @@ void WiFiManager::setRemoveDuplicateAPs(boolean removeDuplicates) { _removeDuplicateAPs = removeDuplicates; } -/** - * toggle configportal blocking loop - * if enabled, then the configportal will enter a blocking loop and wait for configuration - * if disabled use with process() to manually process webserver - * @since $dev - * @access public - * @param boolean shoudlBlock [false] - */ -void WiFiManager::setConfigPortalBlocking(boolean shouldBlock) { - _configPortalIsBlocking = shouldBlock; -} - /** * toggle restore persistent, track internally * sets ESP wifi.persistent so we can remember it and restore user preference on destruct diff --git a/test/test_wifimanager/tests/test_configuration.cpp b/test/test_wifimanager/tests/test_configuration.cpp index 20763e3..b94e019 100644 --- a/test/test_wifimanager/tests/test_configuration.cpp +++ b/test/test_wifimanager/tests/test_configuration.cpp @@ -36,8 +36,6 @@ void test_configuration_setters() { wm.setShowDnsFields(false); // Test portal behavior - wm.setConfigPortalBlocking(true); - wm.setConfigPortalBlocking(false); wm.setCaptivePortalEnable(true); wm.setCaptivePortalEnable(false); diff --git a/test/test_wifimanager/tests/test_nonblocking.cpp b/test/test_wifimanager/tests/test_nonblocking.cpp index 4651378..e0d14cd 100644 --- a/test/test_wifimanager/tests/test_nonblocking.cpp +++ b/test/test_wifimanager/tests/test_nonblocking.cpp @@ -8,8 +8,6 @@ void test_nonblocking_process() { WiFiManager wm; - // Enable non-blocking mode - wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(10); wm.startConfigPortal("TestAP"); @@ -46,8 +44,6 @@ void test_client_check_setters() { wm.setAPClientCheck(true); wm.setAPClientCheck(false); - // Use non-blocking mode - wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(10); // Start portal and verify it works with client check settings @@ -74,7 +70,6 @@ void test_nonblocking_timeout_behavior() { WiFiManager wm; - wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(2); // 2 second timeout wm.startConfigPortal("TestAP"); diff --git a/test/test_wifimanager/tests/test_portal_lifecycle.cpp b/test/test_wifimanager/tests/test_portal_lifecycle.cpp index 560af3d..078a6df 100644 --- a/test/test_wifimanager/tests/test_portal_lifecycle.cpp +++ b/test/test_wifimanager/tests/test_portal_lifecycle.cpp @@ -8,12 +8,9 @@ void test_start_config_portal() { WiFiManager wm; - // Use non-blocking mode so we can control when to stop - wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(10); // Start portal with SSID only - // Note: In non-blocking mode, startConfigPortal() returns false even when successful wm.startConfigPortal("TestAP"); TEST_ASSERT_TRUE(wm.getConfigPortalActive()); @@ -30,8 +27,6 @@ void test_start_config_portal_with_password() { WiFiManager wm; - // Use non-blocking mode - wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(10); // Start portal with SSID and password @@ -51,12 +46,9 @@ void test_start_config_portal_auto_name() { WiFiManager wm; - // Use non-blocking mode - wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(10); // Start portal without SSID (uses chip ID) - // Note: In non-blocking mode, startConfigPortal() returns false even when successful wm.startConfigPortal(); TEST_ASSERT_TRUE(wm.getConfigPortalActive()); @@ -77,20 +69,16 @@ void test_stop_config_portal() { WiFiManager wm; - // Use non-blocking mode - wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(10); // Start portal - // Note: In non-blocking mode, startConfigPortal() returns false even when successful wm.startConfigPortal("TestAP"); TEST_ASSERT_TRUE(wm.getConfigPortalActive()); delay(100); // Stop portal - bool stopped = wm.stopConfigPortal(); - TEST_ASSERT_TRUE(stopped); + wm.stopConfigPortal(); TEST_ASSERT_FALSE(wm.getConfigPortalActive()); Serial.println("[TEST] stopConfigPortal() test completed successfully"); @@ -101,11 +89,8 @@ void test_config_portal_infrastructure() { WiFiManager wm; - // Use non-blocking mode - wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(10); - // Note: In non-blocking mode, startConfigPortal() returns false even when successful wm.startConfigPortal("TestAP"); TEST_ASSERT_TRUE(wm.getConfigPortalActive()); @@ -176,12 +161,9 @@ void test_config_portal_multiple_start_stop() { WiFiManager wm; - // Use non-blocking mode - wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(10); // First cycle - // Note: In non-blocking mode, startConfigPortal() returns false even when successful wm.startConfigPortal("TestAP1"); TEST_ASSERT_TRUE(wm.getConfigPortalActive()); delay(100); @@ -212,21 +194,17 @@ void test_config_portal_already_active() { WiFiManager wm; - // Use non-blocking mode - wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(10); // Start portal - // Note: In non-blocking mode, startConfigPortal() returns false even when successful wm.startConfigPortal("TestAP"); TEST_ASSERT_TRUE(wm.getConfigPortalActive()); delay(100); - // Try to start again (should fail/return false) - bool started2 = wm.startConfigPortal("TestAP2"); - TEST_ASSERT_FALSE(started2); // Should return false when already active - TEST_ASSERT_TRUE(wm.getConfigPortalActive()); // Still active + // Try to start again (should silently fail when already active) + wm.startConfigPortal("TestAP2"); + TEST_ASSERT_TRUE(wm.getConfigPortalActive()); // Still active with original AP name wm.stopConfigPortal(); @@ -238,8 +216,6 @@ void test_get_config_portal_ssid() { WiFiManager wm; - // Use non-blocking mode - wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(10); // Start with known SSID diff --git a/test/test_wifimanager/tests/test_static_ip.cpp b/test/test_wifimanager/tests/test_static_ip.cpp index 001f9ad..16186be 100644 --- a/test/test_wifimanager/tests/test_static_ip.cpp +++ b/test/test_wifimanager/tests/test_static_ip.cpp @@ -16,8 +16,6 @@ void test_set_ap_static_ip_config() { // Set AP static IP wm.setAPStaticIPConfig(ip, gw, sn); - // Use non-blocking mode - wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(10); // Start portal and verify IP is actually set @@ -72,11 +70,8 @@ void test_ap_static_ip_application() { wm.setAPStaticIPConfig(customIP, customGW, customSN); - // Use non-blocking mode - wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(10); - // Note: In non-blocking mode, startConfigPortal() returns false even when successful wm.startConfigPortal("TestAP"); TEST_ASSERT_TRUE(wm.getConfigPortalActive());