0.17.21 • Published 1 year ago

@ticos/miniprogram-sdk v0.17.21

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@ticos/miniprogram-sdk

安装

npm i @ticos/miniprogram-sdk

使用方式

// 初始化
import { iotEventType, TicosIotSdk, IDevice } from '@ticos/miniprogram-sdk';

const getToken = async () => {
  //建议通过服务端获取
  const res = await axios.post('https://api.ticos.cn/auth/miniapp/login', {
    code: xxx,  //微信code, 调用微信接口获取
    appId: xxx, //在管理控制台配置小程序接入后获取
    appSecret: xxx //在管理控制台配置小程序接入后获取
  })

  return res.data;
}

const sdk = new TicosIotSdk({
  getToken,
});

sdk.init();

// 获取绑定设备列表
const { deviceList } = await sdk.cloudApi.getDeviceList();

// 绑定设备
await sdk.cloudApi.bindDevice({ productId: 'pro001', deviceId: 'device001' })
// 解绑设备
await ticosSdk.cloudApi.unbindDevice({ productId: 'pro001', deviceId: 'device001' })

// 监听设备, 通过设备ID 和产品ID 监听
sdk.subscribe([{productId: 'pro001', deviceId: 'device001'}, {productId: 'pro001', deviceId: 'device002'}]);
sdk.onMessage(iotEventType.TICOS_IOT_EVENT_PROPERTY, (message) => {
    console.log('*********device property change', message);
  })
sdk.onStatus((message) => {
    console.log('*********device status change ', message);
  })

其他功能或接口使用请参考 https://docs.ticos.cn/
0.17.21

1 year ago

0.17.20

1 year ago

0.17.14

1 year ago

0.17.16

1 year ago

0.17.15

1 year ago

0.17.18

1 year ago

0.17.17

1 year ago

0.17.19

1 year ago

0.17.2

1 year ago

0.17.3

1 year ago

0.17.4

1 year ago

0.17.5

1 year ago

0.17.6

1 year ago

0.17.7

1 year ago

0.17.8

1 year ago

0.17.9

1 year ago

0.16.0

1 year ago

0.17.1

1 year ago

0.17.10

1 year ago

0.17.12

1 year ago

0.17.11

1 year ago

0.17.13

1 year ago

0.15.0

1 year ago

0.14.0

1 year ago

0.13.0

1 year ago

0.12.0

1 year ago

0.11.6

1 year ago

0.11.5

1 year ago

0.11.3

1 year ago

0.11.2

1 year ago

0.11.0

1 year ago

0.10.0

1 year ago

0.9.0

1 year ago

0.8.0

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.2

1 year ago

0.3.0

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago