小程序开发——获取设备信息 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

👉 立即开发

相关推荐
昔人'9 小时前
使用css `focus-visible` 改善用户体验
前端·css·ux
前端双越老师9 小时前
译: 构建高效 AI Agent 智能体
前端·node.js·agent
进击的圆儿9 小时前
高并发内存池项目开发记录 - 02
开发语言·c++·实战·项目·内存池
xingxing_F9 小时前
Swift Publisher for Mac 版面设计和编辑工具
开发语言·macos·swift
艾小码9 小时前
告别数据混乱!掌握JSON与内置对象,让你的JS代码更专业
前端·javascript
你才是向阳花9 小时前
如何用python来做小游戏
开发语言·python·pygame
夜晚中的人海9 小时前
【C++】使用双指针算法习题
开发语言·c++·算法
怀旧,9 小时前
【Linux系统编程】3. Linux基本指令(下)
linux·开发语言·c++
艾莉丝努力练剑9 小时前
【C++STL :stack && queue (三) 】优先级队列的使用以及底层实现
linux·开发语言·数据结构·c++·stl