Giter VIP home page Giter VIP logo

Comments (22)

codetheweb avatar codetheweb commented on May 23, 2024

from tuyapi.

codetheweb avatar codetheweb commented on May 23, 2024

@kirkbrownOK should be working now. Update the CLI tool with npm i @tuyapi/[email protected] -g and please try again.

from tuyapi.

codetheweb avatar codetheweb commented on May 23, 2024

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.

from tuyapi.

RR2301 avatar RR2301 commented on May 23, 2024

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' }

from tuyapi.

codetheweb avatar codetheweb commented on May 23, 2024

@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.

from tuyapi.

RR2301 avatar RR2301 commented on May 23, 2024

@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.

from tuyapi.

codetheweb avatar codetheweb commented on May 23, 2024

@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.

from tuyapi.

RR2301 avatar RR2301 commented on May 23, 2024

from tuyapi.

codetheweb avatar codetheweb commented on May 23, 2024

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)?

from tuyapi.

RR2301 avatar RR2301 commented on May 23, 2024

from tuyapi.

codetheweb avatar codetheweb commented on May 23, 2024

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.

from tuyapi.

RR2301 avatar RR2301 commented on May 23, 2024

from tuyapi.

codetheweb avatar codetheweb commented on May 23, 2024

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.

from tuyapi.

RR2301 avatar RR2301 commented on May 23, 2024

from tuyapi.

codetheweb avatar codetheweb commented on May 23, 2024

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.

from tuyapi.

RR2301 avatar RR2301 commented on May 23, 2024

from tuyapi.

codetheweb avatar codetheweb commented on May 23, 2024

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?

from tuyapi.

RR2301 avatar RR2301 commented on May 23, 2024

from tuyapi.

codetheweb avatar codetheweb commented on May 23, 2024

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

Do you have an iOS or Android smartphone?

from tuyapi.

RR2301 avatar RR2301 commented on May 23, 2024

from tuyapi.

RR2301 avatar RR2301 commented on May 23, 2024

from tuyapi.

codetheweb avatar codetheweb commented on May 23, 2024

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

from tuyapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.