jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
867 stars 157 forks source link

Found device, but Network Error: Device Unreachable, Err: 905 #515

Open davrivas80 opened 3 days ago

davrivas80 commented 3 days ago

Hi there.

I am trying to connect locally to a Zigbee Gateway with no avail.

This is my simple code:

gw = tinytuya.Device( GATEWAY_ID, address=GATEWAY_IP, local_key=GATEWAY_KEY, persist=True, version=3.4 ) print( 'GW IP found:', gw.address ) print(gw.status())

This is what I get:

GW IP found: 192.168.1.80 {'Error': 'Network Error: Device Unreachable', 'Err': '905', 'Payload': None} Process finished with exit code 0

With DEBUG ON:

DEBUG:TinyTuya [1.14.0]

DEBUG:Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] on win32 DEBUG:Using pyca/cryptography 42.0.8 for crypto, GCM is supported DEBUG:status() entry (dev_type is default) DEBUG:final payload_dict for 'thisisthegatewayid' ('v3.4'/'default'): {1: {'command': {'gwId': '', 'devId': '', 'uid': '', 't': ''}}, 7: {'command': {'protocol': 5, 't': 'int', 'data': {}}, 'command_override': 13}, 8: {'command': {'gwId': '', 'devId': ''}}, 9: {'command': {'gwId': '', 'devId': ''}}, 10: {'command': {}, 'command_override': 16}, 13: {'command': {'protocol': 5, 't': 'int', 'data': {}}}, 16: {'command': {}}, 18: {'command': {'dpId': [18, 19, 20]}}, 64: {'command': {'reqType': '', 'data': {}}}} DEBUG:building command 10 payload=b'{}' DEBUG:socket unable to connect (timeout) - retry 1/5 DEBUG:socket unable to connect (timeout) - retry 2/5 DEBUG:socket unable to connect (timeout) - retry 3/5 DEBUG:socket unable to connect (timeout) - retry 4/5 DEBUG:socket unable to connect (timeout) - retry 5/5 DEBUG:ERROR Network Error: Device Unreachable - 905 - payload: null DEBUG:status() received data={'Error': 'Network Error: Device Unreachable', 'Err': '905', 'Payload': None}

Any clue?

uzlonewolf commented 1 day ago

It looks like either the IP address is wrong, or that gateway does not support local control. Does the scanner python3 -m tinytuya scan find it?

davrivas80 commented 1 day ago

Yes, scan can find it. IP address is correct.

It happens the same with three of my devices: a Zigbee Gateway (the above example, not really interested in polling it, but since it is the gateway to other devices if it is not reachable maybe those subdevices won't be either), a Smart Alarm, and a Smart Switch.

I have other devices I can reach without problem (some smart bulbs).

uzlonewolf commented 1 day ago

That particular "socket unable to connect" error only happens when a TCP connection to the device cannot be established at all - the IP address is wrong, the device is not listening for incoming connections, or a firewall is blocking the connection. I'd power cycle the device and try again. If it still does not work, what does the scanner say the 'Status:' is?

davrivas80 commented 1 day ago

Without modifying a single line of my code I managed to access the Zigbee Gateway and subdevices... I think it has something to do with the Tuya App. It seems a bit odd since it is something I had already discarded since the problems persisted even with my phone disconnected