Low Energy Bluetooth: Notifications not working
-
I am trying to connect to a TI CC2540-based Bluetooth development board ("Beetle BLE"). It sets up a serial bridge to a microcontrolling unit. For this purpose, one single characteristic is used: when writing data to this characteristic, it is transmitted to the MCU, while data coming from the MCU is transferred using characteristic notifications (Polling / reading the characteristic is not really supported and would not make that much sense anyway).
The only descriptor this characteristic comes with is a QBluetoothUuid::CharacteristicUserDescription (0x2901) descriptor. There is no QBluetoothUuid::ClientCharacteristicConfiguration (0x2902) descriptor to enable notifications, as notifications are enabled by default. For example, when using a MCU firmware which outputs data every 1sec, the output of gatttool is:
$ gatttool -b 64:CF:D9:35:A0:CE -I
[64:CF:D9:35:A0:CE][LE]> connect
Attempting to connect to 64:CF:D9:35:A0:CE
Connection successful
Notification handle = 0x0025 value: 61 6c 69 76 65 0d 0a
Notification handle = 0x0025 value: 61 6c 69 76 65 0d 0a
Notification handle = 0x0025 value: 61 6c 69 76 65 0d 0a
[64:CF:D9:35:A0:CE][LE]> quitThe Android demo application also seems to just install notification callback handlers and everything is fine.
My problem is, that Qt does not receive these notifications at all.
Using Qt, I can send data to the MCU using the respective characteristic without any issuesservice->writeCharacteristic(..., "test");
, but the notification slot is never called:
connect(service, SIGNAL(characteristicChanged(const QLowEnergyCharacteristic &, const QByteArray &)), this, SLOT(service_characteristicChanged(const QLowEnergyCharacteristic &, const QByteArray &)));
. I used the heartlistener example project as reference, but even rewriting the complete code did not help.
Android- and PC-based Low Energy tools have no problems receiving them. I activated the qt.bluetooth.bluez logging filter but could not see any hints that there are receipted notifications at all.
It seems I am not the only one with this problem.
I have tested:
- RPi 3B+, Qt 5.9.1 and 5.11.2, onboard Bluetooth device
- RPi 3B+, Qt 5.9.1 and 5.11.2, USB BLE stick
- Ubuntu, Qt 5.11.3, onboard Qualcomm BLE
with all showing the same issue. I always used the bluez backend, I have not been able to test WinRT and Android.
I even tried to write 0x0100 to the non-existing 0x2902 descripter in case Qt needs this to enable notifications internally, but not surprisingly this did not help. I have also not found any clues in the QtConnectivity source.
Is there something I missed? How can I narrow down the cause of the problem?
Thanks.
-
After several desperate tries, I could finally solve my issue: I downgraded Qt from 5.11.3 down to 5.7.1, and my code is working perfectly there (without any changes).
I'm slightly annoyed at myself that I actually tried to downgrade Qt before, but I only downgraded to 5.9.1, which was not sufficient.
-
Hi and welcome to devnet,
That looks like a regression. Did you already took a look at the bug report system ?
-
@nowayback Almost two years later I had the exact same problem.
Instead of downgrading Qt you can run your app like this.BLUETOOTH_FORCE_DBUS_LE_VERSION=5.41 /path/to/YourApplication
The version number should be anything below 5.41 to use the old GATT stack implementation. For further information see this post.
-
I also run now in this issue using Qt 5.15.
I tried to send a command to a thermostate and expected an response from it. After using the workaround menthioned above everything works.
Is there a plan to fix this or is it maybe already fixed in Qt > 6 ?