Skip to content

Commit 9632e86

Browse files
Fix espota completion success/fail check (#7204)
The OTA script was not reporting the actual reported upload status from the ESP8266, and instead always printed "Result: OK" no matter what happened. Now check for ERROR or OK in final message (and ensure the message is not accidentally merged with the final byte count) and report properly. Fixes #7162
1 parent 1af4ea6 commit 9632e86

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

Diff for: libraries/ArduinoOTA/ArduinoOTA.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,13 @@ void ArduinoOTAClass::_runUpdate() {
328328
}
329329

330330
if (Update.end()) {
331+
// Ensure last count packet has been sent out and not combined with the final OK
332+
client.flush();
333+
delay(1000);
331334
client.print("OK");
332-
client.stop();
335+
client.flush();
333336
delay(1000);
337+
client.stop();
334338
#ifdef OTA_DEBUG
335339
OTA_DEBUG.printf("Update Success\n");
336340
#endif

Diff for: tools/espota.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
132132
sys.stderr.write('FAIL\n')
133133
logging.error('%s', data)
134134
sock2.close()
135-
sys.exit(1);
135+
sys.exit(1)
136136
return 1
137137
sys.stderr.write('OK\n')
138138
else:
@@ -172,7 +172,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
172172
connection.sendall(chunk)
173173
if connection.recv(32).decode().find('O') >= 0:
174174
# connection will receive only digits or 'OK'
175-
received_ok = True;
175+
received_ok = True
176176
except:
177177
sys.stderr.write('\n')
178178
logging.error('Error Uploading')
@@ -188,19 +188,25 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm
188188
# the connection before receiving the 'O' of 'OK'
189189
try:
190190
connection.settimeout(60)
191-
while not received_ok:
192-
if connection.recv(32).decode().find('O') >= 0:
193-
# connection will receive only digits or 'OK'
194-
received_ok = True;
195-
logging.info('Result: OK')
191+
received_ok = False
192+
received_error = False
193+
while not (received_ok or received_error):
194+
reply = connection.recv(64).decode()
195+
# Look for either the "E" in ERROR or the "O" in OK response
196+
# Check for "E" first, since both strings contain "O"
197+
if reply.find('E') >= 0:
198+
sys.stderr.write('\n')
199+
logging.error('%s', reply)
200+
received_error = True
201+
elif reply.find('O') >= 0:
202+
logging.info('Result: OK')
203+
received_ok = True
196204
connection.close()
197205
f.close()
198206
sock.close()
199-
if (data != "OK"):
200-
sys.stderr.write('\n')
201-
logging.error('%s', data)
202-
return 1;
203-
return 0
207+
if received_ok:
208+
return 0
209+
return 1
204210
except:
205211
logging.error('No Result!')
206212
connection.close()

0 commit comments

Comments
 (0)