Add callback for OTA update (#1286)

This commit is contained in:
Mollayo
2021-09-03 21:23:37 -05:00
committed by GitHub
parent 8984863fe6
commit 8ce698427d
2 changed files with 16 additions and 0 deletions
+13
View File
@@ -2629,6 +2629,15 @@ void WiFiManager::setPreSaveConfigCallback( std::function<void()> func ) {
_presavecallback = func;
}
/**
* setPreOtaUpdateCallback, set a callback to fire before OTA update
* @access public
* @param {[type]} void (*func)(void)
*/
void WiFiManager::setPreOtaUpdateCallback( std::function<void()> 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;
+3
View File
@@ -220,6 +220,8 @@ class WiFiManager
//called when saving params-in-wifi or params before anything else happens (eg wifi)
void setPreSaveConfigCallback( std::function<void()> func );
//called just before doing OTA update
void setPreOtaUpdateCallback( 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
@@ -661,6 +663,7 @@ class WiFiManager
std::function<void()> _presavecallback;
std::function<void()> _saveparamscallback;
std::function<void()> _resetcallback;
std::function<void()> _preotaupdatecallback;
template <class T>
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {