function monitorNotification() {
uni['notifyBLECharacteristicValueChange']({
deviceId: connectDeviceId,
serviceId: serviceUUID,
characteristicId: readUUID,
state: true,
success: function(res) {
console.log('notifyBLECharacteristicValueChange', res)
uni['onBLECharacteristicValueChange'](function(ffyevz2) {
console.log('onBLECharacteristicValueChange', ffyevz2)
if (ffyevz2['deviceId'] = connectDeviceId && ffyevz2['serviceId'] == serviceUUID && ffyevz2['characteristicId'] ==
readUUID) {
analyticData(ffyevz2['value'])
}
})
},
fail: function(res) {
console.log('notifyBLECharacteristicValueChange fail', res)
if (typeof connectTimer != undefined) {
clearTimeout(connectTimer)
}
typeof connectCallback == FUNCTION && connectCallback(codeEnum['monitorNotificationFailure'])
}
});
}
前面的都成功了,
我要侦听的特征值 {"uuid":"0000FEC8-0000-1000-8000-00805F9B34FB","properties":{"read":false,"write":false,"notify":false,"indicate":true} 也读取到了。并且notifyBLECharacteristicValueChange 也成功了
notifyBLECharacteristicValueChange---COMMA------BEGIN:JSON---{"errMsg":"notifyBLECharacteristicValueChange:ok"}---END:JSON-
但是后面侦听就没有东西了。
同样的代码,我在小程序测试的时候,就能读取到设备发过来的信息。
这个是小程序的调试日志:
hbuilderX 2.5.1
手机:小米 MI 8 SE 系统 MUI 11.0.3