Interaction-lab-eemcs@utwente.nl

Polar H10: Real-time Heart Rate Monitoring

Version/Date:

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:

  1. Publish HR readings with the “Polar Sensor Logger” Android app
  2. Publish HR readings with a Python script
  • Hardware:
    • Polar H10 sensor and strap
  • Software:
    • Mosquitto

To publish HR readings from your phone using MQTT:

  • Hardware:
    • Android Phone (with USB cable)
  • Software:
    • Polar Sensor Logger
    • Android Debug Bridge (ADB)

To publish HR readings with a Python script:

  • Hardware:
    • Computer with Bluetooth Low Energy (BLE) capability
  • Software:
    • Python 3.4+ (should come with PIP)

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

Setup Mosquitto MQTT Broker

Installation

1. Install Mosquitto MQTT broker

2. Add a new Firewall rule to allow TCP port 1883 for new MQTT Client connections:

  1. Open PowerShell in administrator mode
  2. Run in PowerShell:
    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:

  1. Go to Mosquitto's installation directory
  2. Edit mosquitto.conf file with a text editor → insert:
    allow_anonymous true
    listener 1883
Usage

4. Run Mosquitto using the config file:

  1. Open cmd in Mosquitto's installation directory
  2. Run in cmd:
    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:

Polar Sensor Logger (Android App)

Mount the Polar H10 sensor on the chest strap and wear it. Follow these steps on your Android device:

  1. Activate Bluetooth and Location Service
  2. Launch the “Polar Sensor Logger” App, in the main tab configure:
    1. “SDK data select:” check ECG only
    2. “Settings:” check MQTT only
    3. In the pop-up “MQTT-settings” configure:
      1. MQTT-broker address → Insert the IPv4 of the PC on which the Mosquitto broker is running. To find it, run in cmd: ipconfig, or go to https://whatismyipaddress.com/
      2. Port: 1883
      3. Topic: polar_h10
      4. Client ID: polar_h10_realtime
    4. Tap OK
  3. Tap SEEK SENSOR
    1. Select listed sensor Polar H10 <ID>
    2. Tap OK

With Polar Sensor Logger main tab entry “SDK data select” option ECG activated, PSL publishes two topics:

  • Topic psl/ecg (cp. listing 2.6.): delivers a JSON-Object as payload containing, among others
    • a JSON-Field named “ecg”: [ … ], a JSON-Array of ECG values in microvolts [uV]
  • Topic psl/hr (cp. listing 2.7.): delivers a JSON-Object as payload containing, among others
    • a JSON-Field “hr”: 64 containing a JSON-Integer which corresponds to the heart rate in beats per minute (bpm)
    • a JSON-Field “rr”: [ 938 ] containing a JSON-Array of RR intervals in milliseconds [ms]

Python Script

Installation
  1. Download the project files from our GitHub repository
  2. Go to the project's location
  3. Run in cmd:
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
Usage

Run:

python polar_h10_mqtt.py


Polar Sensor Logger


Create and activate venv


All libraries installed


Log of Python script

Interaction Lab