Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEBUG:ERROR Network Error: Unable to Connect - 901 - payload: null #499

Closed
xyz-09 opened this issue May 18, 2024 · 5 comments
Closed

DEBUG:ERROR Network Error: Unable to Connect - 901 - payload: null #499

xyz-09 opened this issue May 18, 2024 · 5 comments
Labels
setup help Support questions for using tinytuya tuya_device Support for specific Tuya Devices

Comments

@xyz-09
Copy link

xyz-09 commented May 18, 2024

I have an issue, with debug mode i've got

It is WS2185 lightStrip with tuya :) controller

Protocol for conections is 3.5

I'v checked all crypto library: pyca/cryptography, PyCryptodomex, PyCrypto

DEBUG:Using pyca/cryptography 3.3.2 for crypto, GCM is supported
Traceback (most recent call last):
  File "***/.local/lib/python3.9/site-packages/tinytuya/core.py", line 1010, in _get_socket
    if self._negotiate_session_key():
  File "***/.local/lib/python3.9/site-packages/tinytuya/core.py", line 1435, in _negotiate_session_key
    rkey = self._send_receive_quick( self._negotiate_session_key_generate_step_1(), 2 )
  File "***/.local/lib/python3.9/site-packages/tinytuya/core.py", line 1119, in _send_receive_quick
    enc_payload = self._encode_message(payload) if type(payload) == MessagePayload else payload
  File "***/.local/lib/python3.9/site-packages/tinytuya/core.py", line 1530, in _encode_message
    data = pack_message(msg,hmac_key=self.local_key)
  File "***/.local/lib/python3.9/site-packages/tinytuya/core.py", line 484, in pack_message
    data2 = cipher.encrypt( raw, use_base64=False, pad=False, iv=True if not msg.iv else msg.iv, header=data[4:])
  File "***/.local/lib/python3.9/site-packages/tinytuya/core.py", line 295, in encrypt
    encryptor = Crypto( AES(self.key), Crypto_modes.GCM(iv) ).encryptor()
  File "/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/ciphers/algorithms.py", line 38, in __init__
    self.key = _verify_key_size(self, key)
  File "/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/ciphers/algorithms.py", line 21, in _verify_key_size
    raise ValueError(
ValueError: Invalid key size (136) for AES.
DEBUG:Using PyCryptodomex 3.9.7 for crypto, GCM is supported
Error: ValueError: Error 6 while instantiating the AES cipher
DEBUG:Using PyCryptodome 3.20.0 for crypto, GCM is supported
ValueError: Incorrect AES key length (17 bytes)
@jasonacox
Copy link
Owner

jasonacox commented May 18, 2024

Hi @xyz-09 -

  1. Can you sare the link to the device? I don't find anything matching WS2185 (but I do see a WS2815).
  2. Can you share the code you are using or are you just doing a scan python -m tinytuya scan -d?

@uzlonewolf
Copy link
Collaborator

ValueError: Incorrect AES key length (17 bytes)
ValueError: Invalid key size (136 [bits]) for AES.
(136 is 17 bytes * 8 bits)

It looks like your device key is wrong. How did you obtain it? python -m tinytuya wizard? Looks like it could be a copy/paste error since it is 1 byte too long.

@xyz-09
Copy link
Author

xyz-09 commented May 19, 2024

Yes its WS2815 but its led strip type 😄 my mistake

The controller: info from tuya developer panel:

  • RGB strip,
  • product category dd

Output from :
#260

Payload: b'{"ip":"xxx.xxx.x.xxx","gwId":"","uuid":"","active":2,"ablilty":0,"encrypt":true,"productKey":"","version":"3.5","token":true,"wf_cfg":true,"clientLink":3}'

I run simple script from example

import tinytuya

d = tinytuya.OutletDevice(
    dev_id='DEVICE_ID_HERE',
    address='IP_ADDRESS_HERE',      # Or set to 'Auto' to auto-discover IP address
    local_key='LOCAL_KEY_HERE', 
    version=3.3)


data = d.status() 
print('set_status() result %r' % data)


d.turn_on()

d.turn_off()

I run
python -m tinytuya scan
and
python -m tinytuya wizard

But both unsuccessful.

@xyz-09
Copy link
Author

xyz-09 commented May 20, 2024

ValueError: Incorrect AES key length (17 bytes)
ValueError: Invalid key size (136 [bits]) for AES.
(136 is 17 bytes * 8 bits)

It looks like your device key is wrong. How did you obtain it? python -m tinytuya wizard? Looks like it could be a copy/paste error since it is 1 byte too long.

There must have been something in it.

Today, I disconnected the controller from the app and from the power, then reconnected it to the app and to the power - thus obtaining a new key for the device.
Additionally, I started a second controller Tuya, supporting protocol 3.3.

Once again, I ran python3 -m tinytuya wizard

Both devices were found without problem.

I copied the local_key again - this time not from the terminal, but from the snapshot.json file.

I managed to get the status of both devices, as well as turn them on and off - so it's a SUCCESS.

It's a pity I wasted the whole Saturday and Sunday trying to connect - without doing the basic test - turn it off and on, disconnect and reconnect the device again.

Your code is a great job 👍
You are amazing 👍
Thank you for taking the time to write and maintain your code.
And Thank You for your help 🥇

@jasonacox
Copy link
Owner

Thanks @xyz-09 ! I'll close this issue.

@jasonacox jasonacox added tuya_device Support for specific Tuya Devices setup help Support questions for using tinytuya labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
setup help Support questions for using tinytuya tuya_device Support for specific Tuya Devices
Projects
None yet
Development

No branches or pull requests

3 participants