2***@qq.com
2***@qq.com
  • 发布:2020-08-17 16:01
  • 更新:2020-08-17 16:01
  • 阅读:679

监听不到蓝牙特征值的变化

分类:uni-app

第一次连接设备的蓝牙能够正常监听到特征值的变化,如果设备蓝牙关闭,断开连接后重新打开,重新连接的时候就监听不到特征值的变化了?

第二次连接的时候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();  
                    }  
                });  
            },
2020-08-17 16:01 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复