Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QLowEnergyController disconnectFromDevice has no effect



  • Hi, I'm trying to implement an Application for Windows, which communicates with a nordic nrf52840 with a running BLE softdevice (blinky demo app).
    I managed it to scan devices, connect to the device, using write and notify characteristics for transmitting data.
    However, when I disconnect from the device, using QLowEnergyController.disconnectFromDevice(), I receive the stateChanged signal with Unconnected state, but the Windows "Bluetooth & other devices" dialog still shows the state "Connected" and not "Paired" as expected. This behavior is reproducable.

    I use Windows 10 Enterprise (10.0.17134) on a Dell Latitude 5480 with the internal bluetooth chip.
    I tried many Qt versions:

    QtVersion					Error				        Remark			
    
    Desktop Qt5.12.5 MSVC 2017 64-Bit debug		still connected after disconnect	
    Desktop Qt5.12.5 MSVC 2017 64-Bit release	still connected after disconnect
    Desktop Qt5.13.2 MSVC 2017 64-Bit debug		still connected after disconnect	Lists also unpaired devices when scanning
    Desktop Qt5.13.2 MSVC 2017 64-Bit release	still connected after disconnect	Lists also unpaired devices when scanning
    Desktop Qt5.14.0 MSVC 2017 64-Bit debug		still connected after disconnect	Tried with 2 different BLE devices (nordic + bluegiga) and 3 different firmware implementations
    Desktop Qt5.14.0 MSVC 2017 64-Bit release	still connected after disconnect	
    Desktop Qt5.14.0 minGW 64-Bit debug			does not connect	
    Qt 5.13.2 for UWP 64bit MSVC debug			crashes when trying to connect
    

    I also tried using Qt 5.12.5 on a Dell OptiPlex 7050 with a Rocketek RT-BT4 dongle. OS: Windows 10 Enterprise (10.0.14393).
    Here the device can be connected for about 1sec. Then it is automatically disconnected.

    Further I tried to build the same application on macOS 10.15.1 (macbook pro 13" early 2015). The application behaves like expected. It connects and disconnects appropriately.

    What I do in my code is the following:

    void MainWindow::controllerStateChanged(QLowEnergyController::ControllerState state)
    {
        qDebug() << "STATE: " << state;
        ui->coControllerState->setCurrentIndex(static_cast<int>(state));
    }
    
    void MainWindow::controllerError(QLowEnergyController::Error error)
    {
        qDebug() << "controller ERROR:" << error;
    }
    
    void MainWindow::on_pbConnect_clicked()
    {
        if (itsLEController == nullptr)
        {
            if (itsDiscoveryAgent != nullptr && itsDiscoveryAgent->isActive())
            {
                itsDiscoveryAgent->stop();
            }
    
            QBluetoothDeviceInfo currentDeviceInfo = itsDeviceInfos.at(ui->coDevices->currentIndex());
            itsLEController = QLowEnergyController::createCentral(currentDeviceInfo, this);
            connect(itsLEController, &QLowEnergyController::stateChanged, this, &MainWindow::controllerStateChanged);
            connect(itsLEController, SIGNAL(error(QLowEnergyController::Error)), this, SLOT(controllerError(QLowEnergyController::Error)));
    
            ui->coControllerState->setCurrentIndex(0);
            itsLEController->connectToDevice();
    
            ui->pbConnect->setEnabled(false);
            ui->pbDisconnect->setEnabled(true);
        }
    }
    
    void MainWindow::on_pbDisconnect_clicked()
    {
        if (itsLEController != nullptr)
        {
            itsLEController->disconnectFromDevice();
    
            disconnect(itsLEController, &QLowEnergyController::stateChanged, this, &MainWindow::controllerStateChanged);
            disconnect(itsLEController, SIGNAL(error(QLowEnergyController::Error)), this, SLOT(controllerError(QLowEnergyController::Error)));
    
            itsLEController->deleteLater();
            itsLEController = nullptr;
    
            ui->pbConnect->setEnabled(true);
            ui->pbDisconnect->setEnabled(false);
        }
    }
    

    I never got an error, and controllerStateChanged is called as expected, but after I get the UnconnectedState, the device is still connected.

    Application Output:

    STATE:  QLowEnergyController::ConnectingState
    STATE:  QLowEnergyController::ConnectedState
    STATE:  QLowEnergyController::ClosingState
    STATE:  QLowEnergyController::UnconnectedState
    

    Does anybody have an idea what I am doing wrong, or what could be the cause of this behavior?

    Thanks in advance for any help!!!

    BR, Robert



  • @Robert-Veigl
    Hi Robert,

    Have you finally found any solution to this major issue ?

    I'm currently working on a very similar problem with a BlueMod S50 component (nordic/telit) without any correct solution.
    Wireshark show that the device is marked as 'coupled' when the controller (Windows drivers ?) emit packet 'Rcvd disconnect complete' to host. This event occurred, in my case, only when closing application and not when disconnectFromDevice is executed.
    I've carrefully unsubscribed from all notifications, deleted all invalidated object (services, characteristics, descriptor) with no effect.
    Furthermore the connection cannot be re-used once closed :-(

    Best regards
    Patrick



  • Hi Robert,
    I have exactly the same problem as you described. Did you manage to solve it ?
    Thank you.
    Regards


Log in to reply