Skip to content

Commit

Permalink
[OTA] Fix "Error response from device" if OK response comes to early (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Gei0r authored and me-no-dev committed Jul 30, 2018
1 parent a7ddf39 commit bdc45e3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tools/espota.py
Expand Up @@ -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')
Expand All @@ -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:
Expand Down

0 comments on commit bdc45e3

Please sign in to comment.