blynk-library-python icon indicating copy to clipboard operation
blynk-library-python copied to clipboard

RPI disconnects

Open ebolisa opened this issue 2 years ago • 8 comments

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

ebolisa avatar Sep 23 '21 23:09 ebolisa

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'

Judas2016 avatar Oct 14 '21 02:10 Judas2016

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

ebolisa avatar Oct 14 '21 08:10 ebolisa

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

Judas2016 avatar Oct 14 '21 17:10 Judas2016

Only with ESP not with Raspberry

ebolisa avatar Oct 14 '21 19:10 ebolisa

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.

Judas2016 avatar Nov 04 '21 20:11 Judas2016

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

jonathongardner avatar Jan 25 '22 01:01 jonathongardner

@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.

ebolisa avatar Jan 25 '22 08:01 ebolisa

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

jonathongardner avatar Jan 25 '22 19:01 jonathongardner