Search code examples
python-3.xbluetooth-lowenergyraspberry-pi3gatt

Getting Data from PolarH10 via BLE


I have been trying to get data from my PolarH10 with my raspberry-pi. I have been successfully getting data through the commandline with bluez, but have been unable to reproduce that in python. I am using pygatt(gatttool bindings) and python3.

I have been closely following the examples provided on bitbucket and was able to detect my device and filter out it's MAC address by filtering it by name. I however was unable to get either of the "reading data asyncronously" examples to work.


#This doesnt work...
req = gattlib.GATTRequester(mymac)
response = gattlib.GATTResponse()

req.read_by_handle_async(0x15, response) # what does the 0x15 mean?
while not response.received():
    time.sleep(0.1)

steps = response.received()[0]


...

#This doesn't work either
class NotifyYourName(gattlib.GATTResponse):
    def on_response(self, data):
        print("your data is: {}".format(data))

response = NotifyYourName()
req = gattlib.GATTRequester(mymac)
req.read_by_handle_async(0x15, response)

while True:
    # here, do other interesting things
    time.sleep(1)

I don't know and cannot extract from the "documentation(s)" how to subscribe to/read notifications from a characteristic(heart rate) of my sensor(PolarH10). The error I am getting is when calling GATTRequester.connect(True) is

RuntimeError: Channel or attrib not ready.

Please tell me how correctly connect to a BLE device via Python on Debian and how to programatically identify offered services and their characteristics and how to get their notifications asyncronously in python using gattlib(pygatt) or any other library. Thanks!


Solution

  • The answer is: Just use bleak.