Reputation: 1
I'm working on a Bluetooth Low Energy medical device and I used the bleak library to connect to the device and read or set data on it.
So far I've been able to connect to it and read data from characteristics with the notify "function"/possibility such as the heart measurement characteristic.
Two issues arose from this.
First one is that I'm unable to find the readable/human value. For the Heart Rate I read those type of bytes :
b'\x11G\x00s\x03w\x03' or b'\x11F\x00u\x03' or b'\x11H\x00\x0b\x03\xed\x02' and I would like to read 69 for 69 BPM for example.
Now I have looked at this thread BLE Heart Rate Senser Value Interpretation and others (Analyze data return from heart rate monitor) to be able to convert. I know this is linked to the Bluetooth SIG but I've seen nowhere bytes like the ones I show and I can't seem to convert properly to a BPM. Did anyone work with similar received data and know how to read it properly ?
Now for my second question (but this is more of a confirmation seeing this thread Bluetooth LE listen to multiple characteristic notifications), I use this code part taken from Bleak's github :
await client.start_notify(CHARACTERISTIC_UUID, notification_handler)
await asyncio.sleep(15.0)
await client.stop_notify(CHARACTERISTIC_UUID)
which enables notifications from one characteristic. Would it be possible to use this for two characteristics simultaneously ? Or rather from what I understood from the thread, can you enable notifications for two characteristics say heart rate measurements and temperature measurements but one after the other ?
I tried to put in this post some of the threads I read and tried to understand, hopefully I didn't miss some post where the answer about the conversion for this type of byte would be explained.
Upvotes: 0
Views: 586
Reputation: 23
For anyone else who lands here and has a device running InfiniTime (ie. PineTime), you can use the struct
module to unpack the data.
import struct
struct.unpack(">H", data)
>
is used because the PineTime's byte order is big-endianH
indicates an unsigned short, because InfiniTime stores the heart rate reading as an unsigned 16 bit integerIf your heart rate device is different, look through it's source code and try to determine the data type, then find the corresponding letter in the struct module's documentation: https://docs.python.org/3/library/struct.html#format-characters
Upvotes: 1