Tutorial
Adrian
2023:11
Polar H10 is a precise heart rate sensor that uses electrodes attached to your chest to produce an electrocardiogram (ECG). The main advantage of performing an ECG is that it measures the heart activity much more accurately and reliably compared to other technologies, such as Optical Heart Rate sensors. When it comes to reading heart rate in real-time for your project or application, you have multiple options on how to achieve this. Polar provides its own SDK to develop Android and iOS applications for the Polar H10. Also, Since Polar H10 uses wireless Bluetooth Low Energy technology (BLE), you can even develop your script to read the heart rate readings directly from the sensor. In this guide, I will explain some of the existing options for reading the heart rate in real time. The described solutions use the MQTT protocol to publish sensor readings which can be read with an MQTT client. The idea is that MQTT provides a universal interface to read the heart rate for your project:
To publish HR readings from your phone using MQTT:
To publish HR readings with a Python script:
Firstly, you have to install and run the Mosquitto MQTT broker. After, you can publish the heart rate to the local Mosquitto broker through either an MQTT client with the Polar Sensor Logger App (on your Android phone) or through a Python script on your PC. Note: Technically, you can use a 3rd party MQTT broker to publish the heart rate readings to (instead of using Mosquitto locally). If you choose to do so, you can skip the Mosquitto Setup Part
1. Install Mosquitto MQTT broker
2. Add a new Firewall rule to allow TCP port 1883 for new MQTT Client connections:
New-NetFirewallRule -DisplayName "Allow TCP Port 1883" -Direction inbound -Profile Any -Action Allow -LocalPort 1883 -Protocol TCP
Note: In practice, Windows should ask you to allow network communication for mosquitto.exe via a Windows Security Alert Prompt. If you give Mosquitto permission through this prompt, step 2 can be skipped
3. Edit the Mosquitto config file to allow external connections:
allow_anonymous true listener 1883
4. Run Mosquitto using the config file:
mosquitto -c mosquitto.conf -v
If everything goes well you should be seeing the logs in cmd confirming that the Mosquitto broker is running on port 1883:
Mount the Polar H10 sensor on the chest strap and wear it. Follow these steps on your Android device:
ipconfig
, or go to https://whatismyipaddress.com/1883
polar_h10
polar_h10_realtime
OK
OK
With Polar Sensor Logger main tab entry “SDK data select” option ECG activated, PSL publishes two topics:
python -m venv venv venv\Scripts\activate pip install -r requirements.txt
Run:
python polar_h10_mqtt.py
Polar Sensor Logger
Create and activate venv
All libraries installed
Log of Python script
https://github.com/utwente-interaction-lab/Polar-H10-mqtt
—