From f9a47786b7d3009e7066f96315c833daf7976a0b Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Mon, 20 Jun 2022 22:12:52 -0500 Subject: [PATCH 1/2] adds otacallback and progress example callback for Update lib #1435 --- .../OnDemandConfigPortal.ino | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index 49eae9a..9576717 100644 --- a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -34,6 +34,21 @@ bool WMISBLOCKING = true; // use blocking or non blocking mode, non global pa // char ssid[] = "*************"; // your network SSID (name) // char pass[] = "********"; // your network password + // called after AP mode and config portal has started + // setAPCallback( std::function func ); + // called after webserver has started + // setWebServerCallback( std::function func ); + // called when settings reset have been triggered + // setConfigResetCallback( std::function func ); + // called when wifi settings have been changed and connection was successful ( or setBreakAfterConfig(true) ) + // setSaveConfigCallback( std::function func ); + // called when saving either params-in-wifi or params page + // setSaveParamsCallback( std::function func ); + // called when saving params-in-wifi or params before anything else happens (eg wifi) + // setPreSaveConfigCallback( std::function func ); + // called just before doing OTA update + // setPreOtaUpdateCallback( std::function func ); + void saveWifiCallback(){ Serial.println("[CALLBACK] saveCallback fired"); } @@ -64,6 +79,12 @@ void handleRoute(){ wm.server->send(200, "text/plain", "hello from user code"); } +void handlePreOtaUpdateCallback(){ + Update.onProgress([](unsigned int progress, unsigned int total) { + Serial.printf("CUSTOM Progress: %u%%\r", (progress / (total / 100))); + }); +} + void setup() { // WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP @@ -128,6 +149,7 @@ void setup() { wm.setWebServerCallback(bindServerCallback); wm.setSaveConfigCallback(saveWifiCallback); wm.setSaveParamsCallback(saveParamCallback); + wm.setPreOtaUpdateCallback(handlePreOtaUpdateCallback); // add all your parameters here wm.addParameter(&custom_html); From b05a71b618406ffda633736b1a1c4a69a6b4794b Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Mon, 20 Jun 2022 22:13:30 -0500 Subject: [PATCH 2/2] add comments for httpupdate callbacks --- WiFiManager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 7576e4f..67761ad 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -3768,6 +3768,11 @@ void WiFiManager::handleUpdating(){ DEBUG_WM(DEBUG_VERBOSE,"Update file: ", upload.filename.c_str()); #endif + // Update.onProgress(THandlerFunction_Progress fn); + // Update.onProgress([](unsigned int progress, unsigned int total) { + // Serial.printf("Progress: %u%%\r", (progress / (total / 100))); + // }); + if (!Update.begin(maxSketchSpace)) { // start with max available size #ifdef WM_DEBUG_LEVEL DEBUG_WM(DEBUG_ERROR,F("[ERROR] OTA Update ERROR"), Update.getError()); @@ -3778,7 +3783,7 @@ void WiFiManager::handleUpdating(){ } // UPLOAD WRITE else if (upload.status == UPLOAD_FILE_WRITE) { - Serial.print("."); + // Serial.print("."); if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) { #ifdef WM_DEBUG_LEVEL DEBUG_WM(DEBUG_ERROR,F("[ERROR] OTA Update WRITE ERROR"), Update.getError());