Skip to content

Commit

Permalink
Merge pull request #1 from adrionics/adrionics-patch-updater-stream-t…
Browse files Browse the repository at this point in the history
…imeout

Update Updater.cpp
  • Loading branch information
adrionics authored May 19, 2019
2 parents 3835991 + 07e30d6 commit 0328fde
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions cores/esp8266/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -446,6 +446,7 @@ size_t UpdaterClass::writeStream(Stream &data) {
_reset();
return 0;
}
unsigned long timeout = millis();
if (_progress_callback) {
_progress_callback(0, _size);
}
Expand All @@ -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
Expand Down

0 comments on commit 0328fde

Please sign in to comment.