
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
qcloud-iotexplorer-h5-panel-sdk
Advanced tools
腾讯连连小程序自定义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');
控制设备属性,如:
sdk.controlDeviceData({
power_switch: 1
});
查询设备历史数据,具体用法参见: AppGetDeviceDataHistory 接口文档
拉取用户信息,具体用法参考 AppGetUser 接口文档
拉取设备所属产品信息,具体用法参考 AppGetProducts 接口文档
拉取设备信息
拉取设备最新的属性,具体用法参考 AppGetDeviceData 接口文档
拉取设备当前在线状态,0 - 离线,1 - 在线
删除设备,deviceId可选,不传则使用当前设备deviceId
若该设备是分享设备,且分享方设置了自定义分享参数,则被分享人在接受分享后可通过调用该接口获取自定义分享参数
在当前 H5 展示一个铺满全屏的设备详情视图,支持自定义拓展菜单项及按钮。
关闭设备详情视图
AppGetUser
跳转到腾讯连连通用的产品详情页(小程序页面)
前往连连小程序反馈页面
前往设备信息页
前往修改设备名称页
前往房间设置页
前往设备分享页
退出当前h5页面返回连连小程序后,让小程序主动刷新一次当前数据。
设置当前页面的分享内容,通过 wx.miniProgram.postMessage 向小程序推送分享信息,具体参考 小程序页面分享文档
调用 wx.miniProgram.navigateBack 返回上一级页面
应用开发 SDK 实例,H5面板sdk底层依赖 应用开发小程序端SDK,更多调用能力请参考应用开发SDK文档
微信 JS-SDK 实例,具体用法参考官方文档,使用前必须保证已经调用 sdk.wxSdkReady 方法
确保微信 jssdk 已注册完成,完成后会触发 resolve,该方法多次调用,若成功会返回缓存的 Promise 对象,如:
sdk.wxSdkReady().then(() => wx.miniProgram.navigateBack());
监听/解绑事件
websocket 的 close 事件
websocket 的 error 事件
当 websocket 收到 control
指令后触发
当 websocket 收到 report
指令后触发
当 websocket 收到 wsStatusChange
后触发
当 App.onShow 执行后触发
当 App.onHide 执行后触发
当 Page.onShow 执行后触发
当 Page.onHide 执行后触发
已废弃,请用 sdk.on('wsClose', callback) 代替
当 websocket close 事件触发后执行回调
已废弃,请用 sdk.on('wsError', callback) 代替
当 websocket 触发 error 事件后触发回调
已废弃,请用 sdk.on('wsControl', callback) 代替
当 websocket 收到 control
指令后触发
已废弃,请用 sdk.on('wsReport', callback) 代替
当 websocket 收到 report
指令后触发
已废弃,请用 sdk.on('wsStatusChange', callback) 代替
当 websocket 收到设备状态改变推送后触发回调
tips模块,样式和风格与连连小程序一致
展示tips
关闭tips
封装后的 tips.show 方法,等价于:
this.show(message, {
type: 'loading',
canBeReplace: true,
duration: 0,
delayDuration: 200,
canClickClose: false,
...options,
})
关闭loading tips
注意,showLoading后必须主动调用hideLoading,否则tips永远不会消失
封装后的 tips.show 方法,等价于:
this.show(message, { type: 'success', ...opts });
封装后的 tips.show 方法,等价于:
this.show(message, { type: 'info', ...options });
会先标准化处理错误展示信息后展示tips,等价于:
展示一个弹窗,参数、功能、样式同小程序原生 showModal 基本一致,返回一个 Promise,为 true 代表用户点击确认,返回 false 表示用户点击取消。
基于 showModal 封装,用于向用户进行二次确认操作时使用,用法:
const isConfirm = await sdk.tips.confirm('确认删除该设备吗?')
if (isConfirm) {
// do something
}
基于 showModal 封装,用于向用户进行消息提示操作时使用,用法:
await sdk.tips.alert('该功能暂时无法使用,请稍后再试');
// do something else
设备离线提示组件,样式和风格与连连小程序一致
展示离线提示
用法同 sdk.offlineTip.show()
关闭离线提示
用法同 sdk.offlineTip.hide()
设备id,由 {productId}/{deviceName}
组成
产品id
设备名称
设备信息,如:
{
AliasName: "设备别名",
CreateTime: 1583739344,
DeviceId: "{productId}/{deviceName}",
DeviceName: "{deviceName}",
DeviceType: 0,
FamilyId: "家庭ID",
IconUrl: "设备ICON",
ProductId: "{productId}",
RoomId: "房间id",
UpdateTime: 1583739344,
UserID: "用户Id"
}
当前家庭的房间列表
当前设备的房间名称
设备所在产品的物模型,如:
{
"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
},
],
"events": [],
"actions": []
}
设备在线状态,在线: 1,非在线: 0
设备展示名称,会依次取:AliasName > productInfo.name > deviceName
来展示
是否是分享设备
设备所在家庭id,如果是分享设备则无此值
设备所在房间id,如果是分享设备则无此值
设备所在家庭详情,如果是分享设备则无此值
用户是否是当前家庭的管理员
用户信息,如:
{
Avatar: "头像url",
CountryCode: "国家代码",
Email: "email",
NickName: "昵称",
PhoneNumber: "电话号码",
UserID: "用户id"
}
由于h5中无法直接调用小程序蓝牙相关接口,sdk封装了特殊的蓝牙模块,通过一个单独的websocket通道打通了h5到小程序直接的蓝牙通信
介绍蓝牙模块中使用到的一些名词
服务id,蓝牙服务的uuid,搜索设备时主要通过 serviceId 来过滤我们需要的设备。
小程序api搜索出来的设备的标识,连接设备时主要通过 deviceId 来标识需要连接的设备
物联网开发平台侧定义的设备ID,查询设备数据和上报设备数据时以该 id 作为设备标识。
全局单例,实例上声明了蓝牙搜索、连接等方法
真正用来连接设备以及跟设备进行通信的模块,每一个设备连接对应一个设备适配器实例,设备适配器会在连接设备后实例化,并在设备断开连接后销毁。
根据不同的 serviceId 来区别不同类型设备的适配器构造函数。
添加一个设备适配器,默认无任何设备适配器,使用时需要根据具体设备情况创建一个设备适配器,并将其构造函数添加到蓝牙适配器中。
如:
class DemoDeviceAdapter extends DeviceAdapter {
static serviceId = '0000FFF0-0000-1000-8000-00805F9B34CC';
static deviceFilter(deviceInfo) {
if (deviceInfo.advertisServiceUUIDs) {
const matchedServiceId = deviceInfo.advertisServiceUUIDs.find(id => id === DemoDeviceAdapter.serviceId);
if (matchedServiceId && deviceInfo.advertisData) {
try {
const macArr = deviceInfo.advertisData.slice(2);
const mac = macArr.join(':');
return {
...deviceInfo,
deviceName: mac,
serviceId: matchedServiceId,
}
} catch (err) {
console.error('parse mac error', err);
}
}
}
}
handleBLEMessage(hex) {
return {
type: 'unknown',
data: hex,
};
}
}
sdk.bluetoothAdapter.addAdapter(DemoDeviceAdapter);
初始化蓝牙模块,包括初始化蓝牙模块,打通小程序间蓝牙通信,注册全局回调等。返回一个带缓存的Promise,可重复调用,可在每次使用前调用
开始搜索蓝牙设备(将会调用 wx.startBluetoothDevicesDiscovery,比较耗费系统资源,务必在不需要搜索后调用 blueToothAdapter.stopSearch,如离开页面后)
该方法返回一个 Promise,注意务必要等待 Promise 响应 resolve 才代表操作指行成功。
指定需要搜索的serviceId,不传的话会使用当前支持的所有 DeviceAdapter 的 serviceId 来匹配。
可选,需要过滤掉的 deviceId 列表(比如刚添加完的设备),搜索结果中将不会出现这些设备
当搜索结果更新后调用,返回搜索到的设备列表
当搜索过程中发生错误后调用,触发后设备搜索将会中止
可选,默认 20000,单位毫秒,超过多久没搜索到设备后将会触发超时错误
停止搜索设备
搜索蓝牙设备,并将在找到第一个满足条件的设备后 resolve,与 startSearch 的区别在于 searchDevice 在搜到第一个匹配设备后即会中止搜索。 该方法常用于已经绑定过设备后,在连接设备时来定向搜索该设备。
指定需要搜索的serviceId,不传的话会使用当前支持的所有 DeviceAdapter 的 serviceId 来匹配。
指定需要搜索的设备 deviceName
同 startSearchParams.ignoreDeviceIds
连接指定设备,传入 searchDevice 或 startSearch 接口搜索出来的 DeviceInfo,连接成功后返回设备适配器
根据 deviceId 查询对应的设备适配器实例,如果设备未连接或已断开,则返回空
当适配器状态变化时触发。
设备适配器构造函数
子类在继承基类后需要设置该属性,代表该设备的主服务ID
子类在继承基类后需要实现该静态方法,在搜索蓝牙设备时会将每个搜出的设备信息传入该方法,如果判断是本产品的设备,则需在除入参deviceInfo之外返回设备唯一标识 deviceName 及 serviceId,否则返回空;
设备适配器
getter,设备的 explorerDeviceId
getter,设备当前是否连接状态
getter,设备的 deviceId
getter,设备的主服务ID,实际上既是挂在构造函数上的静态属性 DeviceAdapter.serviceId
getter,设备的原始名称,即小程序接口搜索出来时的 name 字段
getter,设备的 explorerDeviceId
主动断开设备连接
往蓝牙设备写数据。
子类继承基类后需要实现该方法,用于处理收到 onBLECharacteristicValueChange 回调后的协议解析。
返回值中如果返回 reportData,则会将该部分数据上报到云端(注意需与产品定义物模型匹配),其他字段则会透传到 message
事件的 payload 中。
设备连接后触发
设备断开后触发
当收到 onBLECharacteristicValueChange 回调,并经过 handleBLEMessage 处理后触发
当 onBleConnectionStateChange 触发时触发,若 connected 为 true,则接下来会触发事件 'connect',否则会触发事件 'disconnect'
FAQs
腾讯连连小程序自定义H5面板SDK开发文档
We found that qcloud-iotexplorer-h5-panel-sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.