Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add a callback for OTA update #1286

Merged
merged 1 commit into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) ) {
Expand Down