PDA

View Full Version : Regarding Bluetooth Low energy Heart Listener example



user03
18th August 2016, 18:11
I am a novice in QT programming and require some help to modify the heart listener BLE code (http://doc.qt.io/qt-5/qtbluetooth-heartlistener-example.html).
Basically, my task is to connect to a specific BLE device (I would like to select the device at the back-end, unlike the way it is presented in the example). After establishing the connection, I want to do the exact same thing which is presented in the code, i.e. filter the heart rate service and capture the heart rate measurement characteristic.
Could anyone please suggest if it is possible to have a UI to display only the plot of the data that is received through the heart rate characteristic and perform all the other operations, i.e. connecting to the device, filtering the required service and the specific characteristic from the device back-end.

Also, I tried (and still trying) reading & understanding the code but it is very difficult to understand the part that is for display.

Thank You.

System Info: Ubuntu 14.01, Bluez 4.101

anda_skoa
19th August 2016, 11:16
Hmm, I am not sure I understand what you are referring to as the "backend".

As far as I can tell all BT operations are done in the non-UI parts of the application, which is what I assumed you mean with backend.

Cheers,
_

user03
20th August 2016, 20:01
Thanks for the reply. I understood the code and made some modifications, however, now I am unable to understand that how can I plot the data in real-time. The heart rate listener example provided on the website plots the graph after the measurements are stored in a list. However, I would like to plot the data in real-time and I have used QWT previously for this purpose but I am not sure if I can use qml and qwt both. Could you provide some suggestion as to how can this be achieved. Thanks.

anda_skoa
21st August 2016, 12:21
I don't know whether QWT has QtQuick components as well, better ask in the QWT sub forum.
My guess would be that it does, both QPainter and OpenGL are available in QtWidgets and QtQuick.

Otherwise you could check using the Qt Chart module, http://doc.qt.io/qt-5/qml-qtcharts-chartview.html

Cheers,
_

user03
21st August 2016, 18:56
I am going to use QtCustomPlot for the same, however, I had a small query (would apologise if this sounds simple and irrelevant to most of the users, however, I'm using Qt for the first time and have been struggling since quite a few days to figure out things)
So below is the query: I tried executing below mentioned function (picked up from the heartrate.cpp file)
void ADCReader::updateHeartRateValue(const QLowEnergyCharacteristic &c,
const QByteArray &value)
{
// ignore any other characteristic change -> shouldn't really happen though
if (c.uuid() != QBluetoothUuid(QBluetoothUuid::HeartRateMeasuremen t))
return;
const quint8 *data = reinterpret_cast<const quint8 *>(value.constData());
quint8 flags = data[0];
}

And on passing the numbers from 90 to 110, got the output as mentioned below:
value,16
value,144
value,145
value,146
value,147
value,148
value,149
value,150
value,151
value,152
value,153
value,16
value,16
value,16
value,16
value,16
value,16
value,16
value,16
value,16
value,16.

I think it is little endian format, but I am not sure about the series of 16 displayed in the output. Would be really helpful if someone would be able to explain the reason for getting this type of output.

EDIT: I got the output after inserting
QString s = value.toHex();

anda_skoa
21st August 2016, 21:49
Not sure what you are asking.

You get series of values and print the first byte.

Also not sure why you mentioned little endian, a one byte int doesn't have any endianess differences, only multi-byte integers do.

Cheers,
_

user03
22nd August 2016, 18:09
I don't know whether QWT has QtQuick components as well, better ask in the QWT sub forum.
My guess would be that it does, both QPainter and OpenGL are available in QtWidgets and QtQuick.

Otherwise you could check using the Qt Chart module, http://doc.qt.io/qt-5/qml-qtcharts-chartview.html

Cheers,
_

I checked Qt Chart module and found an example to plot the data (oscilloscope example), however, when i tried running the code on Qt Creator (5.5.1), I got error that Qt Chart not found, could you pls let me know if I need to install this separately, if yes, then how can I install it from the Qt Creator (or do i need to do that from the terminal). Thanks

anda_skoa
22nd August 2016, 18:35
As far as I know there is no QtCreator version 5.5.1 but it would not matter.
Your Qt version, however, needs to be 5.6.0 or higher for the open source licensed Qt Chart, or, in case you are using a commerical license, I think downloaded separately.

Cheers,
_