The idea: a strap that calls out, a phone that listens

A heart-rate strap has a tiny battery. It cannot keep its radio on all the time. So Bluetooth Low Energy (BLE) works in short bursts. First the strap advertises: it calls out "I am here, I measure heart rate" a few times per second. A phone that scans hears it and asks to connect. After that the two meet at fixed times, a fraction of a millisecond each time, and sleep in between. Over this link the phone uses GATT to find the heart-rate value and ask the strap to push every new value.

Three stages: advertising on channels 37, 38, 39; a connection with 30 ms events hopping channels; GATT discovery, a read and a CCCD write, then notifications. A dashed red arrow goes back to advertising after a 2000 ms supervision timeout.
The strap's life: advertise, get connected, serve GATT, and fall back to advertising when the link times out.

The page shows two devices: the strap (the peripheral and GATT server) and the phone (the central and GATT client). The middle panel is the air: the 40 BLE channels in frequency order, the channel in use now (orange), and a log of every packet.

Advertising: the strap sends ADV_IND on channel 38 with Heart Rate 0x180D; the phone answers SCAN_REQ on channel 38; the strap answers SCAN_RSP with the name HRM-Strap. Connection: the strap sends ADV_IND on channel 37; the phone answers CONNECT_IND with interval 30 ms and hop 7; from then on they meet every 30 ms on channels 7, 14, 21 and so on, phone first, strap 150 µs later. GATT: discovery takes 4 request/response pairs and finds handles 0x000E, 0x000F and 0x0011; the phone sends ATT_READ_REQ 0x0011 and gets ATT_READ_RSP 0x01, Chest; the phone sends ATT_WRITE_REQ 0x000F with CCCD = 0x0001 to turn notifications on and gets ATT_WRITE_RSP; then the strap pushes ATT_HANDLE_VALUE_NTF 75 bpm without being asked.
The strap advertises, the phone scans and connects, and after one CCCD write the strap pushes every new bpm without being asked.

Advertising and scanning

BLE uses 40 channels of 2 MHz from 2402 to 2480 MHz. Three of them are advertising channels: 37 (2402 MHz), 38 (2426 MHz) and 39 (2480 MHz). They sit apart, between the busiest Wi-Fi channels. One advertising event sends the same ADV_IND on 37, then 38, then 39. The next event starts one advertising interval later (100 ms here) plus a random advDelay of 0 to 10 ms, so two advertisers do not collide every time.

The ADV_IND carries the strap's address and up to 31 bytes of data. Here: Flags 0x06 (discoverable, BLE only) and the service UUID 0x180D (Heart Rate). The phone listens on one advertising channel at a time, so it misses the other copies. In an active scan it answers the copy it heard with SCAN_REQ, on the same channel, 150 µs later. The strap answers SCAN_RSP with more data: the name "HRM-Strap" (Demo 1: advertise, then an active scan).

CONNECT_IND and connection events

To connect, the phone waits for the next ADV_IND and answers it with CONNECT_IND. The strap stops advertising at once. CONNECT_IND holds everything the link needs:

FieldValue hereMeaning
AA0x50654C23access address that marks this connection's packets
Interval24 → 30 mstime between connection events (units of 1.25 ms)
Latency0events the strap may skip when it has nothing to send
Timeout200 → 2000 mssupervision timeout (units of 10 ms)
ChM, Hopall 37, 7which data channels to use and how far to jump

From then on the two meet at a connection event every 30 ms. The phone always sends first; the strap answers 150 µs later on the same channel. With nothing to say they send empty PDUs: that still proves the link is alive. Each event moves to the next data channel: channel = (last + hop) mod 37, so 7, 14, 21, 28, 35, 5, … A noisy channel spoils only one event (Demo 2: connect, events hop channels).

A time line with five connection events 30 ms apart on channels 7, 14, 21, 28 and 35. In each, a green arrow goes from the phone to the strap, then a purple arrow back.
Connection events: one every 30 ms, phone first, strap 150 µs later, each on a new channel.

With a peripheral latency of 4, the strap could sleep through up to 4 events in a row when it has no data, and save more battery. The page uses latency 0, so the strap answers every event.

GATT: services, characteristics, descriptors

GATT data lives in an attribute table on the strap. Each attribute has a handle (its address), a type (a UUID) and a value. The phone reads and writes them with ATT requests that ride inside the connection events.

HandleTypeValue
0x000CPrimary Service 0x28000x180D Heart Rate
0x000DCharacteristic 0x2803Notify, value at 0x000E, UUID 0x2A37
0x000EHeart Rate Measurement 0x2A37flags 0x00, bpm
0x000FCCCD 0x29020x0000 (off) or 0x0001 (notify)
0x0010Characteristic 0x2803Read, value at 0x0011, UUID 0x2A38
0x0011Body Sensor Location 0x2A380x01 Chest

The phone does not know these handles at first, so it discovers them (Demo 3: GATT service discovery):

  1. ATT_READ_BY_GROUP_TYPE_REQ for type 0x2800 finds the services. Heart Rate is 0x000C–0xFFFF; it ends at 0xFFFF, so it is the last one.
  2. ATT_READ_BY_TYPE_REQ for type 0x2803 finds the two characteristics. The phone asks again from 0x0011 and gets ATT_ERROR_RSP 0x0A, Attribute Not Found: no more.
  3. ATT_FIND_INFORMATION_REQ on the handles between 0x000E and 0x0010 finds the CCCD at 0x000F.

