文章總列表

Holiday Bluetooth Engineer: GATT protocol

The GATT is built over ATT protocol, which defines 2 terms
  • Service
  • Characteristics


Each service contains several characteristics. Each characteristic has single property/value and several descriptor.

Service
In ATT table, the entry with UUID = 0x2800 defines service, which is the start-of-service. The content within is service UUID. In previous post, handle = 1/8/9/11/15 are of such type.



    handle: 0x0001, uuid: 2800          1800, Generic access
    handle: 0x0008, uuid: 2800          1801, Generic attributes
    handle: 0x0009, uuid: 2800          180D, Heart Rate
    handle: 0x0011, uuid: 2800          180F, Battery Service
    handle: 0x0015, uuid: 2800          180A, Device Information

Take handle[0x9] as example, the value is 0x180D, heart rate service. The heart rate monitor handle region is between 0x9 to 0x10 because the next UUID = 0x2800 is located in handle[0x11].

Therefore, by searching UUID = 0x2800, we can find all services in BLE device and identify the handle region of certain service.


Characteristic
Within service, there is another separator 0x2803 which defines characteristics. Central devices such as smart phone scan UUID = 0x2803 between handle[0x9 ~ 0x10] to find all characteristics within. Handle[0xA/ 0xD/ 0xF] defined 3 characteristics as shown below.

    handle: 0x0009, uuid: 2800          180D, Heart Rate

    handle: 0x000a, uuid: 2803          10 000b 2a37
    handle: 0x000b, uuid: 2a37          Heart rate measurement, only notify (*)
    handle: 0x000c, uuid: 2902          Control channel

    handle: 0x000d, uuid: 2803          02 000e 2a38
    handle: 0x000e, uuid: 2a38          01, chest

    handle: 0x000f, uuid: 2803          08 0010 2a39
    handle: 0x0010, uuid: 2a39          Heart rate control point

Smart phone reads handle[0xD] with data 02 000E 2A38. Refer to the interpretation below. Then smart phone knows that handle[0xE]'s UUID = 0x2800.
  • Permission, 0x2, read only
  • Handle number, the characteristic data is located in handle[0xE]
  • UUID number, the characteristic data's UUID is 0x2A38
Data in handle[0xA] is 10 000B 2A37. Permission 0x10 stands for notification only. We can't use normal GATT read to get heart rate measurement. The characteristic has another handle[0xC], which is the descriptor in the picture. In this example, it is CCC (Client Characteristic Configuration), with UUID = 0x2902. The CCC stores a bitmap shown below.
  • [bit0] enable/disable notification
  • [bit1] enable/disable indication
Master device shall write handle[0xC] = 0x1 to enable notification. After enabling, the sensor sends notification (measurement) to smart phone. The term notification in BLE means that master-device (smart phone) doesn't need to respond. On the other hand, indication requires the master-device to acknowledge.


BLE Master Device Summary
Here is what happened when sport tracker connects to BLE device under the hood:
  1. Master device searches UUID 0x2800 to know all services provided by BLE device. After the procedure done, the all handles[] belong to some service is also known.
  2. For some service, search UUID 0x2803 in handles[] can discover all characteristics provided by the services.
  3. Master device can read/write different characteristics to communicate with BLE device. 
  4. Some handle is only for notification/ indication. The master device shall find UUID = 0x2902 and enable notification(bit[0])/ indication(bit[1]) bit.
  5. Then the APP can read heart rate measurement and show it on GUI

Reference

留言

這個網誌中的熱門文章

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

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

CANON G3000 廢墨瓶改裝