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. Qt BLE paring(bonding) problem.
Forum Updated to NodeBB v4.3 + New Features

Qt BLE paring(bonding) problem.

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 245 Views 1 Watching
  • 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.
  • G Offline
    G Offline
    GoRo3
    wrote on last edited by
    #1

    Hi guys!

    I'm developing own device based on nrf52840 MCU. It will communicate with my desktop client written in Qt 5.15. by BLE 5.2. For now i have done all data flow from connecting and communicating with device, but I'm stuck with bonding/paring problem.
    Basically I need to bond or pair with MCU to add my client to whitelist, but by Qt side I have not found any useful (except bug reports) information how to force to pair after connecting to device. I tried to use QBluetoothLocalDevice but i'm getting all the time Paring Error.
    This is code example from class that manages connecting and retrieving service information from MCU.

    BtDeviceManager::BtDeviceManager(QObject *parent) : QObject(parent),
                                                        m_serializer(std::make_unique<FileSerializeService>()),
                                                        m_localDevice(this)
    {
        connect(&m_localDevice, &QBluetoothLocalDevice::pairingFinished, [&](const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing){
           qDebug() << "Pairing has finished with status:" << pairing << " , " << "with address: " << address;
        });
        connect(&m_localDevice, &QBluetoothLocalDevice::error, [&](QBluetoothLocalDevice::Error error){
           qDebug() << "Pairing error" << error;
        });
        connect(&m_localDevice, &QBluetoothLocalDevice::pairingDisplayPinCode, [&](const QBluetoothAddress &address, QString pin){
           qDebug() << "Pairing confirmation is for device " << address <<  "is: " << pin;
        });
        connect(&m_localDevice, &QBluetoothLocalDevice::pairingDisplayPinCode, [&](const QBluetoothAddress &address, QString pin){
           qDebug() << "Pairing pin code for device " << address <<  "is: " << pin;
        });
    
        auto device = m_serializer.deserialize();
        if (device) {
            m_device = device;
            m_device->setManager(this);
    
            connectBt();
        }
    }
    void BtDeviceManager::connectBt()
    {
        if (m_connectionController) {
            m_connectionController->disconnectFromDevice();
            delete m_connectionController;
            m_connectionController = nullptr;
        }
    
    
        m_connectionController = QLowEnergyController::createCentral(m_device->info().address(), m_localDevice.address(), this);
    
        connect(m_connectionController, &QLowEnergyController::serviceDiscovered,
                this, &BtDeviceManager::serviceDiscovered);
        connect(m_connectionController, &QLowEnergyController::discoveryFinished,
                this, &BtDeviceManager::serviceScanDone);
    
        connect(m_connectionController, static_cast<void (QLowEnergyController::*)(QLowEnergyController::Error)>(&QLowEnergyController::error),
                [&](QLowEnergyController::Error error) {
                    Q_UNUSED(error);
                    qWarning() << "Cannot connect to remote device. Error is: " << error;
                });
        connect(m_connectionController, &QLowEnergyController::connected, [&]() {
            qDebug() << "Controller connected. Search services...";
            m_connectedState = true;
            emit connectedStateChanged();
            m_connectionController->discoverServices();
        });
        connect(m_connectionController, &QLowEnergyController::disconnected, [&]() {
            qDebug() << "LowEnergy controller disconnected";
            m_connectedState = false;
            emit connectedStateChanged();
        });
    
        connect(m_connectionController, &QLowEnergyController::stateChanged, [&](auto newState){
            qDebug() << "LowEnergy controller state change to: " << newState;
        });
    
        // Connect
    
        QTimer::singleShot(10000, this, [&](){
            if(m_connectionController->state() == QLowEnergyController::ConnectingState) {
                m_connectionController->disconnectFromDevice();
                qDebug() << "Connection not handled, disconnecting";
            }
        });
    
        m_connectionController->connectToDevice();
    }
    

    I wonder is anybody have tried to make bonding or paring using Qt framework?

    Best Regards!
    GoRo3

    1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher referenced this topic on

    • Login

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