add option to restart ESP when disconnected

This commit is contained in:
technyon
2022-06-30 20:25:37 +02:00
parent 2ef59fc0b6
commit d693e8a065
6 changed files with 47 additions and 0 deletions

View File

@@ -2705,6 +2705,15 @@ void WiFiManager::setPreOtaUpdateCallback( std::function<void()> func ) {
_preotaupdatecallback = func;
}
/**
* setDisconnectedCallback, set a callback to fire when WiFi is disconnected
* @access public
* @param {[type]} void (*func)(void)
*/
void WiFiManager::setDisconnectedCallback( std::function<void()> func ) {
_disconnectedcallback = func;
}
/**
* set custom head html
* custom element will be added to head, eg. new style tag etc.
@@ -3611,6 +3620,12 @@ String WiFiManager::WiFi_psk(bool persistent) const {
// DEBUG_WM(DEBUG_VERBOSE,"[EVENT]",event);
#endif
if(event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED){
if(_disconnectedcallback != nullptr)
{
_disconnectedcallback();
}
#ifdef WM_DEBUG_LEVEL
DEBUG_WM(DEBUG_VERBOSE,F("[EVENT] WIFI_REASON: "),info.wifi_sta_disconnected.reason);
#endif

View File

@@ -253,6 +253,9 @@ class WiFiManager
//called just before doing OTA update
void setPreOtaUpdateCallback( std::function<void()> func );
//called when WiFi has disconnected
void setDisconnectedCallback( 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
@@ -720,6 +723,7 @@ class WiFiManager
std::function<void()> _saveparamscallback;
std::function<void()> _resetcallback;
std::function<void()> _preotaupdatecallback;
std::function<void()> _disconnectedcallback = nullptr;
template <class T>
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {