Skip to content

Commit 6aaa63c

Browse files
authored
Backport: ArduinoOTA upload intermittent failure fixed
Backport of espressif#4657
1 parent de1774b commit 6aaa63c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

libraries/ArduinoOTA/src/ArduinoOTA.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void ArduinoOTAClass::_runUpdate() {
287287
if (!waited){
288288
if(written && tried++ < 3){
289289
log_i("Try[%u]: %u", tried, written);
290-
if(!client.printf("%u", written)){
290+
if(!client.printf("%lu", written)){
291291
log_e("failed to respond");
292292
_state = OTA_IDLE;
293293
break;
@@ -315,14 +315,18 @@ void ArduinoOTAClass::_runUpdate() {
315315
size_t r = client.read(buf, available);
316316
if(r != available){
317317
log_w("didn't read enough! %u != %u", r, available);
318+
if((int32_t) r<0) {
319+
delay(1);
320+
continue; //let's not try to write 4 gigabytes when client.read returns -1
321+
}
318322
}
319323

320324
written = Update.write(buf, r);
321325
if (written > 0) {
322326
if(written != r){
323327
log_w("didn't write enough! %u != %u", written, r);
324328
}
325-
if(!client.printf("%u", written)){
329+
if(!client.printf("%lu", written)){
326330
log_w("failed to respond");
327331
}
328332
total += written;

0 commit comments

Comments
 (0)