The TCP reset issue #2
Comments
@nijave I think the best way forward here is to add logging to your component, in https://github.com/nijave/home-assistant/blob/component-tuya/homeassistant/components/switch/tuya.py in the except block. Dump the exception that is seen. |
Here is a zip of a pcap (from Wireshark) that shows a successful connection followed by what appears to be the outlet/Tuya device terminating the next request with a RST,ACK (see https://stackoverflow.com/questions/1434451/what-does-connection-reset-by-peer-mean) 172.16.2.1 is home-assistant Both times it's requesting the status from the device and the requests appear to be exactly the same except for the packet headers |
|
I've not had chance to review the pcap file, sorry :( Recommend we add an exception catch for ConnectionResetError is you are consistently seeing this. As a first step, add that to your HA component (remove the bare except there at the moment). For a quick test I wrote a script that hammered status checks:
I can't get it to fail consistently BUT I'm seeing something different. invalid json (so no severed connection error). I wonder if this is firmware related? If so, we need to deal with it BUT I want to understand any fix we use :-)
I'm not going to get chance to work on this again today. I need to dump the payload I'm getting. |
This one isn't as important since there's a workaround--just annoying. I suspect it may be quite difficult to debug as well. It's possible it depends on the particular plug + firmware. Someone else was having mostly success and occasional failures: home-assistant/core#11000 (comment) |
Whilst experimenting I also saw:
This is under python 2.7. Suspect this is the same thing as original report. NOTE I've not seen this under Py3 yet on my machine, super odd. |
Opened issue #6 for the issue I'm seeing/ |
Idea to reproduce error:
open socket and send garbage? |
I observed the same error when I tried to connect while the eFamilyCloud was opened. Might that be related? |
Linking Issue #11, exception handling for both will be the same |
On what I think is an unstable wifi network (been experimenting, and Alexa can't always consistently turn off a device that was fine on home network, sometimes fails multiple times in a row and I have to wait) seeing errors on connect: Windows Python 2.7:
3.6.1
|
I believe the devices can connect to only one TCP client at a time. I see "Connection reset by peer" after controlling the device with the Smart Life app. A minute or two later python-tuya starts working again. |
Same experience here... |
I'm seeing this as well. My experience is with hassbian (Home Assistant)
I tried using socket.sendall with same result EDIT: I tried lowering the requested status interval to 60 seconds and didn't fail for about 8 min but then it start acting up again. So limiting the amount of request to the device seems to help. |
@ImNightwing reducing number of hits to device is what I ended up doing too. I also have an Amazon Echo hooked up and that talks directly to the device and even then it sometimes does not respond (and its the only thing on the network talking to it). I once had a device get lock up and I had to unplug/replug so the devices themselves whilst good are not 100% |
I was having trouble with my devices resetting the connection immediately as well, but I found that (for the MS frame work) turning off data buffering had an immediate improvement in the device sending data back. The MS option is https://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.nodelay(v=vs.110).aspx I suspect there is an equivalent option in your frame work. It looks like if the device does not receive data fairly quickly after a connection it resets the connection. |
Suggestion from BillSobel in #2 (comment)
Thanks @BillSobel, that is odd. I've not seen that under Windows but enabling no delay as there is only one send/recieve makes this a very reasonable/easy change to make. This may help if anyone tries to run under IronPython. Posted 01c123f I'm not using Iron Python but I ran a quick test with
needs config files and device id. |
@dadler - I can confirm that was my problem -- it appears the device can only have one open connection. While I had the app on my phone open, I couldn't make a connection with pytuya. Once I closed the app, I was able to connect again. |
Hello, I had recently bought HORSKY socket (https://www.amazon.fr/dp/B0774LKY3K/) and it works great !
Some infos if it can help you :
I'm a beginner in Python, but if i can help you, it's a pleasure 👍 |
Any update on this? |
Need more info., see issue #1
Original reported issue by @nijave:
Under Linux Python 3
@clach04 saw:
This is under python 2.7. Suspect this is the same thing as original report.
NOTE I've not seen this under Py3 yet on my machine but I've had long runs when this never occurs.
The text was updated successfully, but these errors were encountered: