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

👉 立即开发

相关推荐
钛态17 小时前
Vite 中的 CSS 工程化:从 CSS Modules 到 UnoCSS 的渐进式迁移
前端·vue·react·web
「QT(C++)开发工程师」18 小时前
C++ 11 常用for循环
开发语言·c++
我还记得那天18 小时前
0 初识C++
开发语言·c++
FfHUCisI18 小时前
Go 编译过程全景
开发语言·后端·golang
FfHUCisI18 小时前
Golang 语法分析与 AST:Parser 与 go/ast
开发语言·后端·golang
Csvn19 小时前
原型链、this 与闭包内存:三座深水区一次打通(含内存泄漏排查实战)
前端·javascript
lemon_sjdk19 小时前
ObjectProperty
java·开发语言·算法
葡萄城技术团队19 小时前
如何通过 JSON 数据源 / Web API 快速构建轻量级报表(Report)?
前端·json·原型模式