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

Peripheral connect with Windows BLE



  • 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



  • Any idea team ??


  • Moderators

    @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?



  • @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


  • Moderators

    @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?



  • @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



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

    qt.bluetooth.winrt: Could not await services operation
    
    

Log in to reply