Skip to content

Commit 8ce6984

Browse files
authored
Add callback for OTA update (#1286)
1 parent 8984863 commit 8ce6984

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

WiFiManager.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -2629,6 +2629,15 @@ void WiFiManager::setPreSaveConfigCallback( std::function<void()> func ) {
26292629
_presavecallback = func;
26302630
}
26312631

2632+
/**
2633+
* setPreOtaUpdateCallback, set a callback to fire before OTA update
2634+
* @access public
2635+
* @param {[type]} void (*func)(void)
2636+
*/
2637+
void WiFiManager::setPreOtaUpdateCallback( std::function<void()> func ) {
2638+
_preotaupdatecallback = func;
2639+
}
2640+
26322641
/**
26332642
* set custom head html
26342643
* custom element will be added to head, eg. new style tag etc.
@@ -3587,6 +3596,10 @@ void WiFiManager::handleUpdating(){
35873596
if(_debug) Serial.setDebugOutput(true);
35883597
uint32_t maxSketchSpace;
35893598

3599+
// Use new callback for before OTA update
3600+
if (_preotaupdatecallback != NULL) {
3601+
_preotaupdatecallback();
3602+
}
35903603
#ifdef ESP8266
35913604
WiFiUDP::stopAll();
35923605
maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;

WiFiManager.h

+3
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ class WiFiManager
220220
//called when saving params-in-wifi or params before anything else happens (eg wifi)
221221
void setPreSaveConfigCallback( std::function<void()> func );
222222

223+
//called just before doing OTA update
224+
void setPreOtaUpdateCallback( std::function<void()> func );
223225

224226
//sets timeout before AP,webserver loop ends and exits even if there has been no setup.
225227
//useful for devices that failed to connect at some point and got stuck in a webserver loop
@@ -661,6 +663,7 @@ class WiFiManager
661663
std::function<void()> _presavecallback;
662664
std::function<void()> _saveparamscallback;
663665
std::function<void()> _resetcallback;
666+
std::function<void()> _preotaupdatecallback;
664667

665668
template <class T>
666669
auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) {

0 commit comments

Comments
 (0)