Closed KiwiDave23 closed 10 months ago
Usually that means the version is wrong. What happens if you run the scanner? python3 -m tinytuya scan
Well that was an easy fix. Thanks! Changed to version 3.4.
My code read the power data from 5 smart plugs, then the temperature from a temp/humidity probe and then creates a new thread for 2 minutes time, to do the same job again.
The temperature probe is giving me troubles. Sometimes it works for a few read cycles, other times it works for hours but eventuallly it gives: {'Error': 'Network Error: Device Unreachable', 'Err': '905', 'Payload': None}
even when I'm getting this it seems to be communicating with the cloud OK and I can ping it from the dos prompt.
It's not to me if it every recovers from this. I can force it to recover by cycling the power to the temp probe.
Note the temp probe is USB powered, not battery powered.
Any ideas?
Once it stops running, does it continue to fail until you power cycle it?
If not, you could try:
d.set_socketPersistent(True)
) which will keep socket / TCP open - you may need to ping more frequently or send heartbeat (e.g. d.send(d.generate_payload(tinytuya.HEART_BEAT)
)
I'm brand new to GitHub and quite new to tinytuya. Quite basic python.
I'm getting the error: {'Error': 'Unexpected Payload from Device', 'Err': '904', 'Payload': None}
So here is what I have tried.
I am using tinytuya successfully to control/pole smart plugs and now want to interogate a temperature/humidity alarm. I used the wizard to get this: { "name": "Fang Temperature", "id": "bfdfa47429a09b89bebbzl", "key": "rc^z?kyp2nqyO}^Q", "mac": "1c:90:ff:48:e8:32", "uuid": "67d0a72aa8db5a8c", "sn": "JX20221203603079", "category": "wsdcg", "product_name": "Temperature and humidity alarm", "product_id": "rocfghml4gy1vvr8", "biz_type": 18, "model": "AS90", "sub": false, "icon": "https://images.tuyaeu.com/smart/icon/ay1562583874631k02Aw/a4723e20b84980766269881ce96d773b.png" },
I pasted this at the dos prompt: curl --request GET "https://openapi.tuyaeu.com/v2.0/cloud/thing/batch?device_ids=bfdfa47429a09b89bebbzl" --header "sign_method: HMAC-SHA256" --header "client_id: xagdxjagjek4jtjggng3" --header "t: 1692307047419" --header "mode: cors" --header "Content-Type: application/json" --header "sign: E9900D06BE6847CA9EC3112CF44EC4B172CD74683383726970FD37FB80197804" --header "access_token: 16083565d77ccf7a6b40eb8306a90494"
I got this result: {"result":[{"active_time":1692303352,"category":"wsdcg","create_time":1692259406,"custom_name":"Fang Temperature","icon":"smart/icon/ay1562583874631k02Aw/a4723e20b84980766269881ce96d773b.png","id":"bfdfa47429a09b89bebbzl","ip":"124.149.228.148","is_online":true,"lat":"-37.9700","local_key":"rc^z?kyp2nqyO}^Q","lon":"145.0500","model":"AS90","name":"Temperature and humidity alarm","product_id":"rocfghml4gy1vvr8","product_name":"WIFI温湿度报警器","sub":false,"time_zone":"+10:00","update_time":1692303352,"uuid":"67d0a72aa8db5a8c"}],"success":true,"t":1692307056484,"tid":"7d023dde3d4311eeb3f09e6a0abc163a"}
I ran this code in pycharm: import tinytuya
tinytuya.set_debug(True) # use tinytuya.set_debug(True,False) for non-ANSI color terminal
Device_ID = r"bfdfa47429a09b89bebbzl" local_key = r"rc^z?kyp2nqyO}^Q" IP = "192.168.1.63"
d = tinytuya.OutletDevice(Device_ID, IP, local_key) d.set_version(3.3) d.set_socketPersistent(True) data = d.status() print(data)
And got this result: DEBUG:TinyTuya [1.12.9]
DEBUG:Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32 DEBUG:Using PyCrypto (3, 18, '0') DEBUG:status() entry (dev_type is default) DEBUG:final payload_dict for 'bfdfa47429a09b89bebbzl' ('v3.3'/'default'): {1: {'command': {'gwId': '', 'devId': '', 'uid': '', 't': ''}}, 7: {'command': {'devId': '', 'uid': '', 't': ''}}, 8: {'command': {'gwId': '', 'devId': ''}}, 9: {'command': {'gwId': '', 'devId': ''}}, 10: {'command': {'gwId': '', 'devId': '', 'uid': '', 't': ''}}, 13: {'command': {'devId': '', 'uid': '', 't': ''}}, 16: {'command': {'devId': '', 'uid': '', 't': ''}}, 18: {'command': {'dpId': [18, 19, 20]}}, 64: {'command': {'reqType': '', 'data': {}}}} DEBUG:building command 10 payload=b'{"gwId":"bfdfa47429a09b89bebbzl","devId":"bfdfa47429a09b89bebbzl","uid":"bfdfa47429a09b89bebbzl","t":"1692307111"}' DEBUG:sending payload DEBUG:payload encrypted=b'000055aa000000010000000a000000885ec1a2d2f74bda40b5925db7533d72061ffac6238ae34cb20949cc8e37193c109043324b2a3684ef1b7079bf539f8bb88ec811d795f1fedf7d439534eb3054b4fa9eb3e40e62ee1293ac012b250ad5ad1ffac6238ae34cb20949cc8e37193c10b2b9f7d8bdec280fae1ae968163f8f1e5021c4c9b552d9fbe92e07b3746bcc2cd196a81f0000aa55' DEBUG:_recv_all(): no data? b'' DEBUG:_recv_all(): no data? b'' DEBUG:Error decoding received data - read retry 0/5 Traceback (most recent call last): File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 1049, in _send_receive rmsg = self._receive() ^^^^^^^^^^^^^^^ File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 939, in _receive data = self._recv_all( min_len ) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 920, in _recv_all raise DecodeError('No data received - connection closed?') tinytuya.core.DecodeError: No data received - connection closed? DEBUG:_recv_all(): no data? b'' DEBUG:_recv_all(): no data? b'' DEBUG:Error decoding received data - read retry 1/5 Traceback (most recent call last): File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 1049, in _send_receive rmsg = self._receive() ^^^^^^^^^^^^^^^ File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 939, in _receive data = self._recv_all( min_len ) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 920, in _recv_all raise DecodeError('No data received - connection closed?') tinytuya.core.DecodeError: No data received - connection closed? DEBUG:_recv_all(): no data? b'' DEBUG:_recv_all(): no data? b'' DEBUG:Error decoding received data - read retry 2/5 Traceback (most recent call last): File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 1049, in _send_receive rmsg = self._receive() ^^^^^^^^^^^^^^^ File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 939, in _receive data = self._recv_all( min_len ) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 920, in _recv_all raise DecodeError('No data received - connection closed?') tinytuya.core.DecodeError: No data received - connection closed? DEBUG:_recv_all(): no data? b'' DEBUG:_recv_all(): no data? b'' DEBUG:Error decoding received data - read retry 3/5 Traceback (most recent call last): File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 1049, in _send_receive rmsg = self._receive() ^^^^^^^^^^^^^^^ File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 939, in _receive data = self._recv_all( min_len ) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 920, in _recv_all raise DecodeError('No data received - connection closed?') tinytuya.core.DecodeError: No data received - connection closed? DEBUG:_recv_all(): no data? b'' DEBUG:_recv_all(): no data? b'' DEBUG:Error decoding received data - read retry 4/5 Traceback (most recent call last): File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 1049, in _send_receive rmsg = self._receive() ^^^^^^^^^^^^^^^ File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 939, in _receive data = self._recv_all( min_len ) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 920, in _recv_all raise DecodeError('No data received - connection closed?') tinytuya.core.DecodeError: No data received - connection closed? DEBUG:_recv_all(): no data? b'' DEBUG:_recv_all(): no data? b'' DEBUG:Error decoding received data - read retry 5/5 Traceback (most recent call last): File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 1049, in _send_receive rmsg = self._receive() ^^^^^^^^^^^^^^^ File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 939, in _receive data = self._recv_all( min_len ) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Dave\AppData\Local\Programs\Python\Python311\Lib\site-packages\tinytuya\core.py", line 920, in _recv_all raise DecodeError('No data received - connection closed?') tinytuya.core.DecodeError: No data received - connection closed? DEBUG:ERROR Unexpected Payload from Device - 904 - payload: null DEBUG:status() received data={'Error': 'Unexpected Payload from Device', 'Err': '904', 'Payload': None} {'Error': 'Unexpected Payload from Device', 'Err': '904', 'Payload': None}
Process finished with exit code 0