基础库 1.1.0 开始支持,低版本需做兼容处理
获取蓝牙设备某个服务中的所有 characteristic(特征值)
OBJECT参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| deviceId | String | 是 | 蓝牙设备 id,参考 device 对象 |
| serviceId | String | 是 | 蓝牙服务 uuid |
| success | Function | 是 | 成功则返回本机蓝牙适配器状态 |
| fail | Function | 否 | 接口调用失败的回调函数 |
| complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
success返回参数:
| 参数 | 类型 | 说明 |
|---|---|---|
| characteristics | Array | 设备特征值列表 |
| errMsg | String | 成功:ok,错误:详细信息 |
蓝牙设备characteristic(特征值)信息
| 参数 | 类型 | 说明 |
|---|---|---|
| uuid | String | 蓝牙设备特征值的 uuid |
| properties | Object | 该特征值支持的操作类型 |
| 参数 | 类型 | 说明 |
|---|---|---|
| read | Boolean | 该特征值是否支持 read 操作 |
| write | Boolean | 该特征值是否支持 write 操作 |
| notify | Boolean | 该特征值是否支持 notify 操作 |
| indicate | Boolean | 该特征值是否支持 indicate 操作 |
示例代码:
wx.getBLEDeviceCharacteristics({
// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
deviceId: deviceId,
// 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取
serviceId: serviceId,
success: function (res) {
console.log('device getBLEDeviceCharacteristics:', res.characteristics)
}
})
