Comprehensive BLE training

BLE GATT: Services, Characteristics, Descriptors and Notifications

Learn the GATT structure from Service to Characteristic and Descriptor and see the difference between Read, Write, Notify and Indicate in a real sensor.

Contents
Actual photo of nRF51822 based mKIT board; Old example of BLE hardware, not the nRF52840 or Sniffer introduced in the text.
Actual photo of nRF51822 based mKIT board; Old example of BLE hardware, not the nRF52840 or Sniffer introduced in the text. Photo: Ordercrazy; Wikimedia Commons resource; CC0. The content of the photo has not changed; A Wikimedia preview image is used. This is not a documentary photo of the LCENJ experiment.
Step 9 of 20 ways to master BLE

GATT transforms product data into a discoverable structure. Instead of sending anonymous bytes, we specify that this service is an environment, this Characteristic is a temperature, and this Descriptor controls how the notification is triggered.

Service and Characteristic

Service is a logical collection of related capabilities and can be Primary or Secondary. Characteristic includes Declaration, Value and possibly Descriptors. Properties say what operations are allowed; Permission determines what level of access or security is required.

Descriptor and CCCD

The Descriptor holds additional information about the Characteristic. A CCCD with a standard UUID of 0x2902 allows the client to turn on Notify or Indicate. Just having property is not enough; The client should write the CCCD and the server should keep its state for each connection.

Read, Write and Write Without Response

Read is suitable for data that the client can receive at any time. Write Request has protocol confirmation. Write Without Response is useful for a fast flow of commands, but the program must handle buffer overflows and possible misses. Design a functional response or confirmation for important setting.

Notify vs. Indicate

Notify does not have ATT response and is faster, but ATT-level delivery is not guaranteed. Indicate does not allow the next Indication to be sent until Confirmation is received and is more reliable but slower. The current status of the sensor is usually Notify and critical event or setting change can be Indicate.

GATT thermometer model

Create an Environmental Service and put two Characteristics for temperature and humidity. Have both Read and Notify. Send the data with a fixed unit eg hundredths of a degree in int16 and document the endianness convention. Consider the third characteristic for Sampling Interval with Read and Write.

Temperature contract and CCCD with exact value

If you use the standard Environmental Sensing service with UUID=0x181A, follow the standard characteristics: Temperature with UUID=0x2A6E is an int16 value with units of 0.01 degrees Celsius; Humidity with UUID=0x2A6F has a uint16 value with a unit of 0.01 percent humidity. For a custom template, use your own custom UUID and documentation.

Temperature 25.00 C: C4 09
CCCD enable notify: 01 00
CCCD enable indicate: 02 00
CCCD disable: 00 00

0x2902, the UUID is a Descriptor type, not a Handle that you should always write to. Discover the true handle of CCCD. Receiving Indication Confirmation is confirmation of the ATT level and does not mean the physical execution of the command or the correctness of the sensor measurement; For an important command, a functional response and real status are required.

Bluetooth SIG Official Assigned Numbers

Question and answer article

Ask your technical question

Questions and answers are published after moderation. Authors can see their own pending drafts.

No confirmed questions have been registered for this article yet.