PSoC6 BLE: Discovering of all Services, Characteristics and Descriptors in a GATT Database

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Yugandhar
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 5 likes given

Question: How a GATT Client can discover all the Services, Characteristics and Descriptors in the  Peripheral GATT Database with PSoC6 BLE device?

 Answer: BLE Central device (GATT Client role) can discover all the services, characteristics and descriptors on a GATT Server (peripheral in majority of cases), to which it is connected using the Cy_BLE_GATTC_DiscoverPrimaryServices(), Cy_BLE_GATTC_DiscoverCharacteristics() and Cy_BLE_GATTC_DiscoverCharacteristicDescriptors() APIs.

Cy_BLE_GATTC_DiscoverPrimaryServices() API is used to discover all the primary services on a GATT Server as per the handle-range provided. Cy_BLE_GATTC_DiscoverCharacteristics() API is used to discover all the characteristics in a service on a GATT Server when the service handle range is known. Cy_BLE_GATTC_DiscoverCharacteristicDescriptors() API is used to find all the characteristic descriptors when the attribute handle range is known.

Objective:

This example demonstrates how a GATT Client can discover services, characteristics and descriptors on a GATT server Database device with PSoC6 BLE Device.

Overview:

In this example project, BLE component is configured in GAP Central role. Initially, device will scan and connect to the peer device which is advertising with desirable peripheral device address. After the device gets connected to the peripheral, central device will discover all the services, characteristics and descriptors and prints their Attribute handles, UUIDs etc. through UART using a terminal application (like TeraTerm).

Requirements:

Design Tool: PSoC Creator 4.4 or later.

Programming Language: C.

Associated Devices: All PSoC 6 BLE devices.

Required Hardware: CY8CKIT-062-BLE Pioneer Kit.

PSoC Creator Schematic:

                              Figure1: PSoC Creator Schematic- PSoC 6 BLE GATT Client Discovery.

                                       Yugandhar_0-1680079850536.png

 

Project Description:       

    In PSoC6 BLE Central project, BLE Component is configured in dual role where controller on cmo+ and Host and profiles on cm4. In HostMain() function, Cy_BLE_Start(StackEventHandler) function is called to start the BLE Component and register a callback to the stack event handler. On successful stack initialization, CY_BLE_EVT_STACK_ON is received and Cy_BLE_GAPC_StartScan() function is called to discover GAP peripheral devices. As soon as the discovery operation starts, CY_BLE_EVT_GAPC_SCAN_START_STOP event is generated. The event CY_BLE_EVT_GAPC_SCAN_PROGRESS_RESULT will be generated when Discoverable GAP peripheral devices are located. After checking with valid Device address of the GAP peripheral, the GAP central device stops scanning and send a connect request to the peripheral.

     After connecting with the device, Cy_BLE_GATTC_DiscoverPrimaryServices() function is called to discover all the primary services on a GATT Server( peripheral in present case) to which it is connected. Internally, this function initiates multiple Read By Group Type Requests to the peer device, in response to which it receives Read By Group Type Responses. Each Read By Group Type Response results in CY_BLE_EVT_GATTC_READ_BY_GROUP_TYPE_RSP event. Start handle, End handle, UUID values of the services will be displayed in the TeraTerm.

   After discovering all the services, reference project asks to enter character ‘c’ or ‘C’ for discovering the characteristics in a service. After entering the character, user has to enter the service number (numbers should be entered in two-digit format like 01,02,03….) to discover all the characteristics present in that service. Cy_BLE_GATTC_DiscoverCharacteristics() API is used to discover all characteristics within a service on a GATT Server when the service handle range is known. Internally, multiple Read By Type Requests are sent to the GATT Server, in response to which Read By Type Responses are received. Each response results in the event CY_BLE_EVT_GATTC_READ_BY_TYPE_RSP. Characteristic declaration Handle, Characteristic Properties, Characteristic Value Handle and Characteristic UUID values of all the characteristics present in that service will be displayed in the TeraTerm.

   After discovering all the characteristics, reference project asks either to enter character ‘d’ or ‘D’ for discovering the descriptors in a characteristic number or to enter character ‘c’ or ‘C’ for discovering the characteristics present in other services. If user enters character ‘d’ or ‘D’ followed by the characteristic number (numbers should be entered in two-digit format like 01,02,03….), then the client device will starts discovering all the characteristic descriptors present in that characteristic. Cy_BLE_GATTC_DiscoverCharacteristicDescriptors() API is used to discover all the descriptors in a characteristic when the attribute handle range is known. Internally, multiple Find Information Requests are sent to the peer device, in response to which Find Information Responses are received at the GATT Client. Each of these responses generate CY_BLE_EVT_GATTC_FIND_INFO_RSP event at the GATT Client end. Descriptor Handle, Descriptor UUID format and Descriptor UUID values of all the descriptors present in that characteristic will be displayed in the TeraTerm.

Steps to Test the project:

  • Open UART Terminal and the select the COM port (related to PSOC6 BLE device) and use the following settings:

         Baud rate:115200

         Data rate: 8 bit

         Parity: none

         Stop: 1 bit

         Flow control: none

  • After programming the PSoC6 BLE Central, device will start to scan. Among the received peripheral devices, if the peripheral device address matches with 0x00A050AABBFF address then the central device will connect automatically. After the connection got established, client device discovers all the services present in the GATT database. Discovered services will be displayed in the TeraTerm as shown in Figure 2.

                                                    Figure 2: List of services displayed in UART Terminal.

                                               Yugandhar_0-1680083758326.png                               Yugandhar_1-1680079850547.jpeg

  • Enter character ‘c’ or ‘C’ followed by the service number to discover all the characteristics present in that service. List of characteristics will be displayed as shown in Figure 3.

                                                             Figure 3: List of characteristics displayed.

                                                Yugandhar_2-1680079850554.jpeg

 

  • Enter character ‘d’ or ‘D’ followed by the characteristic number to discover all the descriptors present in that characteristic. List of characteristic descriptors will be displayed as shown in Figure 4.

                                                                    Figure 4: List of descriptors displayed.

                                                Yugandhar_3-1680079850564.jpeg

Conclusion:

Central project (GATT Client) is successfully developed and verified with the PSoC6 BLE Device and the expected results are observed. Please find the below attached Central project.

2 Replies
Communication
Level 5
Level 5
100 replies posted First solution authored 250 sign-ins

Your example works very well, but I wonder is there any similar example for Modus Toolbox and PSoC 6BLE?

Thanks!

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

To all,

I have a similar project I posted years ago.  link:  PSoC6-BLE-Beacon-and-Scanner-Creator-projects 

It is a dual project workspace.   It contains a Scanner that has features to reveal GATT Client discovery info.

It also has a Beacon (advertiser) so that you can program which characteristics you want to advertise from your peripheral.

Len
"Engineering is an Art. The Art of Compromise."