nRF5 SDK v16.0.0
GATT Service Client
This information applies to the following SoftDevices: S132, S140

This module implements a client for the Generic Attribute Profile (GATT) Service. It subscribes to indications from the Service Changed Characteristic (0x2A05).

Service Changed indications

A typical BLE client application will interact with services on a server. The location of the services in the GATT database can change as long as a Service Changed indication is sent to the peers. If this indication is not handled, your application will not know about the database changes, which can cause it to fail.

This client module can be included in your BLE applications to subscribe and handle the Service Changed indications. This is required if your application interacts with GATT servers that modify, remove, or add services. A typical course of action if a Service Changed indication is received is to rediscover the database on the peer device.

For more information about the GATT Service, see "Defined Generic Attribute Profile Service" in Bluetooth Specification Version 5.0, Vol 3, Part G, Section 7: Bluetooth Core Specification.

Usage

Note
The application must register each instance of this module as a BLE stack event observer using the NRF_SDH_BLE_OBSERVER macro from the SoftDevice Handler library.
NRF_SDH_BLE_OBSERVER(m_gatts_ble_observer, BLE_GATTS_BLE_OBSERVER_PRIO, ble_gatts_on_ble_evt, &m_instance);

On BLE_GAP_EVT_CONNECTED, a service discovery must be run on the peer (examples in this SDK use db_discovery). If the Service Changed characteristic is discovered on the peer (NRF_BLE_GATTS_C_EVT_DISCOVERY_COMPLETE), you must use nrf_ble_gatts_c_handles_assign to assign handles which will associate the instance of the gatts_c module with this peer.

Once the handles are assigned, you can call nrf_ble_gatts_c_enable_indication to subscribe to Service Changed events from this peer (NRF_BLE_GATTS_C_EVT_SRV_CHANGED). A likely course of action for your application is to rediscover the database (ble_db_discovery_start if you are using the discovery module from this SDK), thereby reassigning the handles of your clients.

Message Sequence Charts

No Service Changed characteristic found:

msc_inline_mscgraph_15


Service Changed characteristic found:

msc_inline_mscgraph_16

Documentation feedback | Developer Zone | Subscribe | Updated