Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

Qt Bluetooth Low Energy Notification Bug / Downgrade Qt



  • I'm having the exact same problem as @nowayback described in this Post.
    The mentioned "solution" was to downgrade Qt from 5.11.3 (current version on my Raspberry Pi) to 5.7.1.

    Is there a way to downgrade without compiling Qt from source?
    Or better: Has this problem been fixed in newer versions of Qt?



  • I've found a workaround for it:
    If you set the environment variable BLUETOOTH_FORCE_DBUS_LE_VERSION to anything below 5.42, Qt will use the old GATT stack implementation instead of BlueZ DBUS implementation. What I've tested:

    BLUETOOTH_FORCE_DBUS_LE_VERSION=5.41 ./BleTest
    

    I'll close this and keep the bugreport open since it's a missing feature / bug of the new implementation.

    Source: qlowenergycontroller.cpp and bluez5_helper.cpp


  • Lifetime Qt Champion

    Hi,

    It depends whether you are cross-compiling or building directly on your target.

    As for the issue, I do not know if it was or not reported since there was no answer on the thread.

    You should check the module's release logs to see if there is anything related there. You might be able to rebuild just that module. However, I would recommend using a more recent version anyway. The current LTS is 5.15 and Qt 6 just got released.



  • This post is deleted!


  • @SGaist
    I'm building directly on my Raspberry Pi 4 since my project is not that large.
    But if I want to use a newer version of Qt I'll have to build it myself, right?
    Or are there any binaries / prebuilt packages to use?


  • Lifetime Qt Champion

    @chrizbee indeed, unless someone has a PPA with packages that can be used on the distribution you use on the Pi.

    Note that you do not need the whole of Qt. Start with qtbase which is mandatory and then only the modules you actually need. It will cut time a lot.



  • @SGaist Okay... here we go again...
    I will report back later if the mentioned bug was fixed with newer versions of Qt (testing with 5.15.2).


  • Lifetime Qt Champion

    Check the bug report system first, this might avoid you long hours of compilation.



  • @SGaist
    I've read some of the Connectivity: Bluetooth bugreports which do not yield any solutions...
    Before building I've tested my code on windows with Qt 5.15.2 which results in the exact same "error".

    So here's my problem:
    My BLE device has the address: FF:FF:20:05:B3:E9 (hcitool lescan)
    With gatttool I am able to subscribe to handle: 0x000e, uuid: 0000ffe1-0000-1000-8000-00805f9b34fb with this command:

    gatttool -b FF:FF:55:03:9F:52 --char-write-req --handle=0x000e --value=0100 --listen
    

    In my application I'm doing the following (pseudocode):

    agent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
    // wait for QBluetoothDeviceDiscoveryAgent::deviceDiscovered(info)
    control = QLowEnergyController::createCentral(info, this);
    control->connectToDevice();
    // wait for QLowEnergyController::connected
    control->discoverServices();
    // wait for QLowEnergyController::serviceDiscovered(uuid)
    if (uuid == myUuid) {
        service = control->createServiceObject(uuid, this);
        // connect characteristicChanged, stateChanged, error, ...
        service->discoverDetails();
    }
    // wait for QLowEnergyService::stateChanged(state)
    if (state == QLowEnergyService::ServiceDiscovered) {
        auto chs = service->characteristics();
        for (QLowEnergyCharacteristic &c : chs) {
            auto des = c.descriptors();
            for (QLowEnergyDescriptor &d : des) {
                qDebug() << d.name() << d.type() << d.handle() << d.uuid() << d.value();
            }
        }
    

    Unfortunately I'm not able to write to the descriptor QBluetoothUuid::ClientCharacteristicConfiguration because service->characteristic(myUuid).descriptors().size() is 0 (characteristic has no descriptors).

    So why can I subscribe to the given uuid / handle with gatttool but not with Qt?



  • @SGaist Or should I create a new post that isn't related to downgrading Qt?



  • Given both of these:

    (1) The older post: https://forum.qt.io/topic/98115/low-energy-bluetooth-notifications-not-working

    And (2) the current issue described here of being unable to convince Qt to attach to notifications because descriptors().size() is zero.

    ... in my mind this definitely qualifies as a reportable bug at https://bugreports.qt.io

    I'm half inclined to report it myself, but I don't have the requisite hardware for reproducing and testing this.

    If I am reading this post (and the other one) correctly, then it looks like there is a valid BLE usage scenario that the Qt BLE code simply fails to account for. And this scenario is roughly described as "my BLE peripheral always sends notifications, despite not providing a 0x2902 descriptor with which to enable them."

    Do any of these cover it?

    https://bugreports.qt.io/browse/QTBUG-83363
    https://bugreports.qt.io/browse/QTBUG-54806
    https://bugreports.qt.io/browse/QTBUG-89723

    If not, then please report it. BLE seems to continue to grow in popularity, so getting this working for future users (not to mention your own use case!) would be a great service.



  • @KH-219Design Your last link is my bugreport :D
    I'm currently testing other Qt versions to see for which version bump it'll stop working.



  • Update: The application does not receive any notifications without configuration for Qt versions >= 5.11.0.

    • Qt 5.10.1: Working
    • Qt 5.11.0: Not working

    It's most probably due to this change:
    [QTBUG-46819] Ported QLowEnergyController central mode to BlueZ's DBus API. The new implementation is used when BlueZ 5.42+ is detected.



  • Excellent investigation. I am now following that bug ticket. Eager to see where it leads...



  • @KH-219Design Do you think there is a workaround for the time being?
    I don't want to build Qt 5.9.9 for my Raspberry Pi...



  • I don't want to rule out the possibility of a workaround, but if I had to make a wager, I would say it is a long shot.

    I have never cross-compiled Qt, so I'm not sure if it is tricky to cross-compile for rpi using a linux host. If you don't want to cross-compile, then I would imagine that the main issue with building for rpi is that you would be building on the rpi, and this will take hours.

    But hey... if you start now, then in a few hours this can all be over ;)

    Other than the idea of it taking a long time, are there other concerns with building from source? I actually do it often (once a month or so) on Linux, and it isn't that bad.

    I've posted about the steps before (but this is all for Ubuntu):

    https://forum.qt.io/topic/119026/how-much-time-will-it-take-to-build-qt-5-15-x-source-package/10

    https://forum.qt.io/topic/114784/definitive-guide-to-building-source-from-downloaded-run-file/33

    Whenever I build any large open source project, it seems that the trickiest part is often just getting all the other '*dev' library dependencies installed first, so that the build can find everything and succeed.

    If something like this exists on raspbian, then you should be most of the way there:

    sudo apt-get build-dep qt5-default
    

    Another option would be to find someone who maintains rpi binaries for qt. Does no one maintain such a collection?



  • @KH-219Design I've actually built Qt directly on a Raspberry Pi 4 a couple of times. But I don't want to stick to the older version of Qt 5.9.9 if there's a workaround for more recent versions.

    [QTBUG-46819] Ported QLowEnergyController central mode to BlueZ's DBus API. The new implementation is used when BlueZ 5.42+ is detected. Earlier versions will continue to use the the previous custom GATT stack. The benefit of this change is improved co-existence with BlueZ which avoids interference between BlueZ and Qt and permits multiple Qt and platform apps being able to share BTLE connections. The custom GATT peripheral role implementation is still used on all BlueZ platforms.

    I thought of something like downgrading BlueZ to < 5.42 (see bold text). Might give that a try if possible.



  • I've found a workaround for it:
    If you set the environment variable BLUETOOTH_FORCE_DBUS_LE_VERSION to anything below 5.42, Qt will use the old GATT stack implementation instead of BlueZ DBUS implementation. What I've tested:

    BLUETOOTH_FORCE_DBUS_LE_VERSION=5.41 ./BleTest
    

    I'll close this and keep the bugreport open since it's a missing feature / bug of the new implementation.

    Source: qlowenergycontroller.cpp and bluez5_helper.cpp


Log in to reply