jasonacox / tinytuya

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

v3.4 session key negotiation failed #400

Open warpkwd opened 10 months ago

warpkwd commented 10 months ago

I'm trying to get status from "ZY-M100-WIFI milli wave sonsor". But it's not well. script is

Example Usage of TinyTuya

import tinytuya d = tinytuya.OutletDevice('DEVICE_ID_HERE', 'IP_ADDRESS_HERE', 'LOCAL_KEY_HERE') d.set_version(3.4) data = d.status() print('Device status: %r' % data)

Please help me.

python mm_tes.py

DEBUG:TinyTuya [1.12.10]

DEBUG:Python 3.11.3 (main, Jun 1 2023, 06:45:39) [GCC 8.4.0] on linux DEBUG:Using PyCrypto (3, 9, '7') DEBUG:status() entry (dev_type is default) DEBUG:final payload_dict for 'eb744fa24f4bf4d5b1elsa' ('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:sending payload quick DEBUG:final payload: b'0123456789abcdef' DEBUG:payload encrypted=b'000055aa0000000100000003000000444585c45fb6194b854078f69e9102a332b939dd8e6dce29af713ab327dc0f417be05300d7a80c77cad41a7d3691fa63ee7f2b5ba55f0866ad473896497d9780db0000aa55' DEBUG:received null payload (None), fetch new one - 1 retries remaining DEBUG:_recv_all(): no data? b'' DEBUG:_recv_all(): no data? b'' DEBUG:received null payload (None) but out of recv retries, giving up DEBUG:session key negotiation failed on step 1 DEBUG:ERROR Check device key or version - 914 - payload: null DEBUG:status() received data={'Error': 'Check device key or version', 'Err': '914', 'Payload': None} Device status: {'Error': 'Check device key or version', 'Err': '914', 'Payload': None}

jasonacox commented 10 months ago

Hi @warpkwd

Two ideas:

  1. Did you use the wizard to get the local key? If so, what does it do during the device polling? I would suggest checking the local key and the version (3.4).
python3 -m tinytuya wizard -d
  1. Run the monitoring tool to see if it picks up anything more: https://github.com/jasonacox/tinytuya/blob/master/examples/monitor.py
warpkwd commented 10 months ago

Thanks@jasonacox

Is localkey change when changed ip address? I got ok response as getting local key by getting new scan. Thanks a lot.

jasonacox commented 10 months ago

The localkey will change anytime you use SmartLife app to pair the Tuya device (e.g. connect via "Add Device"). I don't know if that is what happened in your case, but I'm glad you were able to get it to work!