feat(callback): add config portal timeout callback for handle config portal timeout (#1497)

This commit is contained in:
Thiti Yamsung
2022-09-15 07:07:55 -05:00
committed by GitHub
parent 1b5d71bac7
commit c34770ec32
2 changed files with 25 additions and 0 deletions
+21
View File
@@ -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<void()> func ) {
_preotaupdatecallback = func;
}
/**
* setConfigPortalTimeoutCallback, set a callback to config portal is timeout
* @access public
* @param {[type]} void (*func)(void)
*/
void WiFiManager::setConfigPortalTimeoutCallback( std::function<void()> func ) {
_configportaltimeoutcallback = func;
}
/**
* set custom head html
* custom element will be added to head, eg. new meta,style,script tag etc.
+4
View File
@@ -276,6 +276,9 @@ class WiFiManager
//called just before doing OTA update
void setPreOtaUpdateCallback( std::function<void()> func );
//called when config portal is timeout
void setConfigPortalTimeoutCallback( std::function<void()> 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<void()> _saveparamscallback;
std::function<void()> _resetcallback;
std::function<void()> _preotaupdatecallback;
std::function<void()> _configportaltimeoutcallback;
template <class T>
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {