qcloud-iotexplorer-h5-panel-sdk
腾讯连连小程序自定义H5面板SDK开发文档
开始使用
npm i qcloud-iotexplorer-h5-panel-sdk
引入sdk
import sdk from 'qcloud-iotexplorer-h5-panel-sdk';
// or
const sdk = require('qcloud-iotexplorer-h5-panel-sdk');
API
sdk.controlDeviceData: (data) => Promise
控制设备属性,如:
sdk.controlDeviceData({
power_switch: 1
});
sdk.describeDeviceDataHistory
查询设备历史数据,具体用法参见: AppGetDeviceDataHistory 接口文档
sdk.getUserInfo
拉取用户信息,调用后会更新到 sdk.userInfo 中,具体用法参考 AppGetUser 接口文档
sdk.getProductInfo
拉取设备所属产品信息,调用后会更新 sdk.productInfo 和 sdk.dataTemplate,具体用法参考 AppGetProducts 接口文档
sdk.getDeviceData
拉取设备最新的属性,调用后会更新 sdk.deviceData,具体用法参考 AppGetDeviceData 接口文档
sdk.getDeviceStatus
拉取设备当前在线状态,调用后会更新 sdk.deviceStatus,具体用法参考 AppGetDeviceStatuses 接口文档
sdk.goDeviceDetailPage
跳转到腾讯连连通用的产品详情页(小程序页面)
sdk.onWsClose: (callback) => void;
- callback: ({ code, reason }) => void;
当 websocket close 事件触发后执行回调
sdk.onWsError: (callback) => void;
- callback: (error) => void;
当 websocket 触发 error 事件后触发回调
sdk.onWsControl: (callback) => void;
- callback: ({ deviceId, deviceData }) => void;
当 websocket 收到 control
指令后触发
sdk.onWsReport: (callback) => void;
- callback: ({ deviceId, deviceData }) => void;
当 websocket 收到 report
指令后触发
sdk.onWsStatusChange: (callback) => void;
- callback: ({ deviceId, deviceStatus }) => void;
当 websocket 收到设备状态改变推送后触发回调
sdk.requestTokenApi: (action, data, options) => Promise
sdk.share: ({ title, imgUrl }) => Promise
- title: string 分享的标题
- imgUrl?: string 分享图片的地址,默认会取当前页面截图
设置当前页面的分享内容,通过 wx.miniProgram.postMessage 向小程序推送分享信息,具体参考 小程序页面分享文档
sdk.navBack: () => Promise
调用 wx.miniprogram.navigateBack 返回上一级页面
sdk.appDevSdk
应用开发 SDK 实例,H5面板sdk底层依赖 应用开发小程序端SDK,更多调用能力请参考应用开发SDK文档
sdk.wx
微信 JS-SDK 实例,具体用法参考官方文档,使用前必须保证已经调用 sdk.wxSdkReady 方法
sdk.wxSdkReady: () => Promise
确保微信 jssdk 已注册完成,完成后会触发 resolve,该方法多次调用,若成功会返回缓存的 Promise 对象,如:
sdk.wxSdkReady().then(() => wx.miniprogram.navigateBack());
属性
sdk.deviceId: string
设备id,由 {productId}/{deviceName}
组成
sdk.productId: string
产品id
sdk.deviceName: string
设备名称
sdk.deviceInfo
设备信息,如:
{
AliasName: "设备别名",
CreateTime: 1583739344,
DeviceId: "{productId}/{deviceName}",
DeviceName: "{deviceName}",
DeviceType: 0,
FamilyId: "家庭ID",
IconUrl: "设备ICON",
ProductId: "{productId}",
RoomId: "房间id",
UpdateTime: 1583739344,
UserID: "用户Id"
}
sdk.dataTemplate
设备所在产品的物模型,如:
{
"version": "1.0",
"profile": {
"ProductId": "xxxx",
"CategoryId": "1"
},
"properties": [
{
"id": "int",
"name": "int",
"desc": "",
"mode": "rw",
"define": {
"type": "int",
"min": "0",
"max": "100",
"start": "0",
"step": "1",
"unit": ""
},
"required": false
},
{
"id": "float",
"name": "float",
"desc": "",
"mode": "rw",
"define": {
"type": "float",
"min": "0",
"max": "100",
"start": "0",
"step": "1",
"unit": ""
},
"required": false
},
{
"id": "bool",
"name": "bool",
"desc": "",
"mode": "rw",
"define": {
"type": "bool",
"mapping": {
"0": "关",
"1": "开"
}
},
"required": false
},
{
"id": "enum",
"name": "enum",
"desc": "",
"mode": "rw",
"define": {
"type": "enum",
"mapping": {
"1": "1",
"2": "2",
"3": "3",
"4": "4",
"5": "5"
}
},
"required": false
}
],
"events": [],
"actions": []
}
sdk.deviceStatus: number
设备在线状态,在线: 1,非在线: 0
sdk.deviceDisplayName: string
设备展示名称,会依次取:AliasName > productInfo.name > deviceName
来展示
sdk.isShareDevice: boolean
是否是分享设备
sdk.familyId: string
设备所在家庭id,如果是分享设备则无此值
sdk.roomId: string;
设备所在房间id,如果是分享设备则无此值
sdk.familyInfo
设备所在家庭详情,如果是分享设备则无此值
sdk.isFamilyOwner: boolean
用户是否是当前家庭的管理员
sdk.userInfo
用户信息,如:
{
Avatar: "头像url",
CountryCode: "国家代码",
Email: "email",
NickName: "昵称",
PhoneNumber: "电话号码",
UserID: "用户id"
}