简体   繁体   English

使用 Qt 的“QlowEnergyController”的两个实例连接到两个 BLE 设备

[英]Using two instances of Qt's `QLowEnergyController` to connect to two BLE devices

Problem问题

I want to use Qt's Bluetooth Low Energy to connect to two BLE devices.我想使用 Qt 的低功耗蓝牙连接到两个 BLE 设备。

System系统

  • OS: Arch Linux 4.13.8操作系统: Arch Linux 4.13.8
  • bluez version: 5.47 bluez 版本: 5.47
  • BLE adaptor: Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode) BLE 适配器: Cambridge Silicon Radio, Ltd 蓝牙适配器(HCI 模式)

Solution解决方案

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的连接将成功建立。

Found找到

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.注意: BLE0BLE1是不同的远程设备。

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 时。

Questions问题

  1. Should it work as I have done it above?它应该像我上面所做的那样工作吗? (connect to BLE0 , and afterwards BLE1 )? (连接到BLE0 ,然后是BLE1 )?
  2. I was thinking of using a second adaptor, is it correct that QBluetooth can only use one adaptor (the default one)?我正在考虑使用第二个适配器,QBluetooth 只能使用一个适配器(默认适配器)是否正确?
  3. Can somebody think of any workaround?有人能想到任何解决方法吗?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM