need help to used window10 qt version 5.14.2 qbleutooth characteristicChanged Slot is not running,
-
hi guys,i copy this example to my project,write m_service->writeDescriptor(m_notificationDesc, QByteArray::fromHex("0100")); is ok,
devices can received.but device notify data is not can trigger characteristicChanged Slot, Hope that the big guys help to answer.Thank youIn some cases the peripheral generates value updates which the central is interested in receiving. In order for a characteristic to support such notifications it must have the QLowEnergyCharacteristic::Notify or QLowEnergyCharacteristic::Indicate property and a descriptor of type QBluetoothUuid::ClientCharacteristicConfiguration. Provided those conditions are fulfilled notifications can be enabled as shown in the following code segment:
//PreCondition: service details already discovered QLowEnergyCharacteristic batteryLevel = service->characteristic( QBluetoothUuid::BatteryLevel); if (!batteryLevel.isValid()) return; QLowEnergyDescriptor notification = batteryLevel.descriptor( QBluetoothUuid::ClientCharacteristicConfiguration); if (!notification.isValid()) return; // establish hook into notifications connect(service, SIGNAL(characteristicChanged(QLowEnergyCharacteristic,QByteArray)), this, SLOT(characteristicChanged(QLowEnergyCharacteristic,QByteArray))); // enable notification service->writeDescriptor(notification, QByteArray::fromHex("0100")); // disable notification //service->writeDescriptor(notification, QByteArray::fromHex("0000")); // wait until descriptorWritten() signal is emitted // to confirm successful writeThe example shows a battery level characteristic which updates the central on every value change. The notifications are provided via the characteristicChanged() signal. More details about this mechanism are provided by the Bluetooth Specification.
-
Hi @qixin, your code looks right to me, assuming the device you're talking to does indeed support BLE Notify for that characteristic.
Two things I would try. First, update your
connectto use the newer syntax, like:connect(service, &QLowEnergyService::characteristicChanged, this, &YourClassName::characteristicChanged);This will just allow the compiler to catch any argument errors you might have there (though Qt should be logging an warning at runtime, if that was the problem).
(BTW, you can make that connection as soon as
serviceis constructed if you like, so you don't miss the firstcharacteristicChangedevent ;)Then, enable the QtBluetooth Logging Categories; something like this:
QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));That might give you some hints to why its not working.
Cheers.
PS. Are you able / willing to tell us what device you're talking to? It might be helpful.
-
Hi @qixin, your code looks right to me, assuming the device you're talking to does indeed support BLE Notify for that characteristic.
Two things I would try. First, update your
connectto use the newer syntax, like:connect(service, &QLowEnergyService::characteristicChanged, this, &YourClassName::characteristicChanged);This will just allow the compiler to catch any argument errors you might have there (though Qt should be logging an warning at runtime, if that was the problem).
(BTW, you can make that connection as soon as
serviceis constructed if you like, so you don't miss the firstcharacteristicChangedevent ;)Then, enable the QtBluetooth Logging Categories; something like this:
QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true"));That might give you some hints to why its not working.
Cheers.
PS. Are you able / willing to tell us what device you're talking to? It might be helpful.
hi it connected ble5.0 micro chip.thanks you very much! i used QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); can privide some information to find bug. now it can be used。
but i find new problem used void QLowEnergyController::connectionUpdated(const QLowEnergyConnectionParameters &newParameters) it can not running slot,seem not find information can solution. can you please some advice? thanks