This simple example uses Noble-mac (or with simple documented modification Noble) to listen to heart rate and beat-to-beat interval (aka RRI or IBI) data transimitted from any device which speaks the Bluetooth Heart Rate Service protocol. A list of such devices currently includes:
- Polar H10
- Polar H7
- Wahoo TICKR(X)
- Zephyr HxM (BT4.0 version only)
- 4iiii Viiiiva
and several others (see Notes below)
index.js
is pretty short and thoroughly commented. The code is very basic: it just finds the first bluetooth peripheral transmitting the bluetooth heart rate service and listens for and parses out the measurement data.
- Install node
- Clone this repo
- In the root directory, run
npm install
to install noble - Put on device and run
node index.js
- After a few seconds, you should see RRI data printed to the terminal
I searched for a good Python-based solution (in late 2018) and found nothing suitable. This was the best option available and plays nice with Python via the subprocess
module and pipe of stdout. (see here for some example code).
Based on node-h7-hr, which pulls HR only and uses the original noble, now dysfunctional on macOS. Took some time to figure out how the bytes were laid out for RRI, but I've documented it.
After upgrading macOS and Node versions, I had trouble getting things to work anymore. However in the end there was a relatively simple solution, using the noble-mac package instead of noble, which is more stable on macOS between versions. Those without macOS can make the simple documented changes in index.js
and package.json
to use noble instead.
If you have trouble with Node versions, unfortunately, this can be a wormwhole. However, I can recommend the node-reinstall package for both re-installing and installing first time. Also: run commands without sudo
.
I have tested with the H7 and the Tickr. This should function with other Bluetooth heart rate sensors that broadcast the Heart Rate (180d) service. This does not include Fitbit or Apple products, which are more locked-down on the data side unfortunately.
Example lists of devices this should be compatible with (mostly HR straps) can be found at EliteHRV and Sweetwater
- Bluetooth Heart Rate Measurement Spec
- Polar developer information for H7,H10 etc. (including the important information about units for RRI data!)
- If you are interested in accurate R-R interval data (for HRV, for example) be careful which devices you use. Most optical devices (e.g. wrist-worn) provide insufficiently accurate RRI data. ECG is generally a better method for this purpose. See Marco Altini's great writeup for more nuanced analysis and discussion.