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

Parse Data Errors #81

Open
t3h-n00b opened this issue Jul 23, 2020 · 17 comments
Open

Parse Data Errors #81

t3h-n00b opened this issue Jul 23, 2020 · 17 comments

Comments

@t3h-n00b
Copy link

t3h-n00b commented Jul 23, 2020

Hi,

Facing an issue with some new LED Strip Controllers. Originally bought these expecting to find an ESP inside to flash with Tasmota, but they use a W600 chip that rules that out...

Version of TuyAPI is 5.3.1.

I noted some similar issues (#23, #64), however all of those seemed to be resolved with protocol changes and some time ago - so wondering if this is yet another new protocol or similar...

Example Set commands:

DEBUG=* tuya-cli set --ip 192.168.2.Z --id XXXXX --key YYYYY --protocol-version 3.3 --dps 1 --set 1
  TuyAPI IP and ID are already both resolved. +0ms
  TuyAPI Connecting to 192.168.2.Z... +11ms
  TuyAPI Socket connected. +59ms
  TuyAPI GET Payload: +1ms
  TuyAPI {
  TuyAPI   gwId: 'XXXXX',
  TuyAPI   devId: 'XXXXX',
  TuyAPI   t: '1595491332',
  TuyAPI   dps: {},
  TuyAPI   uid: 'XXXXX'
  TuyAPI } +0ms
  TuyAPI SET Payload: +12ms
  TuyAPI {
  TuyAPI   devId: 'XXXXX',
  TuyAPI   gwId: 'XXXXX',
  TuyAPI   uid: '',
  TuyAPI   t: 1595491331,
  TuyAPI   dps: { '1': 1 }
  TuyAPI } +0ms
  TuyAPI Received data: 000055aa000000010000000a0000002c000000011fd12f2145a2b4e48d0bc6f78454ef31ce04d93fc98d24d84e47a9045c13e0bd73b5e0ba0000aa55 +7ms
  TuyAPI Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('json obj data unvalid')
  TuyAPI     at TuyaDevice.emit (events.js:304:17)
  TuyAPI     at Socket.<anonymous> (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:318:22)
  TuyAPI     at Socket.emit (events.js:315:20)
  TuyAPI     at addChunk (_stream_readable.js:295:12)
  TuyAPI     at readableAddChunk (_stream_readable.js:271:9)
  TuyAPI     at Socket.Readable.push (_stream_readable.js:212:10)
  TuyAPI     at TCP.onStreamRead (internal/stream_base_commons.js:186:23) +4ms
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('json obj data unvalid')
    at TuyaDevice.emit (events.js:304:17)
    at Socket.<anonymous> (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:318:22)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
Emitted 'error' event on TuyaDevice instance at:
    at Socket.<anonymous> (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:334:18)
    at Socket.emit (events.js:315:20)
    [... lines matching original stack trace ...]
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
  code: 'ERR_UNHANDLED_ERROR',
  context: 'json obj data unvalid'
}
DEBUG=* tuya-cli set --ip 192.168.2.Z --id XXXXX --key YYYYY --protocol-version 3.2 --dps 1 --set 1
  TuyAPI IP and ID are already both resolved. +0ms
  TuyAPI Connecting to 192.168.2.Z... +6ms
  TuyAPI Socket connected. +111ms
  TuyAPI GET Payload: +2ms
  TuyAPI {
  TuyAPI   gwId: 'XXXXX',
  TuyAPI   devId: 'XXXXX',
  TuyAPI   t: '1595491352',
  TuyAPI   dps: {},
  TuyAPI   uid: 'XXXXX'
  TuyAPI } +0ms
  TuyAPI SET Payload: +9ms
  TuyAPI {
  TuyAPI   devId: 'XXXXX',
  TuyAPI   gwId: 'XXXXX',
  TuyAPI   uid: '',
  TuyAPI   t: 1595491352,
  TuyAPI   dps: { '1': 1 }
  TuyAPI } +1ms
  TuyAPI Received data: 000055aa000000010000000a0000002c00000001341e53faf713cd68b0675c61c34f2a87a6efc804260729dec5b4d916506bdcf4c31a296e0000aa55 +22ms
  TuyAPI Parsed: +2ms
  TuyAPI {
  TuyAPI   payload: 'parse data error',
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 1
  TuyAPI } +0ms
  TuyAPI Received data: 000055aa00000002000000070000002c00000001341e53faf713cd68b0675c61c34f2a87a6efc804260729dec5b4d916506bdcf42f0215500000aa55 +15ms
  TuyAPI Parsed: +0ms
  TuyAPI {
  TuyAPI   payload: 'parse data error',
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 7,
  TuyAPI   sequenceN: 2
  TuyAPI } +0ms
  TuyAPI Pinging 192.168.2.36 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +35ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms
  TuyAPI Pong from 192.168.2.Z +1ms
  TuyAPI Pinging 192.168.2.Z +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +51ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms
  TuyAPI Pong from 192.168.2.Z +1ms
  TuyAPI Pinging 192.168.2.Z +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +5ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms
  TuyAPI Pong from 192.168.2.Z +1ms
  TuyAPI Pinging 192.168.2.Z +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +97ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms
  TuyAPI Pong from 192.168.2.Z +0ms
  TuyAPI Pinging 192.168.2.Z +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +111ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms
  TuyAPI Pong from 192.168.2.Z +1ms
  TuyAPI Pinging 192.168.2.Z +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +29ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms
  TuyAPI Pong from 192.168.2.Z +0ms
