vshymanskyy / blynk-library-python

Blynk library for Python. Works with Python 2, Python 3, MicroPython.
https://blynk.io/
MIT License
281 stars 97 forks source link

RPI disconnects #58

Open ebolisa opened 2 years ago

ebolisa commented 2 years ago

Raspberry pi (any) with ethernet connection.

The code works fine for few minutes then disconnects with no errors. Tried to set up line 'blynk = BlynkLib.Blynk(BLYNK_AUTH)' to 'blynk = BlynkLib.Blynk(BLYNK_AUTH, insecure= True)' but I get error: AttributeError: 'socket' object has no attribute 'write'

The option 'insecure=True' works fine on ESP32s however.

Any ideas? TIA

Judas2016 commented 2 years ago

I am having the same problem on MacOS. ./manual_tests/test_blynkV2.py::BlynkPublisherTest::test_pushvalue Failed with Error: 'socket' object has no attribute 'write' File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/unittest/case.py", line 59, in testPartExecutor yield File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/unittest/case.py", line 615, in run testMethod() File "/Users/jeff/GitHub/wiab/tests/manual_tests/test_blynkV2.py", line 28, in test_pushvalue blynk = BlynkLib.Blynk(BLYNK_AUTH_TOKEN, insecure=True) File "/Users/jeff/GitHub/wiab/.env/lib/python3.7/site-packages/BlynkLib.py", line 214, in init BlynkProtocol.init(self, auth, **kwargs) File "/Users/jeff/GitHub/wiab/.env/lib/python3.7/site-packages/BlynkLib.py", line 81, in init self.connect() File "/Users/jeff/GitHub/wiab/.env/lib/python3.7/site-packages/BlynkLib.py", line 245, in connect BlynkProtocol.connect(self) File "/Users/jeff/GitHub/wiab/.env/lib/python3.7/site-packages/BlynkLib.py", line 125, in connect self._send(MSG_HW_LOGIN, self.auth) File "/Users/jeff/GitHub/wiab/.env/lib/python3.7/site-packages/BlynkLib.py", line 117, in _send self._write(msg) File "/Users/jeff/GitHub/wiab/.env/lib/python3.7/site-packages/BlynkLib.py", line 249, in _write self.conn.write(data) AttributeError: 'socket' object has no attribute 'write'

ebolisa commented 2 years ago

@Judas2016 It's not OS related but library. It appears to be a timing problem between the client and server.

Judas2016 commented 2 years ago

Did you have any luck in getting it to work with SSL?

ebolisa commented 2 years ago

Only with ESP not with Raspberry

Judas2016 commented 2 years ago

I got SSL working on macOS and the library works as expected now. I updated the version of Python to latest 3.9 from 3.7 and solved the problem.

jonathongardner commented 2 years ago

Im noticing the same issue with my RPI disconnecting.

It looks like when the socket tries to read here (and there's no data) you get a timeout so this line doesn't get called for a while. Then when it eventually does get called depending on how long its been these lines get called and it disconnects.

Not sure if this is a bug in the code or if the conn.read is expecting the blynk server to send data/heartbeat. I honestly just removed those two lines (136-137) and my RPI stoped disconnecting and the project has been working.

If this is a bug in the code than I'm sure there is a more elegant way to fix this

ebolisa commented 2 years ago

@jonathongardner Interesting! Which server are you using? The central or the assigned one? In my case, the connection works better with the assigned one being it lon1 or fran1.

jonathongardner commented 2 years ago

Yeah I'm just using the default one in the package