Back in May, I posted about ordering an Angel Sensor M1. I did have some success tinkering with it, but I never got around to posting my results. After being asked about it a few times, I figured I should get it up on the blog.

The device manufacturer supplies some experimental Python code on github for interacting with the device from a special USB Bluetooth-LE dongle that I don’t have. But I found an easier way of talking to it, at least for those of us on Linux. There is a command-line tool called gatttool that allows you to talk directly with Bluetooth devices that use the Generic Attribute Profile from the command-line without doing any programming at all. Please make sure you have installed the bluez package to get what you need to follow the instructions below. (‘sudo apt-get install bluez‘ on Ubuntu.)

First, you should run:

hcitool -a

to make sure that your Bluetooth device is up and running. In my case, I am using hci0, but you can change this to another device in the commands below. On the 3rd line, it should say something like “UP RUNNING PSCAN”. If it doesn’t say “UP”, then you should run:

sudo hciconfig hci0 up
hciconfig -a

and make sure that hci0 is up now.

Now we are going to scan for all Bluetooth-LE devices:

sudo hcitool lescan

In the output, you should see the MAC address of your Angel Sensor. If not, press the button on the Angel Sensor to turn on Bluetooth and try again.

Now let’s set up a variable to contain your MAC address. (I’m assuming you are using bash… if not, then adjust accordingly.)

mac=xx:xx:xx:xx:xx:xx

(Replace the xx’s with the correct values for your device.)

Finally, we get to try to connect to the device:

sudo gatttool -t random -b $mac -I

You should now see a prompt. But you aren’t connected. In order to connect, just type:

connect

at the prompt.

It might be worth mentioning here that I got this far by reading around on the net. The most useful page I found was here:
http://www.jaredwolff.com/blog/get-started-with-bluetooth-low-energy/

He writes more about how to use these tools. I’m partially following his examples but adapted to the Angel Sensor M1.

It is also worth noting that I started out trying to use a typical Bluetooth-LE compliant USB dongle at first, and it had some errors connecting. On a whim, I tried using my laptop’s internal Bluetooth and everything just worked. So if you see any strange problems up to this point, you might just try a different Bluetooth adaptor. Assuming nothing went wrong for you up to this point, we are now connected to the device over Bluetooth.

So we start by getting the primary UUID’s of the device. At the prompt, run:

primary

Then we can get all available handles:

char-desc

I’m not expert enough in Bluetooth to fully explain what the meaning of this stuff is, so you might want to do some reading up on this if you are interested. In my case, I tinkered around and found some success with the following for requesting heartrate notifications:

char-write-req 0x15 01

In GATT, you can request a value, or you can request notifications whenever a value becomes available via the Client Characteristic Configuration Descriptor (CCCD). The CCCD for heartrate notifications is 0x15, and the value 1 says “send me notifications”.

Once you’ve set-up your device to measure heartrate (this may involve long pressing the button on the device until the blue LED on the back side against your skin turns on), you should see that the second byte of the response string is the heartrate in beats per minute. If you don’t get responses, my recommendation is to use the Google Play app on your phone and make sure you are getting heartrate measurements, and then come back to the Linux command-line and repeat the above steps to get these notifications. I kept fidgeting with it because it wasn’t giving me anything until I realized that it takes 10-15 seconds to lock into your heartrate signal before it starts giving you anything. The Google Play app shows you these signals (when you rotate your screen into landscape mode) and you can watch it lock in. After I had turned on the heartrate sensor and it got the lock, everything seemed to work for me.

Next, we can move on to reading the step count:

char-read-uuid 7a543305-6b9e-4878-ad67-29c5a9d99736

I got this command from comparing the return of the “char-desc” command above with the addresses in the documentation and looking for matching substrings. I’m pretty sure there are things here I don’t understand. But the first two bytes in the response string are the stepcount in little endian format. (Lower byte first.)

Last, there is the health thermometer. In the “primary” command, I noticed this line for health thermometer (address 0x1809 from the documentation):

attr handle: 0x0016, end grp handle: 0x001d uuid: 00001809-0000-1000-8000-00805f9b34fb

which means handles 0x16 to 0x1d are for health thermometer. I tinkered a little bit, but wasn’t able to get the temperature from the thermometer. This isn’t the main thing I wanted to play with at this point, so I moved on before I had any success.

But at least I had success getting access to the heartrate and step counts of the device using gatttool on the Linux command-line.