^C

Example Get Command

DEBUG=* tuya-cli get --ip 192.168.2.X --id XXXXX --key YYYYY --protocol-version 3.3 --all
  TuyAPI IP and ID are already both resolved. +0ms
  TuyAPI Connecting to 192.168.2.Z... +6ms
  TuyAPI Socket connected. +72ms
  TuyAPI GET Payload: +1ms
  TuyAPI {
  TuyAPI   gwId: 'XXXXX',
  TuyAPI   devId: 'XXXXX',
  TuyAPI   t: '1595490890',
  TuyAPI   dps: {},
  TuyAPI   uid: 'XXXXX'
  TuyAPI } +0ms
  TuyAPI GET Payload: +12ms
  TuyAPI {
  TuyAPI   gwId: 'XXXXX',
  TuyAPI   devId: 'XXXXX',
  TuyAPI   t: '1595490890',
  TuyAPI   dps: {},
  TuyAPI   uid: 'XXXXX'
  TuyAPI } +0ms
  TuyAPI Received data: 000055aa000000010000000a0000002c000000011fd12f2145a2b4e48d0bc6f78454ef31ce04d93fc98d24d84e47a9045c13e0bd73b5e0ba0000aa55 +6ms
  TuyAPI Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('json obj data unvalid')
  TuyAPI     at TuyaDevice.emit (events.js:304:17)
  TuyAPI     at Socket.<anonymous> (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:318:22)
  TuyAPI     at Socket.emit (events.js:315:20)
  TuyAPI     at addChunk (_stream_readable.js:295:12)
  TuyAPI     at readableAddChunk (_stream_readable.js:271:9)
  TuyAPI     at Socket.Readable.push (_stream_readable.js:212:10)
  TuyAPI     at TCP.onStreamRead (internal/stream_base_commons.js:186:23) +4ms
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('json obj data unvalid')
    at TuyaDevice.emit (events.js:304:17)
    at Socket.<anonymous> (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:318:22)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at Socket.Readable.push (_stream_readable.js:212:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
Emitted 'error' event on TuyaDevice instance at:
    at Socket.<anonymous> (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:334:18)
    at Socket.emit (events.js:315:20)
    [... lines matching original stack trace ...]
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
  code: 'ERR_UNHANDLED_ERROR',
  context: 'json obj data unvalid'
}
@codetheweb
Copy link
Member

Does this happen every single time, or only sometimes?

@t3h-n00b
Copy link
Author

Yep, so far haven’t been successful with these devices (other than to get the ID/Key values)

@codetheweb
Copy link
Member

Did you try omitting the protocol version parameter / setting it to 3.1 (the default)?

Are you able to capture the network traffic between your device and app to see if the packets look similar to what TuyAPI sends?

@t3h-n00b
Copy link
Author

