From 4d999b145613a6181c76ec2222334d40471a2b78 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 4 Feb 2022 12:35:10 -0600 Subject: [PATCH] fix #1353 #1354 --- WiFiManager.cpp | 18 ++++++++++++++---- WiFiManager.h | 1 + .../OnDemandConfigPortal.ino | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 87ee235..5afe902 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -752,7 +752,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo /** * [process description] * @access public - * @return {[type]} [description] + * @return bool connected */ boolean WiFiManager::process(){ // process mdns, esp32 not required @@ -765,13 +765,23 @@ boolean WiFiManager::process(){ } if(webPortalActive || (configPortalActive && !_configPortalIsBlocking)){ - uint8_t state = processConfigPortal(); - return state == WL_CONNECTED; + + // if timed out or abort, break + if(_allowExit && (configPortalHasTimeout() || abort)){ + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(DEBUG_DEV,F("process loop abort")); + #endif + shutdownConfigPortal(); + return false; + } + + uint8_t state = processConfigPortal(); + return state == WL_CONNECTED; } return false; } -//using esp enums returns for now, should be fine +//using esp wl_status enums as returns for now, should be fine uint8_t WiFiManager::processConfigPortal(){ if(configPortalActive){ //DNS handler diff --git a/WiFiManager.h b/WiFiManager.h index fb0bf56..75c5542 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -462,6 +462,7 @@ class WiFiManager unsigned long _startconn = 0; // ms for timing wifi connects 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 + bool _allowExit = true; // allow exit non blocking #ifdef ESP32 wifi_event_id_t wm_event_id; diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index 829d5b1..b34413f 100644 --- a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -29,6 +29,7 @@ int TESP_CP_TIMEOUT = 90; // test cp timeout bool TEST_NET = true; // do a network test after connect, (gets ntp time) bool ALLOWONDEMAND = true; // enable on demand int ONDDEMANDPIN = 0; // gpio for button +bool WMISBLOCKING = false; // use blocking or non blocking mode // char ssid[] = "*************"; // your network SSID (name) // char pass[] = "********"; // your network password @@ -161,6 +162,13 @@ void setup() { // show password publicly in form // wm.setShowPassword(true); + // sets wether wm configportal is a blocking loop(legacy) or not, use wm.process() in loop if false + // wm.setConfigPortalBlocking(false); + + if(!WMISBLOCKING){ + wm.setConfigPortalBlocking(false); + } + //sets timeout until configuration portal gets turned off //useful to make it all retry or go to sleep in seconds wm.setConfigPortalTimeout(120); @@ -233,6 +241,10 @@ void wifiInfo(){ void loop() { + if(!WMISBLOCKING){ + wm.process(); + } + #ifdef USEOTA ArduinoOTA.handle(); #endif @@ -241,6 +253,13 @@ void loop() { delay(100); if ( digitalRead(ONDDEMANDPIN) == LOW ){ Serial.println("BUTTON PRESSED"); + + // button reset/reboot + // wm.resetSettings(); + // wm.reboot(); + // delay(200); + // return; + wm.setConfigPortalTimeout(140); wm.setParamsPage(false); // move params to seperate page, not wifi, do not combine with setmenu!