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

Setup using CLI-Wizard is throwing an error #48

Closed
kirkbrownOK opened this issue Aug 10, 2018 · 22 comments
Closed

Setup using CLI-Wizard is throwing an error #48

kirkbrownOK opened this issue Aug 10, 2018 · 22 comments
Labels

Comments

@kirkbrownOK
Copy link

This work is most impressive. Unfortunately for me I'm having an issue with the SETUP process. I got my API Key and Secret from tuya. Then I attempted the CLI WIZARD steps provided. My wifi password is a 10 digit string and as a result, I believe it is failing a password validity check. This is the error message I get.

[21:51:50] openhabian@openHABianPi:/etc/openhab2/scripts$ tuya-cli link-wizard
? Make the indicator light on your device flash.
For most devices, this means holding down the main button.
Press return when it's blinking. Yes
? What's your WiFi called? skittles
? What's the password for your WiFi? [hidden]
? How many devices do you want to link? 1
? Do you want to save devices that are successfully linked? Yes
✖ Device(s) failed to be registered!
Error: Invalid WiFi password
at TuyaLink.registerSmartLink (/usr/lib/node_modules/@tuyapi/cli/node_modules/@tuyapi/link/lib/link.js:64:11)
at TuyaLinkWizard.linkDevice (/usr/lib/node_modules/@tuyapi/cli/node_modules/@tuyapi/link/index.js:93:23)
at
at process._tickCallback (internal/process/next_tick.js:188:7)

@codetheweb
Copy link
Owner

codetheweb commented Aug 10, 2018 via email

@codetheweb
Copy link
Owner

@kirkbrownOK should be working now. Update the CLI tool with npm i @tuyapi/cli@1.0.1 -g and please try again.

@codetheweb
Copy link
Owner

As there hasn't been any activity in the last 18 days on this, I'm closing it. Feel free to re-open it @kirkbrownOK if you're still having problems.

@RR2301
Copy link

RR2301 commented Oct 24, 2018

Hi
I have been struggling for while to control my tuya smart plug though njstuya api file.. I have followed the exact steps mentioned in git hub repository.

Appreciate your help in resolving the below issue.

$sudo node njstuya -ip 192.168.XX.XX -id adkepsh9u7acdv98h -key w4duxc9vkrsajt9gy7 OFF

/etc/openhab2/scripts/node_modules/node-forge/lib/aes.js:203
var len = tmp.length();
^

TypeError: tmp.length is not a function
at forge.aes.Algorithm.initialize (/etc/openhab2/scripts/node_modules/node-forge/lib/aes.js:203:19)
at new forge.cipher.BlockCipher (/etc/openhab2/scripts/node_modules/node-forge/lib/cipher.js:118:18)
at Object.forge.cipher.createCipher (/etc/openhab2/scripts/node_modules/node-forge/lib/cipher.js:42:10)
at new TuyaCipher (/etc/openhab2/scripts/node_modules/tuyapi/lib/cipher.js:13:30)
at new TuyaDevice (/etc/openhab2/scripts/node_modules/tuyapi/index.js:43:24)
at Object. (/etc/openhab2/scripts/njsTuya/scripts/njstuya.js:26:12)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)

Also wanted to let you know that when I am trying to connect to the device through link wizard, it is throwing an error.

$sudo tuya-cli link-wizard

Make the indicator light on your device flash.
For most devices, this means holding down the main button.
Press return when it's blinking. Yes
? What's your WiFi called? IOT
? What's the password for your WiFi? [hidden]
? How many devices do you want to link? 1
? Do you want to save devices that are successfully linked? Yes
� Device(s) failed to be registered!

Device(s) failed to be registered!
{ code: 'SING_VALIDATE_FALED_4',
message: 'Parameter or Data Error' }

@codetheweb
Copy link
Owner

@RR2301:

Two things:

  1. That appears to be the wrong format for the ID parameter, it should look more like this: 07200178dc4f223f4800 (20 characters long, vs. your ID which is 17 characters long).
  2. If you simply want to toggle a device with a single property over the command line, I'd suggest using @tuyapi/cli instead as njstuya doesn't appear to be maintained. You can install the official CLI package like this: npm i @tuyapi/cli -g and use it like this: tuya-cli set --id [your-id] --key w4duxc9vkrsajt9gy7 --set false.

