Skip to content

Improve timeout in Updater. #6117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions cores/esp8266/Updater.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Updater.h"
#include "eboot_command.h"
#include <esp8266_peri.h>
#include <PolledTimeout.h>
#include "StackThunk.h"

//#define DEBUG_UPDATER Serial
Expand Down Expand Up @@ -476,7 +477,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())
Expand All @@ -489,6 +490,7 @@ size_t UpdaterClass::writeStream(Stream &data) {
_reset();
return 0;
}
esp8266::polledTimeout::oneShotMs timeOut(streamTimeout);
if (_progress_callback) {
_progress_callback(0, _size);
}
Expand All @@ -506,13 +508,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);
return written;
}
if (timeOut) {
_currentAddress = (_startAddress + _size);
_setError(UPDATE_ERROR_STREAM);
_reset();
return written;
}
delay(100);
} else {
timeOut.reset();
}
if(_ledPin != -1) {
digitalWrite(_ledPin, !_ledOn); // Switch LED off
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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
Expand Down