Skip to content

Commit

Permalink
Backport: ArduinoOTA upload intermittent failure fixed
Browse files Browse the repository at this point in the history
Backport of #4657
  • Loading branch information
Jason2866 authored Feb 5, 2024
1 parent de1774b commit 6aaa63c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions libraries/ArduinoOTA/src/ArduinoOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void ArduinoOTAClass::_runUpdate() {
if (!waited){
if(written && tried++ < 3){
log_i("Try[%u]: %u", tried, written);
if(!client.printf("%u", written)){
if(!client.printf("%lu", written)){
log_e("failed to respond");
_state = OTA_IDLE;
break;
Expand Down Expand Up @@ -315,14 +315,18 @@ void ArduinoOTAClass::_runUpdate() {
size_t r = client.read(buf, available);
if(r != available){
log_w("didn't read enough! %u != %u", r, available);
if((int32_t) r<0) {
delay(1);
continue; //let's not try to write 4 gigabytes when client.read returns -1
}
}

written = Update.write(buf, r);
if (written > 0) {
if(written != r){
log_w("didn't write enough! %u != %u", written, r);
}
if(!client.printf("%u", written)){
if(!client.printf("%lu", written)){
log_w("failed to respond");
}
total += written;
Expand Down

0 comments on commit 6aaa63c

Please sign in to comment.