From 533194253b8bb34209d3f70465218b285824687f Mon Sep 17 00:00:00 2001 From: Adrian Ebeling Date: Sun, 29 Jul 2018 20:24:33 +0200 Subject: [PATCH] [OTA] Fix "Error response from device" if OK response comes to early Because TCP is stream-based, an earlier read can 'take away' the "OK" response from the device, so that a later read doesn't get the message. --- tools/espota.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/espota.py b/tools/espota.py index 1aa542561f3..8abdffb3ac3 100755 --- a/tools/espota.py +++ b/tools/espota.py @@ -179,6 +179,7 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm try: connection.sendall(chunk) res = connection.recv(10) + lastResponseContainedOK = 'OK' in res.decode() except: sys.stderr.write('\n') logging.error('Error Uploading') @@ -187,6 +188,13 @@ def serve(remoteAddr, localAddr, remotePort, localPort, password, filename, comm sock.close() return 1 + if lastResponseContainedOK: + logging.info('Success') + connection.close() + f.close() + sock.close() + return 0 + sys.stderr.write('\n') logging.info('Waiting for result...') try: