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. Peripheral connect with Windows BLE
Forum Updated to NodeBB v4.3 + New Features

Peripheral connect with Windows BLE

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 993 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.
  • martial123M Offline
    martial123M Offline
    martial123
    wrote on last edited by
    #1

    Hi everyone,

    I have make a little application to connect my computer (laptop Windows with intern BLE) with a peripheral device in BLE.

    I am able to detect this device.
    After that, I create a central role and pass as arguments my device peripheral detected.
    And after that i launch connection with :

    void QLowEnergyController::connectToDevice()
    
    

    and i wait my connect active :

    &QLowEnergyController::connected
    

    but in fact, nothing is happening.
    If I look on my icon BLE on windows 10 (manage notification tab) I see my BLE icon switch between connected(1) / not connected...

    So I understand there is something wrong.
    My peripheral device need code (password 123456) to pair before connect on it service.
    I thinks this is the problem .. but on Qt ,
    I did not see any connection function where you could pass the password.

    Is there such a function?

    Thanks.
    Martial

    1 Reply Last reply
    0
    • martial123M Offline
      martial123M Offline
      martial123
      wrote on last edited by
      #2

      Any idea team ??

      J.HilkJ 1 Reply Last reply
      0
      • martial123M martial123

        Any idea team ??

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @martial123 Is the password required before or after the service discover ?

        If it's after the discovery, you could potentially the writeDescriptor function to transfer data. I use it to subscribe to the service.

        Is this what you mean?


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        martial123M 1 Reply Last reply
        1
        • J.HilkJ J.Hilk

          @martial123 Is the password required before or after the service discover ?

          If it's after the discovery, you could potentially the writeDescriptor function to transfer data. I use it to subscribe to the service.

          Is this what you mean?

          martial123M Offline
          martial123M Offline
          martial123
          wrote on last edited by
          #4

          @J-Hilk
          Hi ! , unfortunatly, this is before discover services, here my code to better understand ( inspire from example of Qt heart game ):

              m_deviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
              connect(m_deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &MainWindow::addDevice);
          
          void MainWindow::on_m_scanBLEButton_clicked()
          {
              qDebug()<< " we are in scan ble button "<<endl;
              //m_deviceDiscoveryAgent->setLowEnergyDiscoveryTimeout(5000);
              m_deviceDiscoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
          }
          // I push on scan button, this slot start(just above) and the connect are true when agent discover low energy device. when we have this, we jump in slot addDevice:
          
          void MainWindow::addDevice(const QBluetoothDeviceInfo &device)
          {
              // If device is LowEnergy-device, add it to the list
              if (device.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration)
              {
                  if(device.name() == "CERTIF") // I filter because i just want to add my device named CERTIF.
                  {
                      ui->m_deviceAvailableTextBox->append(device.name());
                      ui->m_deviceAvailableTextBox->append(device.address().toString()); //append my device CERTIF and his mac address
                      m_control = QLowEnergyController::createCentral(device, this); //here I creat a central (my pc ) with this device (CERTIF)
                      m_control->setRemoteAddressType(QLowEnergyController::RandomAddress);
                      //or
                      //m_control->setRemoteAddressType(QLowEnergyController::PublicAddress);
                  }
              }
          }
          
          //so after that, I see on my TextBox (m_deviceAvailableTextBox) CERTIF and his adress.
          //Now I click on an other Pushbutton : 
          
          void MainWindow::on_m_connectBLEButton_clicked()
          {
              qDebug()<< " we are in connect ble button "<<endl;
              m_control->connectToDevice(); //main point were FAILLED.
          }
          // slot in case or we are connect or error appears: 
          
              connect(m_control, QOverload<QLowEnergyController::Error>::of(&QLowEnergyController::error),[this](QLowEnergyController::Error error)
              {
                  qDebug()<< "cannot be connect to the controller "<<error<<endl;
                  ui->m_deviceAvailableTextBox->append("cannot be connect to the controller...");
              });
          
              connect(m_control, &QLowEnergyController::connected,[this]()
              {
                  qDebug()<< "we are in connect controller "<<endl;
                  ui->m_deviceAvailableTextBox->append("Controller connected. Search services...");
                  //m_control->discoverServices();
              });
          
          

          the point is, none of the slots are triggered, connected no and Error no, I have just my app runing ,and if i check my tab on my laptop On bluetooth icon I see my BLE icon switch between connected(1) / not connect.

          What i know, with nRF connect software and dongle nRF, I am able to connect with my device CERTIF because after scan, i try to pair (connect) with this and nRF software open window were i can write down my password (123456) and just after that, I am connected and i can connect to a service ..

          In Qt I am bloqued just before ..
          I hope this is more clear..

          Thanks

          J.HilkJ 1 Reply Last reply
          0
          • martial123M martial123

            @J-Hilk
            Hi ! , unfortunatly, this is before discover services, here my code to better understand ( inspire from example of Qt heart game ):

                m_deviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
                connect(m_deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &MainWindow::addDevice);
            
            void MainWindow::on_m_scanBLEButton_clicked()
            {
                qDebug()<< " we are in scan ble button "<<endl;
                //m_deviceDiscoveryAgent->setLowEnergyDiscoveryTimeout(5000);
                m_deviceDiscoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
            }
            // I push on scan button, this slot start(just above) and the connect are true when agent discover low energy device. when we have this, we jump in slot addDevice:
            
            void MainWindow::addDevice(const QBluetoothDeviceInfo &device)
            {
                // If device is LowEnergy-device, add it to the list
                if (device.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration)
                {
                    if(device.name() == "CERTIF") // I filter because i just want to add my device named CERTIF.
                    {
                        ui->m_deviceAvailableTextBox->append(device.name());
                        ui->m_deviceAvailableTextBox->append(device.address().toString()); //append my device CERTIF and his mac address
                        m_control = QLowEnergyController::createCentral(device, this); //here I creat a central (my pc ) with this device (CERTIF)
                        m_control->setRemoteAddressType(QLowEnergyController::RandomAddress);
                        //or
                        //m_control->setRemoteAddressType(QLowEnergyController::PublicAddress);
                    }
                }
            }
            
            //so after that, I see on my TextBox (m_deviceAvailableTextBox) CERTIF and his adress.
            //Now I click on an other Pushbutton : 
            
            void MainWindow::on_m_connectBLEButton_clicked()
            {
                qDebug()<< " we are in connect ble button "<<endl;
                m_control->connectToDevice(); //main point were FAILLED.
            }
            // slot in case or we are connect or error appears: 
            
                connect(m_control, QOverload<QLowEnergyController::Error>::of(&QLowEnergyController::error),[this](QLowEnergyController::Error error)
                {
                    qDebug()<< "cannot be connect to the controller "<<error<<endl;
                    ui->m_deviceAvailableTextBox->append("cannot be connect to the controller...");
                });
            
                connect(m_control, &QLowEnergyController::connected,[this]()
                {
                    qDebug()<< "we are in connect controller "<<endl;
                    ui->m_deviceAvailableTextBox->append("Controller connected. Search services...");
                    //m_control->discoverServices();
                });
            
            

            the point is, none of the slots are triggered, connected no and Error no, I have just my app runing ,and if i check my tab on my laptop On bluetooth icon I see my BLE icon switch between connected(1) / not connect.

            What i know, with nRF connect software and dongle nRF, I am able to connect with my device CERTIF because after scan, i try to pair (connect) with this and nRF software open window were i can write down my password (123456) and just after that, I am connected and i can connect to a service ..

            In Qt I am bloqued just before ..
            I hope this is more clear..

            Thanks

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @martial123
            well, this seems more like an BLE issue than Qt.

            The windows api is still, meh
            can you pair/connect to it from the windows settings directly ? before trying it with qt?


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            martial123M 1 Reply Last reply
            1
            • J.HilkJ J.Hilk

              @martial123
              well, this seems more like an BLE issue than Qt.

              The windows api is still, meh
              can you pair/connect to it from the windows settings directly ? before trying it with qt?

              martial123M Offline
              martial123M Offline
              martial123
              wrote on last edited by martial123
              #6

              @J-Hilk
              Good Question, I have try, but not succeed . i click on add device bluetooth, i detect him, i click on him and i receive this just below CERTIF : try connecting your device again .
              I have check on my device manager and my laptop have puce with BLE :

              Capture.PNG

              Edit:
              I will try to remove this password in my firmware device, for check if error come from here . but your right, propably it is Window error and not Qt. But still, this is strange that not have any function to pass password to connect ...

              if I managed to connect with my dongle, the problem would be quickly resolved.. see my other topic:
              https://forum.qt.io/topic/113213/nrf-connect-dongle-with-qt-for-windows

              1 Reply Last reply
              0
              • martial123M Offline
                martial123M Offline
                martial123
                wrote on last edited by
                #7

                ooh, and I have this log in my Qt app after long time to connect :

                qt.bluetooth.winrt: Could not await services operation
                
                
                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