Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QLowEnergyController disconnectFromDevice has no effect
Forum Updated to NodeBB v4.3 + New Features

QLowEnergyController disconnectFromDevice has no effect

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 414 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robert Veigl
    wrote on last edited by
    #1

    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

    IxtlI 1 Reply Last reply
    0
    • R Robert Veigl

      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

      IxtlI Offline
      IxtlI Offline
      Ixtl
      wrote on last edited by
      #2

      @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

      1 Reply Last reply
      0
      • SlingyS Offline
        SlingyS Offline
        Slingy
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved