From bdc45e39efa6179e163bc5cdf805e813c06548b7 Mon Sep 17 00:00:00 2001 From: Gei0r Date: Mon, 30 Jul 2018 09:22:01 +0200 Subject: [PATCH] [OTA] Fix "Error response from device" if OK response comes to early (#1695) 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 1aa54256..8abdffb3 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: