mirror of
https://github.com/esp8266/Arduino.git
synced 2025-05-03 20:44:46 +03:00
Update Updater.cpp
Improve timeout to allow reliable updates on slow networks.
This commit is contained in:
parent
b5560759ec
commit
07e30d60bc
@ -433,7 +433,7 @@ bool UpdaterClass::_verifyEnd() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t UpdaterClass::writeStream(Stream &data) {
|
size_t UpdaterClass::writeStream(Stream &data, uint16_t streamTimeout) {
|
||||||
size_t written = 0;
|
size_t written = 0;
|
||||||
size_t toRead = 0;
|
size_t toRead = 0;
|
||||||
if(hasError() || !isRunning())
|
if(hasError() || !isRunning())
|
||||||
@ -446,6 +446,7 @@ size_t UpdaterClass::writeStream(Stream &data) {
|
|||||||
_reset();
|
_reset();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
unsigned long timeout = millis();
|
||||||
if (_progress_callback) {
|
if (_progress_callback) {
|
||||||
_progress_callback(0, _size);
|
_progress_callback(0, _size);
|
||||||
}
|
}
|
||||||
@ -463,14 +464,15 @@ size_t UpdaterClass::writeStream(Stream &data) {
|
|||||||
}
|
}
|
||||||
toRead = data.readBytes(_buffer + _bufferLen, bytesToRead);
|
toRead = data.readBytes(_buffer + _bufferLen, bytesToRead);
|
||||||
if(toRead == 0) { //Timeout
|
if(toRead == 0) { //Timeout
|
||||||
delay(100);
|
if (millis() - timeout > streamTimeout) {
|
||||||
toRead = data.readBytes(_buffer + _bufferLen, bytesToRead);
|
|
||||||
if(toRead == 0) { //Timeout
|
|
||||||
_currentAddress = (_startAddress + _size);
|
_currentAddress = (_startAddress + _size);
|
||||||
_setError(UPDATE_ERROR_STREAM);
|
_setError(UPDATE_ERROR_STREAM);
|
||||||
_reset();
|
_reset();
|
||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
delay(100);
|
||||||
|
} else {
|
||||||
|
timeout = millis();
|
||||||
}
|
}
|
||||||
if(_ledPin != -1) {
|
if(_ledPin != -1) {
|
||||||
digitalWrite(_ledPin, !_ledOn); // Switch LED off
|
digitalWrite(_ledPin, !_ledOn); // Switch LED off
|
||||||
|
Loading…
x
Reference in New Issue
Block a user