platformio / platform-espressif8266

Espressif 8266: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/espressif8266
Apache License 2.0
327 stars 219 forks source link

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

Closed Gei0r closed 6 years ago

Gei0r commented 6 years ago

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?

ivankravets commented 6 years ago

We use this version https://github.com/espressif/arduino-esp32/blob/master/tools/espota.py

Gei0r commented 6 years ago

Thank you. My pull request there was merged. Can you incorporate the fix in platformio?

Maybe you can also change the link in tool-espotapy's package.json, so it points to your link?

ivankravets commented 6 years ago

Done! Please pio update.

Thanks for the report.