Cannot read descriptor of the characteristic - BLE.
-
Hello.
I have a problem with reading characteristic using Bluetooth Low Energy Qt api. The device I'm communicating with is a Decawave DWM1001 module. I was following the tutorial from the documentation. I managed to connect to the device, read and creates it's service successfully. The device has "network node service" with UUID: 680c21d9-c946-4c1f-9c11-baa1c21329e7, which I'm trying to read characteristics from. I call QLowEnergyController::connectToDevice() method, it finds the service and I create a QLowEnergyService object for it, named nodeService.void BluetoothConnector::serviceDiscovered(const QBluetoothUuid &newService) { qDebug() << "Service discovered: " << newService.toString(); if (newService == QBluetoothUuid(nodeServiceUUID)) { nodeService = controller->createServiceObject(QBluetoothUuid(nodeServiceUUID), this); if (nodeService) { qDebug() << "Node service created"; connect(nodeService, &QLowEnergyService::stateChanged, this, &BluetoothConnector::serviceStateChanged); connect(nodeService, &QLowEnergyService::characteristicChanged, this, &BluetoothConnector::updateCharacteristic); //connect(nodeService, &QLowEnergyService::descriptorWritten, this, &BLTest::confirmedDescriptorWrite); nodeService->discoverDetails(); } else { qDebug() << "Node service not found."; } } }
nodeService is created successfully (I get "Node service created" log), then I connect the signals and slots for the service and then call discoverDetails() on nodeService. The serviceStateChanged() slot looks like this:
void BluetoothConnector::serviceStateChanged(QLowEnergyService::ServiceState newState) { if (newState == QLowEnergyService::DiscoveringServices) { qDebug() << "Discovering services"; } else if (newState == QLowEnergyService::ServiceDiscovered) { qDebug() << "Service discovered"; const QLowEnergyCharacteristic networkIdChar = nodeService->characteristic(QBluetoothUuid(networkIdUUID)); const QLowEnergyCharacteristic dataModeChar = nodeService->characteristic(QBluetoothUuid(dataModeUUID)); const QLowEnergyCharacteristic locationChar = nodeService->characteristic(QBluetoothUuid(locationUUID)); if (networkIdChar.isValid() && dataModeChar.isValid() && locationChar.isValid()) { auto idValue = networkIdChar.value(); auto modeValue = dataModeChar.value(); auto locValue = locationChar.value(); qDebug() << "Network ID: " << idValue; qDebug() << "Mode: " << modeValue; qDebug() << "Location: " << locValue; auto notificationDesc = locationChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration); if (notificationDesc.isValid()) { qDebug() << "Notification desc valid"; nodeService->writeDescriptor(notificationDesc, QByteArray::fromHex("0100")); } } else { qDebug() << "Characteristic invalid"; } } }
I get the "Discovering services" log and after that the app hangs for a bit and then I get:
"Cannot read descriptor (onDescReadFinished 3): \"{00002902-0000-1000-8000-00805f9b34fb}\" \"{3f0afd88-7770-46b0-b5e7-9fc099598964}\" \"org.freedesktop.DBus.Error.NoReply\" \"Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.\"" "LowEnergy controller disconnected" "Aborting onCharReadFinished due to disconnect"
It can't read the 00002902-0000-1000-8000-00805f9b34fb which is CCCD descriptor for the 3f0afd88-7770-46b0-b5e7-9fc099598964 characteristic (vendor specific).
Can't figure out what's wrong and why it can't read characteristics from the device. Do I need to do something else to make it work?Thanks.
-
I still can't find a workaround for this. I don't get the "ServiceDiscovered" state when discovering details of the vendor-specific service. When I call discoverDetails() on the generic service like UUID: 1801 it discovers all the characteristics and the state goes to "ServiceDiscovered". I tried everything I can think off: running app as root, setting 'cap_net_raw,cap_net_admin+eip' fot the app and setttings the environment variable BLUETOOTH_FORCE_DBUS_LE_VERSION=5.41 (mention here: [https://forum.qt.io/topic/122098/qt-bluetooth-low-energy-notification-bug-downgrade-qt/17]). I have only problem with Qt apps, the lowenergyscanner example app has the same problem. I can read and write to the ble device without a problem using gatttool or simple python app with bleak library and everything works as expected but with the Qt I can't make it work.
I hope someone had this problem before and know how to fix it.