Yep, tried using no protocol version, and then iterating from 3.1-3.3.

I’ll try and capture some traffic over the next couple of days

@t3h-n00b
Copy link
Author

t3h-n00b commented Aug 5, 2020

Alrighty, I've had a look at the wireshark data.

The responses received seem pretty accurate.

TuyAPI seems to be sending a SYN message to Port 6668 on the device, receive an ACK, then send an ACK.

It then seems to send (with protocol set to 3.3):
000055aa000000010000000a000000887dd4c8fc414aaaef33337a15ca02b6162d8854fee5583d05aff271bc5d1871bf0be2d365fe5623eaf7b0f83fcbafb848d5e9cae2a2a1a135c9ea60ff636ce0533d8b92947c046e26c7f63614790fa7a18a9c5920d82d37a9eca0c7a182a74feaab3a98c2cf2c10ac3d72d7021a64cfe630423d71bf69b0007acf53d0d569bf1629afc2fe0000aa55 which looks pretty similar to the data that it is receiving later.

For protocol set to 3.1:
000055aa000000010000000a000000837b2267774964223a2262666266363537373030636634663639376566766c77222c226465764964223a2262666266363537373030636634663639376566766c77222c2274223a2231353936363139393535222c22647073223a7b7d2c22756964223a2262666266363537373030636634663639376566766c77227d1dde88cb0000aa55
Next command it sends is:
000055aa000000040000000900000008387f5d2e0000aa55

Not sure how much help this is...

@codetheweb
Copy link
Member

Those are the packets that TuyAPI sends, correct? Could you also try recording the packets the official app sends to see how similar they are?

@nug321
Copy link

nug321 commented Aug 19, 2020

Hi guys, I got same error with tuya plug socket.
Here is the tcpdump from app.
dump.zip

@codetheweb
Copy link
Member

@nug321 have you retried getting the local key / relinking your device to confirm it's not an issue with that? The key changes every time you relink it / add it to the app.

@nug321
Copy link

nug321 commented Aug 31, 2020

Yep, checked the keys twice.

@codetheweb
Copy link
Member

@nug321 can you post / email me the local key for that dump you posted earlier so I can try to decode it?

@codetheweb
Copy link
Member

@nug321 I emailed back with a possible solution. Feel free to post here with the results.

@chrisca26
Copy link

Any news regards to this I'm having the same error?

@codetheweb
Copy link
Member

@chrisca26 @nug321 hasn't responded to my last email yet.

It looks like their uid parameter may be different then their id/devId parameter. Not sure if that helps, but I can help investigate further if you email me a packet capture (+ device ID and key) of the app controlling your device.

@codetheweb
Copy link
Member

@nug321 thank you for the additional information. I'm not really sure what's going on at this point; but more data would be helpful. @chrisca26 are you able to provide a packet capture?

@chrisca26
Copy link

How would I go about to do a packet capture? Wireshark and filter on the IP?

@codetheweb
Copy link
Member

Yep. 👍

@bb165source
Copy link

I seem to getting an error too. Not sure if the error is related:

` TuyAPI Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('json obj data unvalid')
TuyAPI at TuyaDevice.emit (events.js:303:17)
TuyAPI at Socket. (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:319:22)
TuyAPI at Socket.emit (events.js:314:20)
TuyAPI at addChunk (_stream_readable.js:298:12)
TuyAPI at readableAddChunk (_stream_readable.js:273:9)
TuyAPI at Socket.Readable.push (_stream_readable.js:214:10)
TuyAPI at TCP.onStreamRead (internal/stream_base_commons.js:188:23) +12ms
events.js:291
throw er; // Unhandled 'error' event
^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('json obj data unvalid')
at TuyaDevice.emit (events.js:303:17)
at Socket. (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:319:22)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:298:12)
at readableAddChunk (_stream_readable.js:273:9)
at Socket.Readable.push (_stream_readable.js:214:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
Emitted 'error' event on TuyaDevice instance at:
at Socket. (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:335:18)
at Socket.emit (events.js:314:20)
[... lines matching original stack trace ...]
at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
code: 'ERR_UNHANDLED_ERROR',
context: 'json obj data unvalid'
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants