wx.getBLEDeviceCharacteristics(Object object)

基础库 1.1.0 开始支持,低版本需做兼容处理

获取蓝牙设备某个服务中所有特征值(characteristic)。

参数

Object object

属性类型默认值必填说明
deviceIdstring蓝牙设备 id
serviceIdstring蓝牙服务 uuid,需要使用 getBLEDeviceServices 获取
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

object.success 回调函数

参数
Object res
属性类型说明
characteristicsArray.<Object>设备特征值列表

res.characteristics 的结构

属性类型说明
uuidstring蓝牙设备特征值的 uuid
propertiesObject该特征值支持的操作类型

properties 的结构

属性类型说明
readboolean该特征值是否支持 read 操作
writeboolean该特征值是否支持 write 操作
notifyboolean该特征值是否支持 notify 操作
indicateboolean该特征值是否支持 indicate 操作

错误

错误码错误信息说明
0ok正常
10000not init未初始化蓝牙适配器
10001not available当前蓝牙适配器不可用
10002no device没有找到指定设备
10003connection fail连接失败
10004no service没有找到指定服务
10005no characteristic没有找到指定特征值
10006no connection当前连接已断开
10007property not support当前特征值不支持此操作
10008system error其余所有系统上报的异常
10009system not supportAndroid 系统特有,系统版本低于 4.3 不支持 BLE
10012operate time out连接超时
10013invalid_data连接 deviceId 为空或者是格式不正确

示例代码

在开发者工具中预览效果

  1. wx.getBLEDeviceCharacteristics({
  2. // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
  3. deviceId,
  4. // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
  5. serviceId,
  6. success (res) {
  7. console.log('device getBLEDeviceCharacteristics:', res.characteristics)
  8. }
  9. })