diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 5fa7023..1e945d8 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2629,6 +2629,15 @@ void WiFiManager::setPreSaveConfigCallback( std::function func ) { _presavecallback = func; } +/** + * setPreOtaUpdateCallback, set a callback to fire before OTA update + * @access public + * @param {[type]} void (*func)(void) + */ +void WiFiManager::setPreOtaUpdateCallback( std::function func ) { + _preotaupdatecallback = func; +} + /** * set custom head html * custom element will be added to head, eg. new style tag etc. @@ -3587,6 +3596,10 @@ void WiFiManager::handleUpdating(){ if(_debug) Serial.setDebugOutput(true); uint32_t maxSketchSpace; + // Use new callback for before OTA update + if (_preotaupdatecallback != NULL) { + _preotaupdatecallback(); + } #ifdef ESP8266 WiFiUDP::stopAll(); maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; diff --git a/WiFiManager.h b/WiFiManager.h index d26d378..de79dc1 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -220,6 +220,8 @@ class WiFiManager //called when saving params-in-wifi or params before anything else happens (eg wifi) void setPreSaveConfigCallback( std::function func ); + //called just before doing OTA update + void setPreOtaUpdateCallback( 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 @@ -661,6 +663,7 @@ class WiFiManager std::function _presavecallback; std::function _saveparamscallback; std::function _resetcallback; + std::function _preotaupdatecallback; template auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {