vshymanskyy / blynk-library-python

Blynk library for Python. Works with Python 2, Python 3, MicroPython.

Home Page:https://blynk.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pycom Lopy4 disconnects

275RR opened this issue · comments

commented

Similar to RPI disconnects #58

I'm able to successfully connect to the Blynk Cloud but quickly crash with OSError: [Errno 104] ECONNRESET.
I believe this might be a SSL socket issue when writing in blynk-library-python. I do not get the error when running insecure=True.

Current firmware and blynk-library as of 10-28-2021:
I'm using a Pycom LoPy 4 (1.20.2.r6) which has MicroPython (v1.11-c5a0a97).

Connecting to Blynk...
Connecting to blynk.cloud:443...
Blynk ready. Ping: 9048 ms
Current slider value: 4
V3 value: ['4']
Traceback (most recent call last):
  File "main.py", line 45, in <module>
  File "main.py", line 42, in runLoop
  File "/flash/lib/BlynkLib.py", line 261, in run
  File "/flash/lib/BlynkLib.py", line 141, in process
  File "/flash/lib/BlynkLib.py", line 117, in _send
  File "/flash/lib/BlynkLib.py", line 249, in _write
OSError: [Errno 104] ECONNRESET

Any ideas how to fix this?

commented

I think SSL is failing to handshake. It just doesn't error until a write? non-blocking

MicroPython SSL
Pycom SSL

I think ssl_context is not supported by Pycom and upstream by MicroPython?

Is there anyway to still use SSL?

I am running into this on RPI4 as well. Disconnect and reconnect fix sometimes, but very random.

File "/usr/src/xxx/src/lib/blynk.py", line 349, in change_color
blynk.set_property(pin, "color", color)
File "/usr/local/lib/python3.7/site-packages/BlynkLib.py", line 90, in set_property
self._send(MSG_PROPERTY, pin, prop, *val)
File "/usr/local/lib/python3.7/site-packages/BlynkLib.py", line 117, in _send
self._write(msg)
File "/usr/local/lib/python3.7/site-packages/BlynkLib.py", line 249, in _write
self.conn.write(data)
File "/usr/local/lib/python3.7/ssl.py", line 948, in write
return self._sslobj.write(data)
BrokenPipeError: [Errno 32] Broken pipe

commented

Also having a very similar issue. ESP32-S2 (featherS2 board)

(Actually using circuitpython rather than micropython. Which has a different socket implementation using socketpool, so have made changes to the library to try to get this working.)

If I don't use SSL (insecure=True) then I get
OSError: [Errno 104] ECONNRESET

If I use SSL, it completely crashes and ressets the board at the _write() function.

I also had trouble with micropython, but will switch back to that now and try from there.

I found the original issue causing my ssl failures, I had legacy code from blynk v1 that was setting table values. I removed that line of code and the broken pipe above is no longer happening.

I am however seeing random connection refused error messages in my logs. They appear to be pure TCP connectivity issues - either my side or the service side causing the socket connection issues.

I have also tweaked the startup parameters for Blynk, I think this has also improved stability of the socket connection.

blynk = BlynkLib.Blynk(AUTHKEY, buffin=2048, heartbeat=100)