mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
Add callbacks for ESP8266HTTPUpdate (#6796)
Replaces abandoned #1817 and #2694 Add optional std::function callback (so it supports lambdas and normal functions) via ::onStart, ::onEnd, ::onProgress, and ::onError methods. Update example with their use. From @baruch's original pull request: The callback is called when the upgrade actually starts rather than just the initial query so that the user can know that it will not take longer and can also prepare for the upgrade by shutting down other works. From @karlp's original pull request: Incomplete: I've not updated any documentation yet. If this style looks good, I'll happily go and update the documentation (likewise for the examples)
This commit is contained in:
committed by
Develo
parent
36f903443b
commit
800794de37
@ -43,6 +43,23 @@ void setup() {
|
||||
|
||||
}
|
||||
|
||||
void update_started() {
|
||||
USE_SERIAL.println("CALLBACK: HTTP update process started");
|
||||
}
|
||||
|
||||
void update_finished() {
|
||||
USE_SERIAL.println("CALLBACK: HTTP update process finished");
|
||||
}
|
||||
|
||||
void update_progress(int cur, int total) {
|
||||
USE_SERIAL.printf("CALLBACK: HTTP update process at %d of %d bytes...\n", cur, total);
|
||||
}
|
||||
|
||||
void update_error(int err) {
|
||||
USE_SERIAL.printf("CALLBACK: HTTP update fatal error code %d\n", err);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// wait for WiFi connection
|
||||
if ((WiFiMulti.run() == WL_CONNECTED)) {
|
||||
@ -57,6 +74,12 @@ void loop() {
|
||||
// value is used to put the LED on. If the LED is on with HIGH, that value should be passed
|
||||
ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);
|
||||
|
||||
// Add optional callback notifiers
|
||||
ESPhttpUpdate.onStart(update_started);
|
||||
ESPhttpUpdate.onEnd(update_finished);
|
||||
ESPhttpUpdate.onProgress(update_progress);
|
||||
ESPhttpUpdate.onError(update_error);
|
||||
|
||||
t_httpUpdate_return ret = ESPhttpUpdate.update(client, "http://server/file.bin");
|
||||
// Or:
|
||||
//t_httpUpdate_return ret = ESPhttpUpdate.update(client, "server", 80, "file.bin");
|
||||
|
Reference in New Issue
Block a user