问题
我想使用Qt的Bluetooth Low Energy连接到两个BLE设备。
系统
解
我使用了两个像这样的QLowEnergyControllers实例:
controller0 = QLowEnergyController::createCentral(qBluetoothDeviceInfoBLE0, this));
controller1 = QLowEnergyController::createCentral(qBluetoothDeviceInfoBLE1, this));
如果然后成功地与
BLE0
连接,并且在发出connected()
信号之后,我将启动到BLE1
的连接。与BLE0
的连接将被中止:qt.bluetooth.bluez: Cannot connect due to pending active LE connections
qt.bluetooth.bluez: void QBluetoothSocketPrivate::_q_readNotify() 17 error: -1 "Software caused connection abort"
...,到
BLE1
的连接将成功建立。找到了
我发现的是QLowEnergyControllers中的此描述:
It is important to mention that some platforms such as a BlueZ based Linux cannot maintain two connected instances of QLowEnergyController to the same remote device
注意:
BLE0
和BLE1
是不同的远程设备。我还可以确认连接到相同的设备适用于我的bluez版本。当使用nodejs的noble包时,它也可以工作。
问题
BLE0
,再连接BLE1
)? 最佳答案
现在已解决此问题(QT 5.11,BlueZ 5.50,Raspian,已通过RPi 4测试)。我可以轻松地创建QLowEnergyController
的两个实例。
但是,一次只能有一个 Activity 的QBluetoothDeviceDiscoveryAgent
。这意味着必须先发现所有设备,然后再通过为每个外围设备创建一个单独的QLowEnergyController
对象来连接它们。
这是一个很棒的简短示例https://bugreports.qt.io/browse/QTBUG-73809
关于c++ - 使用Qt的 `QLowEnergyController`的两个实例连接到两个BLE设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46973968/