• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

TuyaAPI/cloud:

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

TuyaAPI/cloud

开源软件地址:

https://github.com/TuyaAPI/cloud

开源编程语言:

JavaScript 100.0%

开源软件介绍:

tuyapi/cloud Build Status Coverage Status XO code style

A NodeJS wrapper for Tuya's API.

At the moment, only the mobile/app API (as captured by web.archive.org) is supported as it covers the vast majority of use cases.

There are two modes of operation:

  • the 'old' API - described in the docs, using MD5 as a sign mechanism
  • the 'new' API - reverse-engineered from the TuyaSmart Android app, using HMAC-SHA256 as a sign mechanism

If you can, use the old API. Unfortunately, for some clientId/key's you must use the new API (eg. clientId used by TuyaSmart app). To use the the new API, specify apiEtVersion as an option in constructor (currently '0.0.1').

Step-by-step instructions for acquiring keys to use with the old API can be found here.

Obtaining keys for new API (additional parameters secret2 and certSign are required) involves disassembling obtained an APK file (either official app or generated "demo" app from iot.tuya.com). For details see tuya-sign-hacking repo.

Installation

npm i @tuyapi/cloud

Usage

old API (register/login and create token):

const Cloud = require('@tuyapi/cloud');

let api = new Cloud({key: 'your-api-app-key', secret: 'your-api-app-secret'});

api.register({email: '[email protected]', password: 'example-password'}).then(async sid => {
  let token = await api.request({action: 'tuya.m.device.token.create', data: {'timeZone': '-05:00'}});

  console.log(token) // => { secret: '0000', token: '01010101' }
});

new API (listing all devices in all groups):

const Cloud = require('@tuyapi/cloud');

let api = new Cloud({key: apiKeys.key,
                     secret: apiKeys.secret,
                     secret2: apiKeys.secret2,
                     certSign: apiKeys.certSign,
                     apiEtVersion: '0.0.1',
                     region: 'EU'});

api.loginEx({email: myEmail, password: myPassword}).then(async sid => {
  console.log(sid);

  api.request({action: 'tuya.m.location.list'}).then(async groups => {
    for (const group of groups) {
      api.request({action: 'tuya.m.my.group.device.list', gid: group.groupId}).then(async devicesArr => {
        for (const device of devicesArr) {
           console.log('group: "%s"\tdevice: "%s"\tdevId: "%s"', group.name, device.name, device.devId);
        }
      });
    }
  });
});

Documentation

Development

  1. After cloning, run npm i.
  2. Add a file called keys.json with the contents
{
  "key": "your-api-key",
  "secret": "your-api-secret"
  // for new API: add also secret2 and certSign
}
  1. Create a file called dev.js as a playground. Since dev.js is in .gitignore, it won't be committed.
  2. To run tests, run npm test.
  3. To output coverage, run npm run cover (it will exit with an error).
  4. To build documentation, run npm run document.

forthebadge




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap