@@ -294,7 +294,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
294294
295295 if (code <= 0 ) {
296296 DEBUG_HTTP_UPDATE (" [httpUpdate] HTTP error: %s\n " , http.errorToString (code).c_str ());
297- _lastError = code;
297+ _setLastError ( code) ;
298298 http.end ();
299299 return HTTP_UPDATE_FAILED;
300300 }
@@ -334,10 +334,14 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
334334 }
335335 }
336336
337- if (!startUpdate) {
338- _lastError = HTTP_UE_TOO_LESS_SPACE;
337+ if (!startUpdate) {
338+ _setLastError ( HTTP_UE_TOO_LESS_SPACE) ;
339339 ret = HTTP_UPDATE_FAILED;
340340 } else {
341+ // Warn main app we're starting up...
342+ if (_cbStart) {
343+ _cbStart ();
344+ }
341345
342346 WiFiClient * tcp = http.getStreamPtr ();
343347
@@ -360,15 +364,15 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
360364 uint8_t buf[4 ];
361365 if (tcp->peekBytes (&buf[0 ], 4 ) != 4 ) {
362366 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) ;
364368 http.end ();
365369 return HTTP_UPDATE_FAILED;
366370 }
367371
368372 // check for valid first magic byte
369373 if (buf[0 ] != 0xE9 ) {
370374 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) ;
372376 http.end ();
373377 return HTTP_UPDATE_FAILED;
374378
@@ -379,7 +383,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
379383 // check if new bin fits to SPI flash
380384 if (bin_flash_size > ESP.getFlashChipRealSize ()) {
381385 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) ;
383387 http.end ();
384388 return HTTP_UPDATE_FAILED;
385389 }
@@ -388,6 +392,10 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
388392 ret = HTTP_UPDATE_OK;
389393 DEBUG_HTTP_UPDATE (" [httpUpdate] Update ok\n " );
390394 http.end ();
395+ // Warn main app we're all done
396+ if (_cbEnd) {
397+ _cbEnd ();
398+ }
391399
392400#ifdef ATOMIC_FS_UPDATE
393401 if (_rebootOnUpdate) {
@@ -403,7 +411,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
403411 }
404412 }
405413 } else {
406- _lastError = HTTP_UE_SERVER_NOT_REPORT_SIZE;
414+ _setLastError ( HTTP_UE_SERVER_NOT_REPORT_SIZE) ;
407415 ret = HTTP_UPDATE_FAILED;
408416 DEBUG_HTTP_UPDATE (" [httpUpdate] Content-Length was 0 or wasn't set by Server?!\n " );
409417 }
@@ -413,15 +421,15 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
413421 ret = HTTP_UPDATE_NO_UPDATES;
414422 break ;
415423 case HTTP_CODE_NOT_FOUND:
416- _lastError = HTTP_UE_SERVER_FILE_NOT_FOUND;
424+ _setLastError ( HTTP_UE_SERVER_FILE_NOT_FOUND) ;
417425 ret = HTTP_UPDATE_FAILED;
418426 break ;
419427 case HTTP_CODE_FORBIDDEN:
420- _lastError = HTTP_UE_SERVER_FORBIDDEN;
428+ _setLastError ( HTTP_UE_SERVER_FORBIDDEN) ;
421429 ret = HTTP_UPDATE_FAILED;
422430 break ;
423431 default :
424- _lastError = HTTP_UE_SERVER_WRONG_HTTP_CODE;
432+ _setLastError ( HTTP_UE_SERVER_WRONG_HTTP_CODE) ;
425433 ret = HTTP_UPDATE_FAILED;
426434 DEBUG_HTTP_UPDATE (" [httpUpdate] HTTP Code is (%d)\n " , code);
427435 // http.writeToStream(&Serial1);
@@ -444,32 +452,44 @@ bool ESP8266HTTPUpdate::runUpdate(Stream& in, uint32_t size, const String& md5,
444452
445453 StreamString error;
446454
455+ if (_cbProgress) {
456+ Update.onProgress (_cbProgress);
457+ }
458+
447459 if (!Update.begin (size, command, _ledPin, _ledOn)) {
448- _lastError = Update.getError ();
460+ _setLastError ( Update.getError () );
449461 Update.printError (error);
450462 error.trim (); // remove line ending
451463 DEBUG_HTTP_UPDATE (" [httpUpdate] Update.begin failed! (%s)\n " , error.c_str ());
452464 return false ;
453465 }
454466
467+ if (_cbProgress) {
468+ _cbProgress (0 , size);
469+ }
470+
455471 if (md5.length ()) {
456472 if (!Update.setMD5 (md5.c_str ())) {
457- _lastError = HTTP_UE_SERVER_FAULTY_MD5;
473+ _setLastError ( HTTP_UE_SERVER_FAULTY_MD5) ;
458474 DEBUG_HTTP_UPDATE (" [httpUpdate] Update.setMD5 failed! (%s)\n " , md5.c_str ());
459475 return false ;
460476 }
461477 }
462478
463479 if (Update.writeStream (in) != size) {
464- _lastError = Update.getError ();
480+ _setLastError ( Update.getError () );
465481 Update.printError (error);
466482 error.trim (); // remove line ending
467483 DEBUG_HTTP_UPDATE (" [httpUpdate] Update.writeStream failed! (%s)\n " , error.c_str ());
468484 return false ;
469485 }
470486
487+ if (_cbProgress) {
488+ _cbProgress (size, size);
489+ }
490+
471491 if (!Update.end ()) {
472- _lastError = Update.getError ();
492+ _setLastError ( Update.getError () );
473493 Update.printError (error);
474494 error.trim (); // remove line ending
475495 DEBUG_HTTP_UPDATE (" [httpUpdate] Update.end failed! (%s)\n " , error.c_str ());
0 commit comments