I am developing a program to read some characteristics from a smart watch (heart rate, battery level, humidity and temperature).
To doing this, I am following the heart rate game example. From this example I am able to get notifications about heart rate from a simulator on my smartphone, but for the other parameters I am not able to get the values.
For example, for heart rate I'm doing this for stateChanged: (connect(m_service, &QLowEnergyService::stateChanged, this, &DeviceHandler::serviceStateChanged);
)
if (uuid == QBluetoothUuid(QBluetoothUuid::HeartRate)) {
const QLowEnergyCharacteristic hrChar = m_service->characteristic(QBluetoothUuid(QBluetoothUuid::HeartRateMeasurement));
m_notificationDesc = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
m_service->writeDescriptor(m_notificationDesc, QByteArray::fromHex("0100"));
And this for updateValue: (connect(m_service, &QLowEnergyService::characteristicChanged, this, &DeviceHandler::updateValue);
)
auto data = reinterpret_cast<const quint8 *>(value.constData());
quint8 flags = *data;
if (flags & 0x1) // HR 16 bit? otherwise 8 bit
hrvalue = static_cast<int>(qFromLittleEndian<quint16>(data[1]));
else
hrvalue = static_cast<int>(data[1]);
qCDebug(BLELog) << hrvalue;
If i run my program, it finds the device and connect to it and I get correctly the new heart rate value everytime I push "notify" button on the simulator.
For the other services I don't have the equivalent of HeartRateMeasurment. For the battery I tried to use BatteryService and then BatteryLevel as characteristic but my program does not read the values while standing still (but not blocked). Which services and characteristics should I use to get the same result I get with heart rate? Thank you very much for all the help.