ClusterM / tuyanet

.NET library to interface with Tuya WiFi smart devices over LAN.
GNU General Public License v3.0
56 stars 10 forks source link

Devices not connecting time out #3

Open jgric2 opened 1 year ago

jgric2 commented 1 year ago

I have set up a project as per the readme, I am able to see all the devices when calling GetAllDevicesInfoAsync(), I also have the correct region set, However when trying to send commands to my smart LED bulb. However I keep getting an exception where the api cant connect to the bulb, the IP address and all other details seem correct but the code locks up at this line in TuyaDevice.cs: if (!client.ConnectAsync(IP, Port).Wait(ConnectionTimeout)) throw new IOException("Connection timeout"); It seems at the IP connection to the device despite the IP being correct the API times out and cannot connect to the bulb, I have tried to debug it with no luck. I am able to get other TUYA api's working with my devices however I want to use yours as its locally over the network and has support for the IR Blaster devices.

If you could let me know whats going on I would be very greatful. To the best of my knowledge the bulb and the details i have got from the tuya development page are correct.

James

Verthosa commented 1 year ago

I have the same problem :(

lellis1936 commented 1 year ago

I've seen this but it is intermittent. It's likely that the device only permits one connection at a time. When all connections are funneled through the cloud (Alexa, Smart Home app, etc), it's not a problem. But when your local access tries to connect and some other connection is active (e.g. the cloud doing a status check) the attempt will fail.

If I am correct, the ugly solution is to manage your device exclusively locally (remove it from the cloud completely and register it to your locally-running app). Alternatively you can retry periodically until your request succeeds, but I don't know how many attempts would be required; it's a crap shoot. SendAsync has some parameters for doing retries.

Other things that may have to be handled (and that can cause connection failure): 1) the local key can change, 2) the local IP can change.

ClusterM commented 1 year ago

It can be because of protocol version mismatch. I heard that there is new version - 3.4. Maybe it's the problem.

jgric2 commented 1 year ago

I will investigate again in a few days, back from vacation :),

thundr89 commented 1 year ago

A little late, but i have a same error when i want to set dp-s represented in the readme. For example: turn on/off dp is 1 in readme, but this is 24 for my ceiling lamp. I hope this info is helpful guys :)