uniapp低功耗蓝牙多次回调
时间: 2023-12-15 13:33:03 浏览: 188
根据提供的引用内容,uniapp低功耗蓝牙多次回调需要使用uni.onBLECharacteristicValueChange()方法。该方法用于监听低功耗蓝牙设备的特征值变化事件,当低功耗蓝牙设备的特征值发生变化时,会触发该事件,从而实现多次回调。
以下是一个uniapp低功耗蓝牙多次回调的示例代码:
```javascript
// 初始化蓝牙适配器
uni.openBluetoothAdapter({
success: function (res) {
console.log('初始化蓝牙适配器成功');
// 开始搜索蓝牙设备
uni.startBluetoothDevicesDiscovery({
services: [],
allowDuplicatesKey: true,
success: function (res) {
console.log('开始搜索蓝牙设备成功');
// 监听蓝牙设备变化事件
uni.onBluetoothDeviceFound(function (res) {
console.log('发现新蓝牙设备:' + JSON.stringify(res.devices));
});
// 监听低功耗蓝牙设备的特征值变化事件
uni.onBLECharacteristicValueChange(function (res) {
console.log('低功耗蓝牙设备的特征值发生变化:' + JSON.stringify(res));
});
},
fail: function (res) {
console.log('开始搜索蓝牙设备失败:' + JSON.stringify(res));
}
});
},
fail: function (res) {
console.log('初始化蓝牙适配器失败:' + JSON.stringify(res));
}
});
```
阅读全文
相关推荐
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)