Subsection 15.1.5 How Communication Happens: GATT
Once a dedicated connection is established, data moves according to the Generic Attribute Profile (GATT), which defines how two BLE devices transfer data back and forth. GATT arranges the peripheral’s data in a small hierarchy. A service is a category of functionality, and a peripheral can offer several. Each service contains one or more characteristics, and a characteristic is one piece of data. Each characteristic carries a value, which is the actual data, and properties, which are the rules for using it: whether the central may read it, write it, or subscribe to be notified when it changes.
Here is a concrete example of that hierarchy. Team 15’s Bluefruit device offers one service, which the team named ENGS 28 Super Cool Final Project. Inside it are two characteristics. The first is a temperature, whose value could for example be 72 °F and whose property is read, so the central can request the current value at any time. The second is a motor speed, whose value is for example 65 rpm and whose property is write, so the central can send a new value. A third property, notify (not used in the example), lets the peripheral push a new value to the central whenever the value changes, without being asked. Your own project’s data does not appear as its own service; it rides inside the UART service’s two characteristics (Subsection 15.1.6).
| The GATT layer | Team 15’s instance |
|---|---|
| Device | Team 15’s Bluefruit module |
| Service, a category of functionality | ENGS 28 Super Cool Final Project |
| Characteristic, one piece of data | Temperature: value 72 °F, property read |
| Characteristic, another piece of data | Motor speed: value 65 rpm, property write |
A message board is a good analogy for the rhythm of the exchange. The peripheral wakes up and begins advertising, and its advertising packet names its available services; the characteristics inside them are discovered once the central connects. Each characteristic defines its rules, and those rules define how the client can interact with it. There is no constant conversation: the peripheral pins a note to a board and the central reads it once it has connected, rather than the two of them talking continuously. The peripheral sends a structured update when there is something to send and stays silent the rest of the time, and that is what makes BLE cheap enough in power to run from a coin cell.
