Skip to content

Small fix for espota.py: Don't know how to contribute #92

@Gei0r

Description

@Gei0r

Hi,
I had a small problem with OTA using platformio: The upload worked fine, but platformio reported "[ERROR]: Error response from device". I was able to fix the problem in espota.py. Now I want to contribute the fix, but I don't know where. Platformio does not seem to take the file from github, but rather from bintray.com. The "official" github version is different from the bintray one.

Anyway, here's the fix: The problem is that TCP is a stream-based protocol and the "OK" response from the ESP can be read by an earlier recv call. When espota.py later tries to receive the "OK" again, it is already gone.
Therefore I added a little flag that is set if a response contains "OK" so that we don't continue looking for it afterwards.

diff --git a/espota.py b/espota.py
index 1aa5425..8618e88 100755
--- a/espota.py
+++ b/espota.py
@@ -179,21 +179,21 @@ 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,13 +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:

How can I get this fix into platformio?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions