javascript - react-native蓝牙设备不断断开连接
问题描述
我正在构建一个需要与蓝牙设备通信的 react-native 应用程序(目前仅适用于 Android)。我正在使用这个蓝牙库
我可以成功扫描设备,当我尝试连接时问题开始:等待几秒钟后我收到错误
设备 MAC_ADDRESS 已断开连接
这是代码:
bluetoothInstance.startDeviceScan(null, null, (error, device) => {
console.log('start scanning');
if (error) {
console.log(error);
return
} else {
if (device.id = DEVICE_ID) {
console.log('device found');
console.log('stop scanning');
bluetoothInstance.stopDeviceScan();
console.log('connecting...');
device.connect()
.then((device) => {
console.log("Discovering services and characteristics");
return device.discoverAllServicesAndCharacteristics()
})
.then((device) => {
console.log("Setting notifications");
return device;
})
.then(() => {
console.log("Listening...");
}, (error) => {
console.log(error.message);
})
}
}
});
console.log
连接到设备后我看不到任何打印。我没有阅读“发现服务和特征”,也没有阅读“设置通知”,也没有阅读“正在侦听...”,只是对应于该行的“设备 MAC_ADDRESS 已断开连接” console.log(error.message)
。
我究竟做错了什么?
解决方案
推荐阅读
- javascript - 用于在 javascript 中实现 GUI 编辑器的库或工具(如 figma)
- python - 通过 Python 脚本运行 Powershell 命令不起作用(例如:Set-Location(更改目录))
- azure - 在内联代码连接器逻辑应用中查找 HTML 元素值
- mysql - Mysql系统错误:8 EOF发生违反协议(_ssl.c:877)
- webassembly - WebAssembly 类型化的函数引用不起作用
- python-3.x - 在稳定的 sigmoid 中出现溢出错误
- java - 试图让应用程序从 android 9 运行到 android 11
- android - 知道为什么带有 autoSizeTextType 的 AppCompatTextView (AndroidX) 在平板电脑和 Compat 主题中不起作用吗?
- laravel - Livewire - 我只能将记录添加到数据透视表 - 通过复选框
- python - 使用进度条为 Kivy 应用程序调用顺序线程