Discovering BLE Device Services and Characteristics

Before starting access operations, the GATT Client must perform Services Discovery to discover all the services and characteristics hosted by the GATT Server on the remote device. The Services Discovery is initiated by the discoverServices() method of the BluetoothGatt class.

boolean discoverServices()

The discovery of services is an asynchronous operation. Once service discovery is completed, the onServicesDiscovered() callback in the BluetoothGattCallback class is triggered. If the discovery was successful, the remote services list can be retrieved using the getService() method.

void onServicesDiscovered(BluetoothGatt gatt, int status)

List<BluetoothGattService> getServices()

The members in the services list are instances of BluetoothGattService class. The getUuid() method can be used to retrieve the UUID of the service.

UUID getUuid()

For each service discovered in the GATT Server, the list of characteristics can be retrieved using the getCharacteristics() method.

List<BluetoothGattCharacteristic> getCharacteristics()

The members in the characteristics list are instances of BluetoothGattCharacteristic class. The getUuid() method can be used to retrieve the UUID of the characteristic.

In the MCHP Transparent UART Android app, the onConnectionStateChange() callback method of the BluetoothGattCallback class provides information on when the Central GATT Client has connected/disconnected to/from the remote GATT Server on the peripheral device. On the BluetoothProfile.STATE_CONNECTED callback event indicating a successful connection with the peripheral, the BLEService automatically attempts to discover the services hosted by the peripheral as shown in the screenshot below.

discoverservices.png

The onServicesDiscovered() callback method is called when the peripheral services are discovered successfully. The discovered services can be accessed using BluetoothGatt.getServices() method through BLEService.getSupportedGattServices().

getservices.png

The characteristics available in an specific service can be accessed using the BluetoothGattService.getCharacteristics() method through BLEService.getSupportedGattServices().

getcharacteristics.png
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.