@@ -294,7 +294,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
294
294
295
295
if (code <= 0 ) {
296
296
DEBUG_HTTP_UPDATE (" [httpUpdate] HTTP error: %s\n " , http.errorToString (code).c_str ());
297
- _lastError = code;
297
+ _setLastError ( code) ;
298
298
http.end ();
299
299
return HTTP_UPDATE_FAILED;
300
300
}
@@ -334,10 +334,14 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
334
334
}
335
335
}
336
336
337
- if (!startUpdate) {
338
- _lastError = HTTP_UE_TOO_LESS_SPACE;
337
+ if (!startUpdate) {
338
+ _setLastError ( HTTP_UE_TOO_LESS_SPACE) ;
339
339
ret = HTTP_UPDATE_FAILED;
340
340
} else {
341
+ // Warn main app we're starting up...
342
+ if (_cbStart) {
343
+ _cbStart ();
344
+ }
341
345
342
346
WiFiClient * tcp = http.getStreamPtr ();
343
347
@@ -360,15 +364,15 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
360
364
uint8_t buf[4 ];
361
365
if (tcp->peekBytes (&buf[0 ], 4 ) != 4 ) {
362
366
DEBUG_HTTP_UPDATE (" [httpUpdate] peekBytes magic header failed\n " );
363
- _lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
367
+ _setLastError ( HTTP_UE_BIN_VERIFY_HEADER_FAILED) ;
364
368
http.end ();
365
369
return HTTP_UPDATE_FAILED;
366
370
}
367
371
368
372
// check for valid first magic byte
369
373
if (buf[0 ] != 0xE9 ) {
370
374
DEBUG_HTTP_UPDATE (" [httpUpdate] Magic header does not start with 0xE9\n " );
371
- _lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
375
+ _setLastError ( HTTP_UE_BIN_VERIFY_HEADER_FAILED) ;
372
376
http.end ();
373
377
return HTTP_UPDATE_FAILED;
374
378
@@ -379,7 +383,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
379
383
// check if new bin fits to SPI flash
380
384
if (bin_flash_size > ESP.getFlashChipRealSize ()) {
381
385
DEBUG_HTTP_UPDATE (" [httpUpdate] New binary does not fit SPI Flash size\n " );
382
- _lastError = HTTP_UE_BIN_FOR_WRONG_FLASH;
386
+ _setLastError ( HTTP_UE_BIN_FOR_WRONG_FLASH) ;
383
387
http.end ();
384
388
return HTTP_UPDATE_FAILED;
385
389
}
@@ -388,6 +392,10 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
388
392
ret = HTTP_UPDATE_OK;
389
393
DEBUG_HTTP_UPDATE (" [httpUpdate] Update ok\n " );
390
394
http.end ();
395
+ // Warn main app we're all done
396
+ if (_cbEnd) {
397
+ _cbEnd ();
398
+ }
391
399
392
400
#ifdef ATOMIC_FS_UPDATE
393
401
if (_rebootOnUpdate) {
@@ -403,7 +411,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
403
411
}
404
412
}
405
413
} else {
406
- _lastError = HTTP_UE_SERVER_NOT_REPORT_SIZE;
414
+ _setLastError ( HTTP_UE_SERVER_NOT_REPORT_SIZE) ;
407
415
ret = HTTP_UPDATE_FAILED;
408
416
DEBUG_HTTP_UPDATE (" [httpUpdate] Content-Length was 0 or wasn't set by Server?!\n " );
409
417
}
@@ -413,15 +421,15 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
413
421
ret = HTTP_UPDATE_NO_UPDATES;
414
422
break ;
415
423
case HTTP_CODE_NOT_FOUND:
416
- _lastError = HTTP_UE_SERVER_FILE_NOT_FOUND;
424
+ _setLastError ( HTTP_UE_SERVER_FILE_NOT_FOUND) ;
417
425
ret = HTTP_UPDATE_FAILED;
418
426
break ;
419
427
case HTTP_CODE_FORBIDDEN:
420
- _lastError = HTTP_UE_SERVER_FORBIDDEN;
428
+ _setLastError ( HTTP_UE_SERVER_FORBIDDEN) ;
421
429
ret = HTTP_UPDATE_FAILED;
422
430
break ;
423
431
default :
424
- _lastError = HTTP_UE_SERVER_WRONG_HTTP_CODE;
432
+ _setLastError ( HTTP_UE_SERVER_WRONG_HTTP_CODE) ;
425
433
ret = HTTP_UPDATE_FAILED;
426
434
DEBUG_HTTP_UPDATE (" [httpUpdate] HTTP Code is (%d)\n " , code);
427
435
// http.writeToStream(&Serial1);
@@ -444,32 +452,44 @@ bool ESP8266HTTPUpdate::runUpdate(Stream& in, uint32_t size, const String& md5,
444
452
445
453
StreamString error;
446
454
455
+ if (_cbProgress) {
456
+ Update.onProgress (_cbProgress);
457
+ }
458
+
447
459
if (!Update.begin (size, command, _ledPin, _ledOn)) {
448
- _lastError = Update.getError ();
460
+ _setLastError ( Update.getError () );
449
461
Update.printError (error);
450
462
error.trim (); // remove line ending
451
463
DEBUG_HTTP_UPDATE (" [httpUpdate] Update.begin failed! (%s)\n " , error.c_str ());
452
464
return false ;
453
465
}
454
466
467
+ if (_cbProgress) {
468
+ _cbProgress (0 , size);
469
+ }
470
+
455
471
if (md5.length ()) {
456
472
if (!Update.setMD5 (md5.c_str ())) {
457
- _lastError = HTTP_UE_SERVER_FAULTY_MD5;
473
+ _setLastError ( HTTP_UE_SERVER_FAULTY_MD5) ;
458
474
DEBUG_HTTP_UPDATE (" [httpUpdate] Update.setMD5 failed! (%s)\n " , md5.c_str ());
459
475
return false ;
460
476
}
461
477
}
462
478
463
479
if (Update.writeStream (in) != size) {
464
- _lastError = Update.getError ();
480
+ _setLastError ( Update.getError () );
465
481
Update.printError (error);
466
482
error.trim (); // remove line ending
467
483
DEBUG_HTTP_UPDATE (" [httpUpdate] Update.writeStream failed! (%s)\n " , error.c_str ());
468
484
return false ;
469
485
}
470
486
487
+ if (_cbProgress) {
488
+ _cbProgress (size, size);
489
+ }
490
+
471
491
if (!Update.end ()) {
472
- _lastError = Update.getError ();
492
+ _setLastError ( Update.getError () );
473
493
Update.printError (error);
474
494
error.trim (); // remove line ending
475
495
DEBUG_HTTP_UPDATE (" [httpUpdate] Update.end failed! (%s)\n " , error.c_str ());
0 commit comments