Notifications and the CCCD

A read is one request and one response: ATT_READ_REQ 0x0011 returns 0x01, Chest. Asking for the heart rate that way every second would waste radio time. Instead the phone writes 0x0001 to the Client Characteristic Configuration Descriptor (CCCD, 0x2902): ATT_WRITE_REQ 0x000F = 01 00. From then on the strap pushes each new value as ATT_HANDLE_VALUE_NTF in its next answer. A notification gets no ATT reply. While the CCCD is 0x0000, a new value stays on the strap and it answers with empty PDUs (Demo 4: read, enable notifications, get bpm).

An indication (CCCD 0x0002) is the same push, but the phone must confirm each one. Heart rate uses notifications: a lost value is replaced by the next one a second later.

Supervision timeout

Both sides keep a timer. Each packet heard from the other side restarts it. If it reaches the supervision timeout (2000 ms here) the link is lost. The phone reports reason 0x08, Connection Timeout. The strap drops the link too, forgets the CCCD (it was not bonded) and goes back to advertising (Demo 5: strap walks out of range). The timeout must be longer than (1 + latency) × interval × 2, here 60 ms, so a few lost packets do not end the link.

See also Wi-Fi CSMA/CA, the other radio sharing the 2.4 GHz band, and MQTT QoS, which often carries such sensor values on from the phone or a gateway.

What the page leaves out

The page answers each ATT request in the same connection event; real stacks often answer one event later. It sends one packet each way per event and hides the link-layer SN/NESN acknowledgements, the More Data bit, the transmit window and window widening. It skips the MTU exchange, pairing and bonding, encryption, connection parameter updates, the 2M and Coded PHYs, extended advertising (Bluetooth 5) and Channel Selection Algorithm #2. The GAP and GATT services and RSSI are fixed sample values.

On the mind map

Open the Networking mind mapNetworkingLayers & links: frames on one local networkLayers & linksIP & routing: packets hop between networksIP & routingCore services: address, name and timeCore servicesTCP, UDP & sockets: end to end between two portsTCP, UDP & socketsHTTP & TLS: what a browser does per requestHTTP & TLSAPIs & push: how apps talk to serversAPIs & pushProxies & edge: boxes in the middle of the pathProxies & edgeContainers: virtual networks from Linux partsContainersReal-time media: voice and video over UDPReal-time mediaSecurity at the edge: filter traffic at the borderSecurity at the edgeProtocol layersProtocol layerseach layer wraps the one above in a headerHub vs switch vs routerHub vs switch vs routerL1 repeats, L2 learns MACs, L3 routes IPIGMP multicastIGMP multicastsnooping sends a group only to membersRapid Spanning TreeRapid Spanning TreeAlternate port takes over at onceLACP Link AggregationLACP Link AggregationOne flow rides one link, never moreVLANsVLANs802.1Q tag splits one switch into LANs802.1X and RADIUS802.1X and RADIUSPort stays closed until Access-AcceptARPARPbroadcast who-has IP, reply with the MACCRCCRCXOR division remainder catches bit errorsInternet ChecksumInternet ChecksumSum + NOT sum = 0xFFFF; blind to swapsWi-Fi CSMA/CAWi-Fi CSMA/CAlisten, random backoff, wait for the ACKBluetooth LE and GATTWrite CCCD 0x0001, then values get pushedALOHA and CSMA/CDALOHA and CSMA/CDFrame must last 2τ to hear a collisionLoRaWAN class ALoRaWAN class ASend any time, listen only at RX1/RX2Cellular Reuse and HandoverCellular Reuse and HandoverMargin + timer: no ping-pong, no dropDigital modulation (QAM)Digital modulation (QAM)More bits per symbol needs more SNROpen the Networking mind mapNetworkingframes on one local networkLayers & linksProtocol layersProtocol layerseach layer wraps the one above in a headerHub vs switch vs routerHub vs switch vs routerL1 repeats, L2 learns MACs, L3 routes IPIGMP multicastIGMP multicastsnooping sends a group only to membersRapid Spanning TreeRapid Spanning TreeAlternate port takes over at onceLACP Link AggregationLACP Link AggregationOne flow rides one link, never moreVLANsVLANs802.1Q tag splits one switch into LANs802.1X and RADIUS802.1X and RADIUSPort stays closed until Access-AcceptARPARPbroadcast who-has IP, reply with the MACCRCCRCXOR division remainder catches bit errorsInternet ChecksumInternet ChecksumSum + NOT sum = 0xFFFF; blind to swapsWi-Fi CSMA/CAWi-Fi CSMA/CAlisten, random backoff, wait for the ACKBluetooth LE and GATTWrite CCCD 0x0001, then values get pushedALOHA and CSMA/CDALOHA and CSMA/CDFrame must last 2τ to hear a collisionLoRaWAN class ALoRaWAN class ASend any time, listen only at RX1/RX2Cellular Reuse and HandoverCellular Reuse and HandoverMargin + timer: no ping-pong, no dropDigital modulation (QAM)Digital modulation (QAM)More bits per symbol needs more SNR
This page on the Networking mind map · 83 pages in 10 branches · open it to see the whole map and test yourself in recall mode.