小程序开发——获取设备信息 API(四)

ty.device.addDeviceToDesk

添加设备到桌面

需引入DeviceKit,且在>=2.2.0版本才可使用

请求参数

Object object

属性 类型 默认值 必填 说明
deviceId string deviceId 设备 id
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

返回结果

  • success

  • fail
属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {errorMsg: string, errorCode: string }

请求示例

ty.device.addDeviceToDesk({
  deviceId: '64710761ecfabcaaf553',
})
  .then((res) => {
    console.log(res);
  })
  .catch((error) => {
    console.log(error);
  });

👉 立即开发

ty.device.getEncryptLocalKeyWithData

获取加密过的设备 localKey

BLE(thing)蓝牙大数据通道传输过程中需要用到的特殊加密操作

需引入DeviceKit,且在>=1.2.6版本才可使用

请求参数

Object object

属性 类型 默认值 必填 说明
deviceId string 大数据通道加密计算结构 deviceId 设备 id
keyDeviceId string keyDeviceId 需要传输加密密钥的设备 Id
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

返回结果

  • success

String string

  • fail
属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {errorMsg: string, errorCode: string }

请求示例

ty.device.getEncryptLocalKeyWithData({
  deviceId: '64710761ecfabcaaf553',
  keyDeviceId: '64710761ecfabcaaf553',
})
  .then((res) => {
    console.log(res);
  })
  .catch((error) => {
    console.log(error);
  });

返回示例

42954ff1dcc15a996b7f270f4767f594

ty.device.registerDeviceListListener

注册需要监听的设备列表的监听器

需引入DeviceKit,且在>=2.3.1版本才可使用

请求参数

Object object

属性 类型 默认值 必填 说明
deviceIdList Array<String> 需注册的设备 id 列表
complete function 接口调用完成的回调函数(成功或失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

返回结果

  • success

  • fail
属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {errorMsg: string, errorCode: string }

请求示例

ty.device.registerDeviceListListener({
  deviceIdList: [ '64710761ecfabcaaf553' ]
});

ty.device.unregisterDeviceListListener

注销需要监听的设备列表的监听器

需引入DeviceKit,且在>=2.3.1版本才可使用

请求参数

Object object

属性 类型 默认值 必填 说明
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

返回结果

  • success

  • fail
属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {errorMsg: string, errorCode: string }

请求示例

ty.device.unregisterDeviceListListener();

👉 立即开发

ty.device.onDeviceInfoUpdated

设备 dp 名字和设备名字更新时触发

需引入DeviceKit,且在>=1.2.6版本才可使用

请求参数

Function Callback

设备 dp 名字和设备名字更新时触发的回调函数

返回结果

Object object

属性 类型 默认值 必填 说明
deviceId string deviceId 设备 id 支持跨面板获取其他的设备信息,当前面板可以传当前设备的 id 来进行获取
dps Object dps

请求示例

ty.device.onDeviceInfoUpdated((res) => {
  console.log(res);
})

返回示例

{
  "dps": {
    "1": false,
    "9": 0,
    "38": "off",
    "40": "relay",
    "42": "",
    "43": "",
    "44": "invalid"
  },
  "deviceId": "vdevo167878067815995"
}

ty.device.offDeviceInfoUpdated

取消监听:设备 dp 名字和设备名字更新时触发

需引入DeviceKit,且在>=2.1.6版本才可使用

请求参数

Function Callback

取消监听:设备 dp 名字和设备名字更新时触发的回调函数

返回结果

请求示例

ty.device.offDeviceInfoUpdated(() => {});

ty.device.onDeviceOnlineStatusUpdate

设备上下线状态变更

需引入DeviceKit,且在>=1.2.6版本才可使用

请求参数

Function Callback

设备上下线状态变更的回调函数

回调结果

Object object

属性 类型 默认值 必填 说明
online boolean 在线状态
deviceId string 设备 id
onlineType number 设备在线类型(预留,后期使用) Wi-Fi online 1 << 0 Local online 1 << 1 Bluetooth LE online 1 << 2 Bluetooth LE mesh online 1 << 3

请求示例

ty.device.onDeviceOnlineStatusUpdate((res) => {
  console.log(res);
})

返回示例

{
  "online": true,
  "deviceId": "vdevo167878067815995"
}

ty.device.offDeviceOnlineStatusUpdate

取消监听:设备上下线状态变更

需引入DeviceKit,且在>=2.1.6版本才可使用

参数

function callback

取消监听:设备上下线状态变更的回调函数

回调参数 Object res

属性 类型 默认值 必填 说明
online boolean 在线状态
deviceId string 设备 id
onlineType number 设备在线类型(预留,后期使用) Wi-Fi online 1 << 0 Local online 1 << 1 Bluetooth LE online 1 << 2 Bluetooth LE mesh online 1 << 3

👉 立即开发

相关推荐
浮华似水11 分钟前
简洁之道 - React Hook Form
前端
正小安2 小时前
如何在微信小程序中实现分包加载和预下载
前端·微信小程序·小程序
说私域2 小时前
基于定制开发与2+1链动模式的商城小程序搭建策略
大数据·小程序
吾爱星辰3 小时前
Kotlin 处理字符串和正则表达式(二十一)
java·开发语言·jvm·正则表达式·kotlin
ChinaDragonDreamer3 小时前
Kotlin:2.0.20 的新特性
android·开发语言·kotlin
IT良3 小时前
c#增删改查 (数据操作的基础)
开发语言·c#
Kalika0-04 小时前
猴子吃桃-C语言
c语言·开发语言·数据结构·算法
_.Switch4 小时前
Python Web 应用中的 API 网关集成与优化
开发语言·前端·后端·python·架构·log4j
一路向前的月光4 小时前
Vue2中的监听和计算属性的区别
前端·javascript·vue.js
长路 ㅤ   4 小时前
vite学习教程06、vite.config.js配置
前端·vite配置·端口设置·本地开发