codetheweb / tuyapi

🌧 An easy-to-use API for devices that use Tuya's cloud services. Documentation: https://codetheweb.github.io/tuyapi.
MIT License
2.1k stars 343 forks source link

protocol 3.3 ? #424

Closed msillano closed 3 years ago

msillano commented 3 years ago

Describe the bug

This morning I start testing a new device (Smart Breaker: https://www.aliexpress.com/item/1005001863612580.html) using tuyaDAEMON (https://github.com/msillano/tuyaDAEMON wth tuyapi 6.1.1).

1) The switch is easily connected to smartlife, then I catch ids with tuya-cli, all ok: in the morning I do many tests, all works like a charm.

2) In the afternoon: very slow responses, many disconnections (?) So I make an error: I deleted the device on smartlife and reconnected it. From that, if I do a command, the captured MQTT is undecoded by tuyapi.

Maybe a firmware upgrade? But without any warning message !?. Auto-update OFF, the tuya version is not changed (1.0.7 both).

Debug Output

  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +4ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms
  TuyAPI Pong from 192.168.1.244 +1ms
  TuyAPI Received data: 000055aa00000000000000080000004b00000000332e330000000000004ac8000000015588da04789f316692235a35277fe3e0a3fd2c500fbc0c1c3b4ad37124bc475b543475c5de42b47e13a9aa6189b9eada0285dc5b0000aa55 +7s
  TuyAPI Parsed: +1ms
  TuyAPI {
  TuyAPI   payload: "3.3\x00\x00\x00\x00\x00\x00J�\x00\x00\x00\x01U��\x04x�1f�#Z5'\x7F���,P\x0F�\f\x1C;J�q$�G[T4u��B�~\x13��a����",
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 8,
  TuyAPI   sequenceN: 0
  TuyAPI } +6ms

16 Feb 18:40:45 - [info] [tuya-smart-device:cb5af4dc.7cb258] Data from device: "3.3\u0000\u0000\u0000\u0000\u0000\u0000J�\u0000\u0000\u0000\u0001U��\u0004x�1f�#Z5'���,P\u000f�\f\u001c;J�q$�G[T4u��B�~\u0013��a����"

16 Feb 18:40:45 - [warn] [function:*OUT data process] ERROR from 'smart breaker #3': not JSON data but HEX:332e330000000000004aefbfbd0000000155efbfbdefbfbd0478efbfbd3166efbfbd235a35277fefbfbdefbfbdefbfbd2c500fefbfbd0c1c3b4aefbfbd7124efbfbd475b543475efbfbdefbfbd42efbfbd7e13efbfbdefbfbd61efbfbdefbfbdefbfbdefbfbd  ('3.3  J�   U��x�1f�#Z5'���,P�;J�q$�G[T4u��B�~��a����')

  TuyAPI Pinging 192.168.1.175 +3s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +7ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms
  TuyAPI Pong from 192.168.1.175 +4ms
  TuyAPI Pinging 192.168.1.244 +207ms

This is not the unique device with this behavior: also a 'siren' does the same, but from the first start. What I found very strange in the events is the change of the device's responses.

Desktop:

Best Regards, m.s.

stevoh6 commented 3 years ago

When you unregister/remove and add again the device from mobile app, device will have new key for encoding/decoding messages.

Simply get new keys, update configs and everything will be fine again ;) This behaviour is known also mentioned in documentation.

msillano commented 3 years ago

Thanks, I been stupid :( Of course, tested and now all work fine: id was the same, but the key is changed. So I can eval the response undecoded from tuyapi like

 TuyAPI   payload: "3.3\x00\x00\x00\x00\x00\x00J�\x00\x00\x00\x01U��\x04x�1f�#Z5'\x7F���,P\x0F�\f\x1C;J�q$�G[T4u��B�~\x13��a����",

as an indication of bad key ? OK. Best regards m.s.