From c34770ec32e823e58fe66404e48add7cf9a66a43 Mon Sep 17 00:00:00 2001 From: Thiti Yamsung Date: Thu, 15 Sep 2022 19:07:55 +0700 Subject: [PATCH] feat(callback): add config portal timeout callback for handle config portal timeout (#1497) --- WiFiManager.cpp | 21 +++++++++++++++++++++ WiFiManager.h | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 2a71921..271c599 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -786,6 +786,12 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo #endif shutdownConfigPortal(); result = abort ? portalAbortResult : portalTimeoutResult; // false, false + if (_configportaltimeoutcallback != NULL) { + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(DEBUG_VERBOSE,F("[CB] config portal timeout callback")); + #endif + _configportaltimeoutcallback(); // @CALLBACK + } break; } @@ -830,6 +836,12 @@ boolean WiFiManager::process(){ #endif webPortalActive = false; shutdownConfigPortal(); + if (_configportaltimeoutcallback != NULL) { + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(DEBUG_VERBOSE,F("[CB] config portal timeout callback")); + #endif + _configportaltimeoutcallback(); // @CALLBACK + } return false; } @@ -2788,6 +2800,15 @@ void WiFiManager::setPreOtaUpdateCallback( std::function func ) { _preotaupdatecallback = func; } +/** + * setConfigPortalTimeoutCallback, set a callback to config portal is timeout + * @access public + * @param {[type]} void (*func)(void) + */ +void WiFiManager::setConfigPortalTimeoutCallback( std::function func ) { + _configportaltimeoutcallback = func; +} + /** * set custom head html * custom element will be added to head, eg. new meta,style,script tag etc. diff --git a/WiFiManager.h b/WiFiManager.h index c1887f7..1911516 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -276,6 +276,9 @@ class WiFiManager //called just before doing OTA update void setPreOtaUpdateCallback( std::function func ); + //called when config portal is timeout + void setConfigPortalTimeoutCallback( std::function func ); + //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 @@ -771,6 +774,7 @@ class WiFiManager std::function _saveparamscallback; std::function _resetcallback; std::function _preotaupdatecallback; + std::function _configportaltimeoutcallback; template auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {