From 553ae00bac1cf6deef0ccd6e3dce9de01fa21857 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 21 Jan 2022 14:02:59 -0600 Subject: [PATCH] #1327 --- WiFiManager.cpp | 15 +++++++++++---- .../AutoConnectNonBlocking.ino | 5 ++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 21490674..379d5486 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -705,15 +705,16 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, non blocking/processing")); if(_configPortalTimeout > 0) DEBUG_WM(DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds")); #endif - return result; + return result; // skip blocking loop } + // enter blocking loop, waiting for config + #ifdef WM_DEBUG_LEVEL DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, blocking, waiting for clients...")); if(_configPortalTimeout > 0) DEBUG_WM(DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds")); #endif - // blocking loop waiting for config while(1){ // if timed out or abort, break @@ -729,6 +730,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo state = processConfigPortal(); // status change, break + // @todo what is this for, should be moved inside the processor if(state != WL_IDLE_STATUS){ result = (state == WL_CONNECTED); // true if connected DEBUG_WM(DEBUG_DEV,F("configportal loop break")); @@ -832,7 +834,7 @@ uint8_t WiFiManager::processConfigPortal(){ shutdownConfigPortal(); return WL_CONNECT_FAILED; // CONNECT FAIL } - else{ + else if(_configPortalIsBlocking){ // clear save strings _ssid = ""; _pass = ""; @@ -840,9 +842,14 @@ uint8_t WiFiManager::processConfigPortal(){ WiFi_Disconnect(); WiFi_enableSTA(false); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Disabling STA")); + DEBUG_WM(DEBUG_VERBOSE,F("Processing - Disabling STA")); #endif } + else{ + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(DEBUG_VERBOSE,F("Portal is non blocking - remaining open")); + #endif + } } return WL_IDLE_STATUS; diff --git a/examples/NonBlocking/AutoConnectNonBlocking/AutoConnectNonBlocking.ino b/examples/NonBlocking/AutoConnectNonBlocking/AutoConnectNonBlocking.ino index fa04d917..28c50249 100644 --- a/examples/NonBlocking/AutoConnectNonBlocking/AutoConnectNonBlocking.ino +++ b/examples/NonBlocking/AutoConnectNonBlocking/AutoConnectNonBlocking.ino @@ -10,7 +10,7 @@ void setup() { //wm.resetSettings(); wm.setConfigPortalBlocking(false); - + wm.setConfigPortalTimeout(60); //automatically connect using saved credentials if they exist //If connection fails it starts an access point with the specified name if(wm.autoConnect("AutoConnectAP")){ @@ -19,6 +19,9 @@ void setup() { else { Serial.println("Configportal running"); } + + wm.startConfigPortal(); + // wm.startWebPortal(); } void loop() {