From 07e30d60bc8fe50559e9331770808324a7ea5eed Mon Sep 17 00:00:00 2001 From: adrionics Date: Sun, 19 May 2019 12:02:17 -0600 Subject: [PATCH 1/3] Update Updater.cpp Improve timeout to allow reliable updates on slow networks. --- cores/esp8266/Updater.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cores/esp8266/Updater.cpp b/cores/esp8266/Updater.cpp index 9f68541f4..800a1cbb7 100644 --- a/cores/esp8266/Updater.cpp +++ b/cores/esp8266/Updater.cpp @@ -433,7 +433,7 @@ bool UpdaterClass::_verifyEnd() { return false; } -size_t UpdaterClass::writeStream(Stream &data) { +size_t UpdaterClass::writeStream(Stream &data, uint16_t streamTimeout) { size_t written = 0; size_t toRead = 0; if(hasError() || !isRunning()) @@ -446,6 +446,7 @@ size_t UpdaterClass::writeStream(Stream &data) { _reset(); return 0; } + unsigned long timeout = millis(); if (_progress_callback) { _progress_callback(0, _size); } @@ -463,14 +464,15 @@ size_t UpdaterClass::writeStream(Stream &data) { } toRead = data.readBytes(_buffer + _bufferLen, bytesToRead); if(toRead == 0) { //Timeout - delay(100); - toRead = data.readBytes(_buffer + _bufferLen, bytesToRead); - if(toRead == 0) { //Timeout - _currentAddress = (_startAddress + _size); - _setError(UPDATE_ERROR_STREAM); - _reset(); - return written; - } + if (millis() - timeout > streamTimeout) { + _currentAddress = (_startAddress + _size); + _setError(UPDATE_ERROR_STREAM); + _reset(); + return written; + } + delay(100); + } else { + timeout = millis(); } if(_ledPin != -1) { digitalWrite(_ledPin, !_ledOn); // Switch LED off From 4dd278b96fe9a467e56461232025be586f981dea Mon Sep 17 00:00:00 2001 From: adrionics Date: Sun, 19 May 2019 12:04:41 -0600 Subject: [PATCH 2/3] Update Updater.h --- cores/esp8266/Updater.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp8266/Updater.h b/cores/esp8266/Updater.h index 8de16c7ed..9f5682f0d 100644 --- a/cores/esp8266/Updater.h +++ b/cores/esp8266/Updater.h @@ -80,7 +80,7 @@ class UpdaterClass { Should be equal to the remaining bytes when called Usable for slow streams like Serial */ - size_t writeStream(Stream &data); + size_t writeStream(Stream &data, uint16_t streamTimeout = 60000); /* If all bytes are written From 7304f9bf5a736f191909b7f6969cc60c097032c9 Mon Sep 17 00:00:00 2001 From: adrionics Date: Tue, 21 May 2019 01:30:59 -0600 Subject: [PATCH 3/3] Update Updater.cpp --- cores/esp8266/Updater.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cores/esp8266/Updater.cpp b/cores/esp8266/Updater.cpp index 800a1cbb7..1f37f76ef 100644 --- a/cores/esp8266/Updater.cpp +++ b/cores/esp8266/Updater.cpp @@ -3,6 +3,7 @@ #include "eboot_command.h" #include #include +#include //#define DEBUG_UPDATER Serial @@ -446,7 +447,7 @@ size_t UpdaterClass::writeStream(Stream &data, uint16_t streamTimeout) { _reset(); return 0; } - unsigned long timeout = millis(); + esp8266::polledTimeout::oneShotMs timeOut(streamTimeout); if (_progress_callback) { _progress_callback(0, _size); } @@ -464,7 +465,7 @@ size_t UpdaterClass::writeStream(Stream &data, uint16_t streamTimeout) { } toRead = data.readBytes(_buffer + _bufferLen, bytesToRead); if(toRead == 0) { //Timeout - if (millis() - timeout > streamTimeout) { + if (timeOut) { _currentAddress = (_startAddress + _size); _setError(UPDATE_ERROR_STREAM); _reset(); @@ -472,7 +473,7 @@ size_t UpdaterClass::writeStream(Stream &data, uint16_t streamTimeout) { } delay(100); } else { - timeout = millis(); + timeOut.reset(); } if(_ledPin != -1) { digitalWrite(_ledPin, !_ledOn); // Switch LED off