基础库 1.1.0 开始支持,低版本需做兼容处理
读取低功耗蓝牙设备的特征值的二进制数据值。注意:必须设备的特征值支持read
才可以成功调用,具体参照 characteristic 的 properties 属性
OBJECT参数说明:
参数 |
类型 |
必填 |
说明 |
deviceId |
String |
是 |
蓝牙设备 id,参考 device 对象 |
serviceId |
String |
是 |
蓝牙特征值对应服务的 uuid |
characteristicId |
String |
是 |
蓝牙特征值的 uuid |
success |
Function |
是 |
成功则返回本机蓝牙适配器状态 |
fail |
Function |
否 |
接口调用失败的回调函数 |
complete |
Function |
否 |
接口调用结束的回调函数(调用成功、失败都会执行) |
success返回参数:
参数 |
类型 |
说明 |
errCode |
Number |
错误码 |
errMsg |
String |
成功:ok,错误:详细信息 |
示例代码:
wx.onBLECharacteristicValueChange(function(characteristic) {
console.log('characteristic value comed:', characteristic)
})
wx.readBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
success: function (res) {
console.log('readBLECharacteristicValue:', res.errCode)
}
})