In the preparations for getting my first smart phone, mainly to use it as a heart rate monitor and GPS for my workouts, I opted for buying a bluetooth heart rate chest strap. Until I’ll get new phone, I want to connect the chest strap to my laptop, for logging heart rate when exercising at home.
Searching the net for Linux HRM (heart rate monitor) implementation, I have found an interesting post Listening to a Polar Bluetooth HRM in Linux. The author wrote a Ruby script that listens to the Polar bluetooth device. So I opted to buy the chest strap he uses in the blog post - Polar WearLink+ transmitter with Bluetooth. Pay attention this is not the Polar H7 which is the newer and support Bluetooth 4.0, but have a lot of issues connecting to android devices. I paid 80$ include shipping to Israel.
After getting the Polar strap, I notice problem connecting the device. Searching Google, I found that there are issues with the battery, that drains too fast. Here is the thread about this problem. I took the battery out, and tried to replace it with other batteries, but nothing. My computer couldn’t find the device. Next day I tried again, and replaced the battery again to the original. Then by magic, the computer did found the device. I don’t know how or why this happened, but I’ll keep track of the battery life and post back.
My heart rate on the screen ;-)
In his blog post Daniel created a small program that listen to the
heart rate belt, then prints the data to the screen. Here is a sample output of
the program, and the column
:hr=> shows my heart rate:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Few steps to get it working
Compile kernel Bluetooth drivers
Networking support -> Bluetooth subsystem support (NEW) I just marked
everything as module. After you understand what driver you need, you can unmark
the drivers that are not needed by your system. This procedure is for
Gentoo users, or people that use custom kernels. For other OSs Bluetooth is
usually provided with the standard kernel.
You will need to install bluez for handling the Bluetooth service:
emerge -av net-wireless/bluez
Next, if you have Broadcom BCM203x and STLC2300 Bluetooth chips, you should install their firmware:
emerge -av net-wireless/bluez-firmware
For debugging the connection you can use hcidump similar to tcpdump:
emerge -av net-wireless/bluez-hcidump
And last, but very important for providing PIN to the Bluetooth device:
emerge -av net-wireless/blueman
I have an Lenovo X201 laptop, so I enable and disable the Bluetooth with this command:
echo enable > /proc/acpi/ibm/bluetooth echo disable > /proc/acpi/ibm/bluetooth
If you don’t have a Thikpad, this method will not work, as this command relays on thinkpad.ko kernel module. Please Google to find out how to enable Bluetooth on your setup.
Now start the bluez service:
Search the Polar device
In order to search the chest strap, you will need to run:
and the output should look similar to this:
Scanning ... 00:22:D0:00:95:31 Polar iWL
The mac address is important, as you need to supply it as a parameter to polar.rb.
I found that my laptop will not find the Polar device on the first scan, so I ran the following command to scan few times:
while true ; do hcitool scan ; sleep 1 ; done
It took a while, but it finds the Polar device eventually.
Pairing laptop with Polar strap
Ok, I must admit, this was quit challenging. I didn’t install the bluman package at first, and saw that running
ruby polar.rb 00:22:D0:00:95:31
result with connection refused. Using hcidump, I saw that the Bluetooth on the chest strap is aborting the connection due to lack of PIN code. The manual states that the PIN is 0000 (4 times zero), so I searched for a way to add this to the program. It wasn’t straight forward task, so I read again Daniel’s post and noticed that he uses the blueman package. I installed it. Then ran the command:
Hit the Search button and it should find the Polar device, then hit the Pair button to allow the device to request the PIN. This provided the initial pairing of the device with the laptop.
After this procedure, I was able to run the
polar.rb using the command:
ruby polar.rb 00:22:D0:00:95:31
and my heart rate beats started appearing on the laptop screen.