@RR2301
Copy link

RR2301 commented Oct 25, 2018

@codetheweb
Thanks for your quick reply.
In spite of using the correct ID format and CLI package @tuyapi/cli I am getting the below error.
pi@raspberrypi:/etc/openhab2/scripts $ tuya-cli set --id 0120057360019492b55d --key w4duxc9v3vkrsajt8gy7 --set false
/usr/local/lib/node_modules/@tuyapi/cli/node_modules/node-forge/lib/aes.js:203
var len = tmp.length();
^

TypeError: tmp.length is not a function
at forge.aes.Algorithm.initialize (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/node-forge/lib/aes.js:203:19)
at new forge.cipher.BlockCipher (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/node-forge/lib/cipher.js:118:18)
at Object.forge.cipher.createCipher (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/node-forge/lib/cipher.js:42:10)
at new TuyaCipher (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/lib/cipher.js:13:30)
at new TuyaDevice (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:43:24)
at parseConfig (/usr/local/lib/node_modules/@tuyapi/cli/lib/control.js:24:10)
at Object.set (/usr/local/lib/node_modules/@tuyapi/cli/lib/control.js:50:15)
at Command.program.command.description.option.option.option.option.option.action.options (/usr/local/lib/node_modules/@tuyapi/cli/cli.js:59:11)
at Command.listener (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/commander/index.js:315:8)
at Command.emit (events.js:182:13)

Note : I retrieve the ID of a smart plug from tuya app installed in my phone. Is there any other way to fetch the ID. I tried tuya-cli link-wizard but it did not work.

@codetheweb
Copy link
Owner

@RR2301 that looks like the right ID but still the wrong format for the key. Try following this guide to get the ID and key.

@RR2301
Copy link

RR2301 commented Oct 25, 2018 via email

@codetheweb
Copy link
Owner

There's no other way to acquire the IDs and keys other than (a) performing a MITM attack on your phone (what tuya-cli list app and the Android method do) or (b) generating an official linking token using Tuya's API and transmitting it to the device. The first method is relatively easy, the second is not and now costs money after Tuya has updated their API.

All that to say that you have to follow the guide to get the parameters. What's not working with list-app? Do you have an iPhone? Did you trust the certificate (different than installing the certificate)?

@RR2301
Copy link

RR2301 commented Oct 26, 2018 via email

@codetheweb
Copy link
Owner

People have been having issues with link-wizard. If the list-app command is working, you should be able to get your parameters from that. If not, you said you can see traffic in Charles so I'd advise looking through those requests to get the ID and key.

@RR2301
Copy link

RR2301 commented Oct 27, 2018 via email

@codetheweb
Copy link
Owner

Does the tuya-cli set work? You can do --set false and --set true to respectively turn your device off and on.

The other option would be to write your own script file in NodeJS using TuyAPI.

@RR2301
Copy link

RR2301 commented Oct 29, 2018 via email

@codetheweb
Copy link
Owner

Hmm, your ID looks good but the key still looks too long (should be 16 characters). Could you post a link to the device that you bought? And how did you get those parameters?

Also, please make sure that your Node version is >=6.0.0. You can check with node -v.

@RR2301
Copy link

RR2301 commented Oct 30, 2018 via email

@codetheweb
Copy link
Owner

Your device looks fine, I have a very similar one. Can you please check your Node version? Did you get the above parameters with tuya-cli list-app?

@RR2301
Copy link

RR2301 commented Oct 31, 2018 via email

@codetheweb
Copy link
Owner

The list command just outputs saved API keys and device parameters.

Do you have an iOS or Android smartphone?

@RR2301
Copy link

RR2301 commented Nov 1, 2018 via email

@RR2301
Copy link

RR2301 commented Nov 1, 2018 via email

@codetheweb
Copy link
Owner

It looks like it's only capturing the CONNECT requests for some reason, not actual traffic. Did you trust the certificate?

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

No branches or pull requests

3 participants