第一次连接设备的蓝牙能够正常监听到特征值的变化,如果设备蓝牙关闭,断开连接后重新打开,重新连接的时候就监听不到特征值的变化了?
第二次连接的时候notify开启是正常的,就是不执行uni.onBLECharacteristicValueChange()方法
notifyBLECharacteristicValue() {
let deviceId = uni.getStorageSync('deviceId');
let serviceId = uni.getStorageSync('serviceId');
let characteristicId = uni.getStorageSync('notifyId');
let notify = true;
let self = this;
uni.notifyBLECharacteristicValueChange({
state: true, // 启用 notify 功能
deviceId,
serviceId,
characteristicId,
success(res) {
console.log(res)
uni.onBLECharacteristicValueChange(function (res) {
console.log(res)
console.log(self.ab2hex(res.value))
})
},
fail(res) {
console.log(res)
uni.showToast({
title: '数据获取失败',
icon: 'none',
mask: true
});
self.onlyOneDeal = true;
self.notifyBLECharacteristicValue();
}
});
},
0 个回复