基础库 1.1.1 开始支持,低版本需做兼容处理
启用低功耗蓝牙设备特征值变化时的 notify 功能,订阅特征值。注意:必须设备的特征值支持notify
或者indicate
才可以成功调用,具体参照 characteristic 的 properties 属性
另外,必须先启用notify
才能监听到设备 characteristicValueChange 事件
OBJECT参数说明:
参数 |
类型 |
必填 |
说明 |
deviceId |
String |
是 |
蓝牙设备 id,参考 device 对象 |
serviceId |
String |
是 |
蓝牙特征值对应服务的 uuid |
characteristicId |
String |
是 |
蓝牙特征值的 uuid |
state |
Boolean |
是 |
true: 启用 notify; false: 停用 notify |
success |
Function |
是 |
成功则返回本机蓝牙适配器状态 |
fail |
Function |
否 |
接口调用失败的回调函数 |
complete |
Function |
否 |
接口调用结束的回调函数(调用成功、失败都会执行) |
success返回参数:
参数 |
类型 |
说明 |
errMsg |
String |
成功:ok,错误:详细信息 |
示例代码:
wx.notifyBLECharacteristicValueChange({
state: true,
deviceId: deviceId,
serviceId: serviceId,
characteristicId: characteristicId,
success: function (res) {
console.log('notifyBLECharacteristicValueChange success', res.errMsg)
}
})