Unsolved Qt BLE paring(bonding) problem.
-
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 -