I am looking to create a simple python script that reads heart rate data from a Polar sensor over Bluetooth. I have read through a lot of other posts and cannot find something simple that I am able to successfully execute.
I have the device MAC address for the Polar wearable. I know the service UUID for the value I want to read (0x180D for HR). I don't care much about which library or service I use, but I cannot seem to get this to work.
I am able to have my script successfully recognize the Polar sensor, however, I cannot figure out how to read the value from this. I have downloaded a Bluetooth Scanner app for my phone which is able to successfully connect and read the value, so I know it should be easy to do and cannot figure out how to write this up.
Any help would be tremendously appreciated.
Although the code example from @ukBaz is useful and will accidentally show the correct broadcast HR in some cases, the part that unpacks the 5 bit flags is completely wrong (in wrong bit order and shifted by 3 bits). I discovered the problem when I was also trying to decode the other data such as R-R intervals and its flag was always wrong.
To correct the flags, change the bitstruct.unpack() lines as I've done below. The corrected code then is: