文章總列表

Holiday Bluetooth Engineer, make it work

Foreword
I searched the Internet over and over, with keyword "Raspberry Pi, BLE" or "BLE Linux". Eventually, I found two articles are useful. Following instructions, I soon get my heart rate sensor up. However, I don't know the Bluetooth completely. This makes me feel uncomfortable.
As a holiday Bluetooth engineer, sometimes I must bring up things earlier than understanding it. So I decide to write down what I've learned here, then find answer later.


gatttool
The gatttool is part of Bluez package. The keyword "GATT/ATT" appeared so frequently that this must be an important keyword. I will figure out them later.

Use the MAC address with "hcitool lescan" showed in previous post, I can start gatt connection with the tool. See following screenshot.



In the tool's command line interface, typing "help" to know the functionality it provided:


The command "primary" is interesting, it shows the service provided by this device. I checked each UUID, and here's the definition. I got these information from Bluetooth Developer Portal. So, I got the evidence that the device is heart rate monitor.
  • 0x1800, Generic Access
  • 0x1801, Generic Attribute
  • 0x180D, Heart Rate
  • 0x180F, Battery Service
  • 0x180A, Device information
The "attr handle" string below is also wired for me. It looks like some index of the table.



The next command is "char-desc", which generates a list of all available handles. I checked the table with "primary" screenshot. I found some regularity within. For example, handle 0/8/9/11/15 has uuid 0x2800. This page shows 0x2800 is "primary service" thing. (What's that !!)

I checked I a lot of web pages and had some feeling that I could figure out what they are. I think I would write another article explaining what they are.



Eventually, I followed the instruction suggested by the article. I told me that I shall set 0x0100 to some entry with UUID = 0x2902. I checked the table above and found they're handle 0x0C & 0x14. With some try and error, I found setting handle[0x0c] = 0100 can enable heart rate notification as shown below.


Notification is that heart rate monitor sends heart rate counter to host (RPi). As RPi receives the data, it will display in the screen. The page indicates how to interpret the data sent by the device.

Here is the interpretation of 1st notification: 0x16 0x42 0xA1 0x03

  • 0x16
    [bit0] 0:heart rate value is UINT8, 1:heart rate value is UINT16
    [bit2:1] 3:Sensor contact feature is supported
    [bit3] 0: Energy expanded field is not present
    [bit4] 1: One or more RR-interval values are present. Unit = 1/1024 seconds
  • 0x42
    Heart rate measure value, 66 in decimal
  • 0xa1 0x03
    The heart rate interval is 0x3A1 = 929 / 1024 seconds
    60sec / (929/1024) = 66 (heart rate)

The BLE data format is quite dense. It used a 8-bit header to present variable length data format. The heart rate read value makes sense. So finally, I believe I've running the BLE on my RPi to get the heart rate.



留言

這個網誌中的熱門文章

幼犬書桌椅選擇心得 升降桌 兒童桌椅

Herman Miller Aeron 一代氣壓棒維修

STM32 UART + DMA,使用HAL實作TX/RX,以及不定長度接收