Qt: 5.10,
Linux Ubuntu 17.10,
Bluez 5.4x
and I´m using QBluetooth to connect with multiple Bluetooth Low Energy Devices. Everything works fine for one Connection. But when I connect to a second Device with QLowEnergyController::connectToDevice() I get the following error and the first Connection gets aborted:
qt.bluetooth.bluez: Cannot connect due to pending active LE Connections
qt.bluetooth.bluez: void QBluetoothSocketPrivate::_q_readNotify() 21 error: -1 "Software caused Connection abort"
After that the second connection gets established.
I`m using one instance of QLowEnergyController in Central Mode per Connection.
After a Research I think it should be possible to create multiple Connections to BLE Peripherals with the Bluez Bluetooth Protocol Stack. But I´m not sure if QBluetooth support this Feature...
Does anybody know something about multiple LE Connections with QBluetooth?
Is this the right way to establish a second Connection?
Does somebody know a good Workaround?
Thanks for your help!
The problem isn't BLE, but its Qt implementation. The documentation says that any attempt to connect simultaneously to two BLE devices using QLowEnergyController will fail. Check it there: http://doc.qt.io/qt-5/qlowenergycontroller.html ; Section "Detailed Description", paragraph 5:
"BlueZ based Linux cannot maintain two connected instances of QLowEnergyController to the same remote device. In such cases the second call to connectToDevice() may fail."
According to this, it should be possible to establish connexion to two different remote devices using two instances of the class, but it simply doesn't work. If you keep on reading the documentation, you'll find out that " This limitation may disappear at some stage in the future.".
I tried a workaround by disconnecting from the first device before connecting to the second device (both TI SensorTag), but since I had to re-discover the services and re-enable the sensors (see disconnectFromDevice() in the documentation) every time I would re-connect the program became way too slow.
If you want to connect to two devices using Qt, you have to use the Bluez API through the D-Bus with Qt's D-Bus classes.
Edit:
I managed to connect to multiple devices using D-Bus classes. The architecture of my program isn't much more complicated, only the syntax got a little more tricky. The only big issue was the BlueZ version: the D-Bus interface changed a lot between 5.3x (default Ubuntu 16.04) that doesn't support Low Energy (experimental...) and later versions. I think that's the reason why Qt's D-Bus Bluetooth hasn' been enabled yet. Since BLE isn't flagged as experimental since BlueZ 5.42, you should be fine using D-Bus with your current version. For the record, I'm perfectly fine using D-Bus with Raspbian's default 5.9 BlueZ.
Related
I have a BLE module that i'm trying to update the firmware in, but having a lot of problems connecting the recommended update software (ISupdater). All I get is 'connect failed' message. There seems to be no troubleshooting information available, so I hope that someone has run into the same issues and solved it.
For the hardware setup, I'm connecting to a PC via a USB-USART serial adapter board. I have the 3.3V, GND, reset switch, mode switch, USART connection from the RN4870 BLE module connected as per the microchip connection diagrams (https://microchipdeveloper.com/ble:rn4870-app-example-fw-upgrade). I have verified many many many times that my connections are correct.
Connection Diagram
To test the BLE connection and data transfer I have mobile devices (iOS and Android) with the recommended apps (SmartData, mBIoT). I can see the BLE broadcast in the bluetooth lists, and I can connect to it to use the apps.
For the RN4870 module, I'm able to connect to CoolTerm software to test that I'm getting communication between the terminal and a mobile device. I'm able to send and receive data on the CoolTerm terminal, and on the mobile device apps, so that suggests to me that the USART adaptor is working correctly, and so is the BLE module.
In CoolTerm, I'm able to enter the CMD mode for the RN4870 module to set and read settings of the module, so I can check and set the baudrate to the default 115200.
If I use a BM70 module (which is the same hardware as RN4870 but different firmware), i can't enter any CMD mode, or do any sort of reset. The data is still able to be sent and received, so that confirms the baud rate is correct.
When I attempt to connect to either BLE module using the ISUpdate software that is recommended in the update steps to use as the firmware updater, I'm not able to connect to the module to update the firmware. I've tried many times to get the software to connect, many different ways, without success, and it's frustrating to no end.
I've updated the MCP2200 drivers to the latest ones from the microchip website, as well as using the latest versions of the CoolTerm and ISupdater. I've also tried previous versions, but still they all have 'connect failed'
ISupdater Image
has anyone got any solutions to the issue?
PC: Windows 10, 64-bit
BLE Modules: RN4870, BM70
CoolTerm Version: v1.8.0 (build 861)
ISUpdater Version: v4.0.0.207
IS187x_102_BLEDK3v1.11_UIv1.01 for Windows 10
Mobile Apps: SmartData, LightBlue for iOS, LightBlue for Android, mBIoT
Hmm, well it turns out that the USB-USART serial adaptor (although confirmed to be working correctly) seemed to be the problem.
At first, I only had the 1 adaptor, and I had to borrow a different adaptor. After swapping this FTDI232 USB-USART Serial adaptor, the connection was made first try, and I was able to update the firmware. I have now purchased a new adaptor.
So, if you are having the same trouble, try using a different adaptor.
I'm trying to establish a connection between my PC running Ubuntu and my iPhone via Bluetooth automatically when it becomes available, after being manually paired beforehand. I've seen this to be possible with certain peripherals, mainly audio. For example, my phone will automatically connect to a Bluetooth speaker when it is turned on and Bluetooth is active on my phone; another example is my phone automatically connects to my car's radio system via Bluetooth when I turn the car on.
I'm not able to connect my phone to my PC without first initiating the connection from the smartphone's Bluetooth menu. I'm thinking that I could possibly write an application for the PC to attempt to connect to the device every few minutes or something, but it seems that the phone needs to be the device to initiate the connection.
The only information that I need for what I'm trying to do ultimately is that the devices can pair successfully. Essentially I'm trying to build a sort of proximity trigger between my phone and my PC without using Wi-Fi and GPS - I can't use these for some specific reasons.
Is there any way to make this happen?
Yes this should be doable as long as you use the Background Processing feature for iOS apps. In the example I'll give below, we'll have the PC be the peripheral and the phone be the central, but you can really have it working either way. You will need to do the following:-
First initial connection needs to be performed in the foreground (this is due to iOS's background limitations).
On the iOS side, you need an application that acts as a central that scans and connects to the remove device (check this example as a starting point).
Upon connection, you need to bond with the PC. Bonding is important as it will prevent you from having to do the pairing again in the future. However, pairing/bonding is managed by the iPhone's OS so you cannot write it in your application, so the workaround is to have an encrypted characteristic on the PC side that will force the iPhone to bond (this is covered later).
On the PC side, you need to have a BlueZ script that acts as a peripheral that is always advertising. You can do this using bluetoothctl (check the examples here and here).
Before you start advertising, you need to have a GATT server on the PC side (to do this, check this example).
When registering characteristics, ensure that one of them has the encrypt-read property (you can find a full list of the properties here).
Now when you attempt to read this characteristic from the iOS side, the two devices should bond (make sure that your PC is bondable which you can do this via these commands).
Once the devices are paired, your iOS app needs to be working in the background constantly scanning and attempting to connect to the same peripheral (have a look at this and this example).
You can find more useful information at the links below:-
Getting started with Bluetooth Low Energy
The Ultimate Guide to CoreBluetooth Development
How to manage Bluetooth devices on Linux using bluetoothctl
I am writing a library in C/C++ for a Bluetooth low energy device. So far I have been using the D-Bus interface exposed by Bluez and been able to discover, connect and communicate with the device.
However, when the device disconnects either due to a link failure or it being out of range, reconnecting to it is not trivial. Ideally I would like to be able to create pending connections to all disconnected devices, but Bluez doesn't seem to support that. It seems that Bluez only supports one simultaneous connect call, which timeouts after 15-20 seconds.
A solution would thus be to listen for advertisement packages, and connect when a known device is detected. The good people on #bluez told me that this was already implemented, and the way to do it is to register an object that implements GattProfile1 with the GattManager1 RegisterProfile method. Trying this gave no result, the device stays disconnected after a link failure. It is also very poorly documented, so there is a good chance I have missed something.
My questions are: Is this the right solution? Will it provide a seamless and fast reconnections? If it is, what can be wrong?
If you wish to reconnect to a single bluetooth device, you can monitor the connection state by receiving org.freedesktop.DBus.Properties.PropertiesChanged, and calling org.bluez.Device1.Connect to reconnect when necessary. Since this will timeout, you can put Connect() inside a loop which you will exit only when the org.bluez.Device1.Connected property is true.
Has the original author managed to do this yet for multiple devices by implementing GattProfile1?
I would like to know which is the current modern way to do DUN reverse tethering using Bluez version >= 5.
I have an old PDA that I use sometime (a Tapwave Zodiac running PalmOS5. It's similar to Palm Tungsten, etc.) These old devices don't have Wifi, only Bluetooth. For networking over Bluetooth, these old devices don't support PAN, only DUN.
So to provide them networking, one need to share a desktop PC's connection over bluetooth DUN.
Up until Bluez version 4, the standard way to provide networking over bluetooth for such PalmOS 5 devices was:
https://wiki.debian.org/BluetoothPalmOSConnection
Basically:
run "dund" to listen for incoming connection.
once the palmos device connects to the PC, have dund start PPPD with parameters tailored for the device
use iptables to forward the connection.
My problem:
I've read that bluez 5 changed the way DUN is handled and thus support for the old "dund" was dropped.
Indeed there's no "bluez-compat" package available anymore for my current distro (opensuse 13.1, runs bluez 5.18)
So my question:
What's the modern successor of "dund --listen" for bluez 5 ?
How should I setup a DUN service on my computer to which to connect from my PDA ?
I've looked around, but I haven't been able to find any guide.
The "dund" functionality should very probably be replicated using some scripting and dbus calls. But I can't find any pointer where to begin looking for a solution.
Thanks for your help.
I think you can
Run pppd with "rfcomm listen" in the "connect" script of your /etc/ppp/peers/ file
Use "sdptool add DUN" so that your service is discoverable
I guess you'll figure out the exact details yourself. Please respond if it won't work for you and I'll try that myself or be more specific.
Take care,
Lubo
I have been using bluetooth module BC 417 of company "NOVA".
I have kept all UART setting as suggested by datasheet.
i.e. buad rate=9600, parity=none, stop bit=1
My connection is getting established with nokia 5130 bluetooth, but as soon as m going to send something from UART connection is disabled.
Whenever i go to connect this module to android phone's bluetooth, connection does not take place.
For making connection i am using this command BC:CS=<address of bluetooth>
So i have following question:-
Is there any another setting is required in hyper terminal?
Is there any firmware is available for nova comm control interface module version 1.2?
Sorry, I only have enough reputation to answer and not just comment. You might want to try making sure that hardware flow control is switched on. It's a little difficult to know for sure as details of your set-up are so sketchy. Are you connecting this to an embedded micro and then trying to connect to a phone? What are you connecting hyper terminal to? Another phone or this Nova module?