[英]Using two instances of Qt's `QLowEnergyController` to connect to two BLE devices
I want to use Qt's Bluetooth Low Energy to connect to two BLE devices.我想使用 Qt 的低功耗蓝牙连接到两个 BLE 设备。
I use have two QLowEnergyControllers instances like this:我使用了两个QLoEnergyControllers实例,如下所示:
controller0 = QLowEnergyController::createCentral(qBluetoothDeviceInfoBLE0, this));
controller1 = QLowEnergyController::createCentral(qBluetoothDeviceInfoBLE1, this));
If then successfully conneect with BLE0
, and after the signal connected()
is emited, I initiate a connection to BLE1
.如果然后与
BLE0
成功connected()
,并且在发出connected()
信号后,我将启动与BLE1
的连接。 The connection to BLE0
will be aborted:与
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"
... and the connection to BLE1
will be established successfully. ... 与
BLE1
的连接将成功建立。
What I found is this description in QLowEnergyControllers :我发现的是QLoEnergyControllers 中的这个描述:
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
值得一提的是,某些平台(例如基于 BlueZ 的 Linux)无法将 QlowEnergyController 的两个连接实例维护到同一个远程设备
Note: BLE0
and BLE1
are different remote devices.注意:
BLE0
和BLE1
是不同的远程设备。
I can also confirm that connecting to the same devices works with my version of bluez.我还可以确认连接到相同的设备适用于我的 bluez 版本。 It also works when using nodejs' package noble.
它也适用于使用 nodejs 的包 noble 时。
BLE0
, and afterwards BLE1
)? BLE0
,然后是BLE1
)?This is fixed by now (QT 5.11, BlueZ 5.50, Raspian, tested with RPi 4).现在已修复(QT 5.11、BlueZ 5.50、Raspian,已使用 RPi 4 进行测试)。 I can easily create two instances of
QLowEnergyController
.我可以轻松地创建
QLowEnergyController
两个实例。
However, there can only be one QBluetoothDeviceDiscoveryAgent
active at a time.但是,一次只能有一个
QBluetoothDeviceDiscoveryAgent
处于活动状态。 That means one has to discover all devices first and afterwards connect to them by creating a separate QLowEnergyController
object for each peripheral.这意味着必须首先发现所有设备,然后通过为每个外围设备创建单独的
QLowEnergyController
对象来连接到它们。
Here is a great short example https://bugreports.qt.io/browse/QTBUG-73809这是一个很好的简短示例https://bugreports.qt.io/browse/QTBUG-73809
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.