Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1335

Python • BLE connection Raspi 4 to Polar H10 chest belt via Python-script

$
0
0
Hi,

I'm trying what I would consider to be a simple task but I don't succeed so far. The only thing I want to do is to connect a sensor via Bluetooth to the Raspberry 4B and read out it's data. In my case it's a Polar H10 chest belt.

Even the straight forward example from Chat-GPT is not working. Is it that hard and buggy connecting a BLE device with Python to a Raspi 4 or am I just incompetent? Are there any libraries which are recommended to use?

Code:

from bluepy import btle# Die MAC-Adresse des Polar H10 eingebendevice_mac = "xx:xx:xx:xx:xx:xx"# Verbindung zum Gerät herstellendev = btle.Peripheral(device_mac)# Ein bestimmtes Service- oder Characteristic-UUID angeben# Um z.B. den Herzfrequenz-Characteristic zu lesenheart_rate_service = dev.getServiceByUUID("180D")heart_rate_char = heart_rate_service.getCharacteristics("2A37")[0]while True:    # Herzfrequenzdaten lesen    hr_data = heart_rate_char.read()    print(hr_data)
Using this example I get an Error "bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral xx, addr type: public" at the line "dev = btle.Peripheral(device_mac)". However, using "hcitool lescan" I can find the chest belt.

So, if using BLE with Raspi is in principle a buggy or complicated thing, I would prefer using Matlab or something instead. If I'm simply just a bit incompetent, I would love if you can give me some help.

Thanks,
Markus

Statistics: Posted by M_a-r_k-u_s — Sat Aug 24, 2024 11:07 am



Viewing all articles
Browse latest Browse all 1335

Trending Articles