Bluetooth Low Energy: Reading Sensor data in real time after retrieving characteristics
-
Hello everyone,
I am developing a desktop application for reading and plotting sensor datan from an Adafruit Feather M0 Bluefruit LE developing board. This board does have a UART Service with 2 characteristics: the TX (0x0002) is used to send data back to the sensor node and the RX (0x0003) is used to send data out to the connected Central device (my Laptop).
So after connecting and creating serviceobject for the UART Service, I am able to retrieve the characteristics with
QList<QLowEnergyCharacteristic> chars = service->characteristics();
and when calling the UUIDS for the chars the UUIDS for the above mentioned characteristics TX and RX are shown, that's fine.
So How can I now get the Value of the Characteristic RX (for reading the data) and how can I update this call, so that the data are send in realtime?
When I call for both charactersqDebug () << char.value();
the output for both is
"" ""
So empty, but the value for the RX characteristic should be a sensor value..
Thanks for the help!
-
@TUStudi said in Bluetooth Low Energy: Reading Sensor data in real time after retrieving characteristics:
So How can I now get the Value of the Characteristic RX
It seems (I have not used Qt Bluetooth), the characteristicChanged() signal is responsible for that.
Regard
-
Thank you for your reply. I found this in the documentation:
In 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:
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"));
So you were right. But what I do not understand: The writeDescriptor function "Writes newValue as value for descriptor." But what "value" is the
QByteArray::fromHex("0100")
? Because when i write the same code for my application and when I callvalue()
on the ClientCharacteristicConfiguration Descriptor from my RX characteristic the output is\x00\x00