TuyaAPI / cli

🔧 A CLI for Tuya devices
MIT License
261 stars 44 forks source link

Some errors are happening #134

Closed leoheck closed 2 years ago

leoheck commented 2 years ago

Reporting issues I am seeing.

GET

➜ DEBUG=* tuya-cli get --id ID_HERE --key KEY_HERE --full
Error: find() timed out. Is the device powered on and the ID or IP correct?
    at /usr/local/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:824:13
    at Timeout._onTimeout (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/p-timeout/index.js:25:13)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)

SET

➜ DEBUG=* tuya-cli set --id ID_HERE --key KEY_HERE --dps 1 --set false       
Error: find() timed out. Is the device powered on and the ID or IP correct?
    at /usr/local/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:824:13
    at Timeout._onTimeout (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/p-timeout/index.js:25:13)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)

[SOLVED] the commands need the ip, it is not optional. And it has to be the local IP, not the one found on Tuya's APP. Sometime the device has the macaddress listed on Tuya's App what makes the disover of the IP easy. Sometimes it does not have what was on my case.

codetheweb commented 2 years ago

Try passing in the IP of your device as an argument as well and see if that fixes it.

leoheck commented 2 years ago

Hi @codetheweb I was trying that, and it was not working too. Let me check again what was the issue I was having with the ip. Ah, by tha way I was using the ip gotten from inside the Tuya's app. It was not a local ip.

leoheck commented 2 years ago

This is what happens when I use the public ip.

➜ DEBUG=* tuya-cli get --ip [IP_HERE] --id [ID_HERE] --key [KEY_HERE] --full
  TuyAPI IP and ID are already both resolved. +0ms
  TuyAPI Connecting to [IP_HERE]... +6ms
  TuyAPI Error event from socket. [IP_HERE] Error: connect ECONNREFUSED [IP_HERE]:6668
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1138:16) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '[IP_HERE]',
  port: 6668
} +13ms
events.js:291
      throw er; // Unhandled 'error' event
      ^

Error: Error from socket: connect ECONNREFUSED [IP_HERE]:6668
    at Socket.<anonymous> (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:515:30)
    at Socket.emit (events.js:314:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on TuyaDevice instance at:
    at Socket.<anonymous> (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:515:16)
    at Socket.emit (events.js:314:20)
    [... lines matching original stack trace ...]
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
leoheck commented 2 years ago

Ah, using local ip i am seeing this

➜ DEBUG=* tuya-cli get --ip [LOCAL_IP_HERE] --id [ID_HERE] --key [KEY_HERE] --full
  TuyAPI IP and ID are already both resolved. +0ms
  TuyAPI Connecting to [LOCAL_IP_HERE]... +2ms
  TuyAPI Socket connected. +851ms
  TuyAPI GET Payload: +3ms
  TuyAPI {
  TuyAPI   gwId: '[ID_HERE]',
  TuyAPI   devId: '[ID_HERE]',
  TuyAPI   t: '[T_HERE]',
  TuyAPI   dps: {},
  TuyAPI   uid: '[ID_HERE]'
  TuyAPI } +0ms
  TuyAPI Received data: [RECEIVED_DATA] +102ms
  TuyAPI Parsed: +5ms
  TuyAPI {
  TuyAPI   payload: '7�q6��\u0002�^f$�R\u0013\u1011D\u001cFw�a�RF{?�\u0006����',
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 1
  TuyAPI } +1ms
  TuyAPI Received DATA packet +1ms
  TuyAPI Disconnect +1ms
7�q6���^f$�RDFw�a�RF{?�����
  TuyAPI Socket closed: [LOCAL_IP_HERE] +4ms

The issue now with this is that I have 3 tuya devices on my network. But I have no ideia how do I identify each IP. The app does not show the Macaddress for this bulb. Do you know any way to identify the local ip of each device?

leoheck commented 2 years ago

For the set operation I am seeing this:

➜ DEBUG=* tuya-cli set --ip [LOCAL_IP_HERE] --id [ID_HERE] --key [KEY_HERE] --dps 1 --set "true"
  TuyAPI IP and ID are already both resolved. +0ms
  TuyAPI Connecting to [LOCAL_IP_HERE]... +3ms
  TuyAPI Socket connected. +307ms
  TuyAPI SET Payload: +3ms
  TuyAPI {
  TuyAPI   devId: '[ID_HERE]',
  TuyAPI   gwId: '[ID_HERE]',
  TuyAPI   uid: '',
  TuyAPI   t: 1633458303,
  TuyAPI   dps: { '1': true }
  TuyAPI } +0ms
  TuyAPI Received data: [RECEIVED_DATA] +100ms
  TuyAPI Parsed: +3ms
  TuyAPI {
  TuyAPI   payload: '7�q6��\u0002�^f$�R\u0013\u1011D\u001cFw�a�RF{?�\u0006����',
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 7,
  TuyAPI   sequenceN: 1
  TuyAPI } +1ms
  TuyAPI Received DATA packet +1ms
Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('Timeout waiting for status response from device id: [ID_HERE]')
    at TuyaDevice.emit (events.js:303:17)
    at /usr/local/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:369:12
    at Timeout._onTimeout (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/p-timeout/index.js:25:13)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7) {
  code: 'ERR_UNHANDLED_ERROR',
leoheck commented 2 years ago

I had to find the right IP. And some devices were missing. Specially the one I wanted to control. Then I installed tinytuya, and with this scan python3 -m tinytuya scan I was able to identify my specific bulb. Because it was the only one that had the information displayed.

So, I managed to make it work. Now, it could have a way to identify the ip of the bulb with the list command if possible.

codetheweb commented 2 years ago

I don't think Tuya provides the local IP of devices for that API call.

leoheck commented 2 years ago

I don't think Tuya provides the local IP of devices for that API call.

Yeah, but how do you get it for your devices? Any idea?

codetheweb commented 2 years ago

As stated in the TuyAPI readme, I'm not currently using any of this on a day-to-day basis. Having said that, some form of IP scanning with nmap or the like usually works pretty well.

TuyAPI should be able to automatically find your devices assuming they're not on different subnets and nothing weird is going on with your network.

leoheck commented 2 years ago

Cool. Thanks, codetheweb.