[GH-ISSUE #1435] Firmware update progress callback #1227

Closed
opened 2026-02-28 01:29:07 +03:00 by kerem · 15 comments
Owner

Originally created by @Sladerix on GitHub (Jun 19, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1435

Hi everyone, I'm using this library for the "Update Firmware" function. Very useful.
However I was wondering if there is a way to get the update progress with some callback or something..
I see in the serial monitor that while updating, the library, prints a lot of dots "." so I imagine that could be possible to have a callback for the progress of it.

is it something already implemented or should I edit the library myself?

Thanks in advance

Originally created by @Sladerix on GitHub (Jun 19, 2022). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1435 Hi everyone, I'm using this library for the "Update Firmware" function. Very useful. However I was wondering if there is a way to get the update progress with some callback or something.. I see in the serial monitor that while updating, the library, prints a lot of dots "." so I imagine that could be possible to have a callback for the progress of it. is it something already implemented or should I edit the library myself? Thanks in advance
kerem closed this issue 2026-02-28 01:29:07 +03:00
Author
Owner

@tablatronix commented on GitHub (Jun 19, 2022):

You can add your own arduinoota callbacks in your code also I think there is one wm callback at least

<!-- gh-comment-id:1159802953 --> @tablatronix commented on GitHub (Jun 19, 2022): You can add your own arduinoota callbacks in your code also I think there is one wm callback at least
Author
Owner

@Sladerix commented on GitHub (Jun 19, 2022):

You can add your own arduinoota callbacks in your code also I think there is one wm callback at least

Ouh ok. Where can I find the full documentation about this?

<!-- gh-comment-id:1159808380 --> @Sladerix commented on GitHub (Jun 19, 2022): > You can add your own arduinoota callbacks in your code also I think there is one wm callback at least Ouh ok. Where can I find the full documentation about this?
Author
Owner

@tablatronix commented on GitHub (Jun 19, 2022):

The Arduinoota example sketch or esp examples

<!-- gh-comment-id:1159833894 --> @tablatronix commented on GitHub (Jun 19, 2022): The Arduinoota example sketch or esp examples
Author
Owner

@Sladerix commented on GitHub (Jun 20, 2022):

Ok thanks, I found some examples in File > Examples > ArduinoOTA and File > Examples > Update

But I wish to keep using the WiFiManager Library at the moment. I will take a look in the source files

<!-- gh-comment-id:1160052349 --> @Sladerix commented on GitHub (Jun 20, 2022): > Ok thanks, I found some examples in **_File > Examples > ArduinoOTA_** and **_File > Examples > Update_** But I wish to keep using the WiFiManager Library at the moment. I will take a look in the source files
Author
Owner

@Sladerix commented on GitHub (Jun 20, 2022):

In the source file I didn't found pretty much, apart for the setPreOtaUpdateCallback accessibile method.
And the handleUpdating function that is private... but the only things it does is to write the bytes with the Update object I think (and other checks).

also there is this comment:
... // add progress handler for debugging ...

<!-- gh-comment-id:1160073976 --> @Sladerix commented on GitHub (Jun 20, 2022): In the source file I didn't found pretty much, apart for the **setPreOtaUpdateCallback** accessibile method. And the **handleUpdating** function that is private... but the only things it does is to write the bytes with the _Update_ object I think (and other checks). also there is this comment: `... // add progress handler for debugging ...`
Author
Owner

@tablatronix commented on GitHub (Jun 20, 2022):

you should be able to use them both

 ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
<!-- gh-comment-id:1160550700 --> @tablatronix commented on GitHub (Jun 20, 2022): you should be able to use them both ```c++ ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { Serial.printf("Progress: %u%%\r", (progress / (total / 100))); }); ```
Author
Owner

@Sladerix commented on GitHub (Jun 20, 2022):

you should be able to use them both

Uhm I didn't understand how to use both given the fact that the "autoConnect" is blocking.
However I tried like so (do not work, only prints dots while updating):

#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>



void setup() {
  Serial.begin(115200);
  
  WiFiManager wifiManager;
 
  wifiManager.setConfigPortalTimeout(180);
  //wifiManager.setConfigPortalBlocking(false);

  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
  //ArduinoOTA.begin();

  wifiManager.resetSettings();
  if(!wifiManager.autoConnect("AutoConnectAP")) {
    Serial.println("failed to connect and hit timeout");
  } 

  Serial.println("connected...yeey :)");
}

void loop() {
  // put your main code here, to run repeatedly:
  ArduinoOTA.handle();
}

if I try to uncomment ArduinoOTA.begin(); it goes in crash loop

<!-- gh-comment-id:1160705254 --> @Sladerix commented on GitHub (Jun 20, 2022): > you should be able to use them both Uhm I didn't understand how to use both given the fact that the "autoConnect" is blocking. However I tried like so (do not work, only prints dots while updating): ```c++ #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager #include <WiFi.h> #include <ESPmDNS.h> #include <WiFiUdp.h> #include <ArduinoOTA.h> void setup() { Serial.begin(115200); WiFiManager wifiManager; wifiManager.setConfigPortalTimeout(180); //wifiManager.setConfigPortalBlocking(false); ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { Serial.printf("Progress: %u%%\r", (progress / (total / 100))); }); //ArduinoOTA.begin(); wifiManager.resetSettings(); if(!wifiManager.autoConnect("AutoConnectAP")) { Serial.println("failed to connect and hit timeout"); } Serial.println("connected...yeey :)"); } void loop() { // put your main code here, to run repeatedly: ArduinoOTA.handle(); } ``` if I try to uncomment `ArduinoOTA.begin(); `it goes in crash loop
Author
Owner

@tablatronix commented on GitHub (Jun 21, 2022):

Sorry I wasnt thinking, let me see what I can add

<!-- gh-comment-id:1161154506 --> @tablatronix commented on GitHub (Jun 21, 2022): Sorry I wasnt thinking, let me see what I can add
Author
Owner

@tablatronix commented on GitHub (Jun 21, 2022):

Sorry i meant Update ( we are using httpupload not arduinoota oops
add a callback for Update library inside a wm ota callback


void handlePreOtaUpdateCallback(){
  Update.onProgress([](unsigned int progress, unsigned int total) {
        Serial.printf("CUSTOM Progress: %u%%\r", (progress / (total / 100)));
  });
}

  wm.setPreOtaUpdateCallback(handlePreOtaUpdateCallback);
<!-- gh-comment-id:1161178539 --> @tablatronix commented on GitHub (Jun 21, 2022): Sorry i meant Update ( we are using httpupload not arduinoota oops add a callback for Update library inside a wm ota callback ```C++ void handlePreOtaUpdateCallback(){ Update.onProgress([](unsigned int progress, unsigned int total) { Serial.printf("CUSTOM Progress: %u%%\r", (progress / (total / 100))); }); } wm.setPreOtaUpdateCallback(handlePreOtaUpdateCallback); ```
Author
Owner

@Sladerix commented on GitHub (Jun 21, 2022):

OK.
Now it works as expected!

Thanks very much!!!

Full code example for future people

#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager

void handlePreOtaUpdateCallback(){
  Update.onProgress([](unsigned int progress, unsigned int total) {
        Serial.printf("CUSTOM Progress: %u%%\r", (progress / (total / 100)));
  });
}

void setup() {
  Serial.begin(115200);
  
  WiFiManager wifiManager;
 
  wifiManager.setConfigPortalTimeout(180);
  //wifiManager.setConfigPortalBlocking(false);

  wifiManager.setPreOtaUpdateCallback(handlePreOtaUpdateCallback);
  wifiManager.resetSettings();
  if(!wifiManager.autoConnect("AutoConnectAP")) {
    Serial.println("failed to connect and hit timeout");
  } 

  Serial.println("connected...yeey :)");
}

void loop() {
  // put your main code here, to run repeatedly:
}
<!-- gh-comment-id:1161393410 --> @Sladerix commented on GitHub (Jun 21, 2022): OK. Now it works as expected! Thanks very much!!! Full code example for future people ```c++ #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager void handlePreOtaUpdateCallback(){ Update.onProgress([](unsigned int progress, unsigned int total) { Serial.printf("CUSTOM Progress: %u%%\r", (progress / (total / 100))); }); } void setup() { Serial.begin(115200); WiFiManager wifiManager; wifiManager.setConfigPortalTimeout(180); //wifiManager.setConfigPortalBlocking(false); wifiManager.setPreOtaUpdateCallback(handlePreOtaUpdateCallback); wifiManager.resetSettings(); if(!wifiManager.autoConnect("AutoConnectAP")) { Serial.println("failed to connect and hit timeout"); } Serial.println("connected...yeey :)"); } void loop() { // put your main code here, to run repeatedly: } ```
Author
Owner

@Sladerix commented on GitHub (Jun 21, 2022):

add a callback for Update library inside a wm ota callback

Do you think it's possibile to send BLE data in that callback?
Because I did something like:

void handlePreOtaUpdateCallback(){
  Update.onProgress([](unsigned int progress, unsigned int total) {
        Serial.printf("CUSTOM Progress: %u%%\r\n", (progress / (total / 100)));

        char valueByte[16];
        ltoa(int(progress / (total / 100)), valueByte, 10);
        pC_UPDATEPROGRESS->setValue(valueByte);
        pC_UPDATEPROGRESS->notify();
        free(valueByte);
  });
}

But only the Serial.printf is executed..
it's a WiFi + BLE limitation?

<!-- gh-comment-id:1161558458 --> @Sladerix commented on GitHub (Jun 21, 2022): > add a callback for Update library inside a wm ota callback Do you think it's possibile to send BLE data in that callback? Because I did something like: ```c++ void handlePreOtaUpdateCallback(){ Update.onProgress([](unsigned int progress, unsigned int total) { Serial.printf("CUSTOM Progress: %u%%\r\n", (progress / (total / 100))); char valueByte[16]; ltoa(int(progress / (total / 100)), valueByte, 10); pC_UPDATEPROGRESS->setValue(valueByte); pC_UPDATEPROGRESS->notify(); free(valueByte); }); } ``` But only the Serial.printf is executed.. it's a WiFi + BLE limitation?
Author
Owner

@tablatronix commented on GitHub (Jun 21, 2022):

I think you are pretty limited during ota updates, you can declare this function so its not anonymous and try that.
But I think interrupts are stopped during ota.

I have never tried it or seen an example, I usually avoid even updating displays or neopixels.

The httpupdate ota can maybe be run async and with loop, but I think there are issues and i have not gotten the async branch httpupdate working either...

feel free to open a new issue about this specifically, and ill look around for any pre written code or check the esp repo issues.

If you know another lib that does this well for reference that would be good also.

<!-- gh-comment-id:1161701541 --> @tablatronix commented on GitHub (Jun 21, 2022): I think you are pretty limited during ota updates, you can declare this function so its not anonymous and try that. But I think interrupts are stopped during ota. I have never tried it or seen an example, I usually avoid even updating displays or neopixels. The httpupdate ota can maybe be run async and with loop, but I think there are issues and i have not gotten the async branch httpupdate working either... feel free to open a new issue about this specifically, and ill look around for any pre written code or check the esp repo issues. If you know another lib that does this well for reference that would be good also.
Author
Owner

@Sladerix commented on GitHub (Jun 21, 2022):

I have never tried it or seen an example, I usually avoid even updating displays or neopixels.

Actually I ended by showing the progress on an LCD, instead of sending it over BLE, and it worked. So for what I’ve to do I’m happy like that.

_(small note: both in the serial monitor and on LCD the percentage do not go to 100% but stops about 77% and then the esp32 restarts.

The flashing goes ok because it works then.

I think this is related to the “asynchronous-ness” of the update process (?) that can’t fire the callback all the way to the end because the update actually finishes before it can call the “onProgress” the last few times?
Just curious, not an important thing)_

<!-- gh-comment-id:1161959741 --> @Sladerix commented on GitHub (Jun 21, 2022): > I have never tried it or seen an example, I usually avoid even updating displays or neopixels. Actually I ended by showing the progress on an LCD, instead of sending it over BLE, and it worked. So for what I’ve to do I’m happy like that. _(small note: both in the serial monitor and on LCD the percentage do not go to 100% but stops about 77% and then the esp32 restarts. The flashing goes ok because it works then. I think this is related to the “asynchronous-ness” of the update process (?) that can’t fire the callback all the way to the end because the update actually finishes before it can call the “onProgress” the last few times? Just curious, not an important thing)_
Author
Owner

@ha11otronix commented on GitHub (Mar 29, 2024):

OK. Now it works as expected!

Thanks very much!!!

Full code example for future people

#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager

void handlePreOtaUpdateCallback(){
  Update.onProgress([](unsigned int progress, unsigned int total) {
        Serial.printf("CUSTOM Progress: %u%%\r", (progress / (total / 100)));
  });
}

void setup() {
  Serial.begin(115200);
  
  WiFiManager wifiManager;
 
  wifiManager.setConfigPortalTimeout(180);
  //wifiManager.setConfigPortalBlocking(false);

  wifiManager.setPreOtaUpdateCallback(handlePreOtaUpdateCallback);
  wifiManager.resetSettings();
  if(!wifiManager.autoConnect("AutoConnectAP")) {
    Serial.println("failed to connect and hit timeout");
  } 

  Serial.println("connected...yeey :)");
}

void loop() {
  // put your main code here, to run repeatedly:
}

Is it possible to show the same Progress on browser itself instead of Serial printing? I may not have access to Serial while doing OTA then showing it on browser helps.

<!-- gh-comment-id:2027825538 --> @ha11otronix commented on GitHub (Mar 29, 2024): > OK. Now it works as expected! > > Thanks very much!!! > > Full code example for future people > > ```c++ > #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager > > void handlePreOtaUpdateCallback(){ > Update.onProgress([](unsigned int progress, unsigned int total) { > Serial.printf("CUSTOM Progress: %u%%\r", (progress / (total / 100))); > }); > } > > void setup() { > Serial.begin(115200); > > WiFiManager wifiManager; > > wifiManager.setConfigPortalTimeout(180); > //wifiManager.setConfigPortalBlocking(false); > > wifiManager.setPreOtaUpdateCallback(handlePreOtaUpdateCallback); > wifiManager.resetSettings(); > if(!wifiManager.autoConnect("AutoConnectAP")) { > Serial.println("failed to connect and hit timeout"); > } > > Serial.println("connected...yeey :)"); > } > > void loop() { > // put your main code here, to run repeatedly: > } > ``` Is it possible to show the same Progress on browser itself instead of Serial printing? I may not have access to Serial while doing OTA then showing it on browser helps.
Author
Owner

@tablatronix commented on GitHub (Mar 30, 2024):

I tried that and ota is receiving data via webserver+wifi and its not really possibly to reliablly send data during this, I find that if ota misses even 200ms it can fail.

If you ever find any implementation that has done this and it works let me know

<!-- gh-comment-id:2027843721 --> @tablatronix commented on GitHub (Mar 30, 2024): I tried that and ota is receiving data via webserver+wifi and its not really possibly to reliablly send data during this, I find that if ota misses even 200ms it can fail. If you ever find any implementation that has done this and it works let me know
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1227
No description provided.