3 Replies Latest reply on Oct 28, 2016 12:44 PM by e.pratt_1639216

    GATT services discovery


      I'm trying to get data from a custom GAP peripheral, GATT server.
      The peripheral sent data, and I can read GATT DB from CySmart, of course the services are unknown, but the data can be read and write.
      Now, starting from PSoC_4_BLE_Central_IAS example, I try to read the same data.
      •    After the call back function initialization CyBle_Start(StackEventHandler) and CyBle_ProcessEvents(); I manage the events I scan for device CyBle_GapcStartScan(CYBLE_SCANNING_FAST);  
      •    and after the CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT I get advertising data from evetparameter pointer.
      •    Found my device, I connect it by CyBle_GapcConnectDevice(&connectPeriphDevice);
      •    did this, I start GATT discovery calling  CyBle_GattcStartDiscovery(connHandle) that does not return any event parameter (the documentation says this) and
      •    I need to discover my GATT services and attributes. I've used CyBle_GattcDiscoverAllPrimaryServices(connHandle); and CYBLE_EVT_GATTC_DISCOVERY_COMPLETEe event are generated
      from here  I'm not understand how continue.
      Where are the discovered services?
      Does CYBLE_EVT_GATTC_DISCOVERY_COMPLETE returns an evetparameter? (reading the BLE documentation, this is not clear).
      The examples on central function are very few, Can I have some help?


      Thanks, Fabrizio

        • 1. Re: GATT services discovery
          Madhu Lakshmipathy



          After you call the GattcDiscoverAllPrimaryServices API, you will get the discovery data in chunks called (group) from the peripheral. Each time you receive a group, you will get the CYBLE_EVT_GATTC_READ_BY_GROUP_TYPE_RSP. You can obtain the data from the event parameter when you get this event. After all the discovery data is sent in multiple CYBLE_EVT_GATTC_READ_BY_GROUP_TYPE_RSP events, you will finally get the CYBLE_EVT_GATTC_DISCOVERY_COMPLETE event.


          I have attached a Central / Clinet project which discovers all primary services and characteristics from a server and displays them.


          Please find it attached. Use a UART Serial terminal (Like teraterm / coolterm) to test the project.




          - Madhu Sudhan

          • 2. Re: GATT services discovery

            Thanks Madhu, your help is helpful, but it generates, to me, some doubts and I need to understand.


            On my previous try I've used, after the connection, the CyBle_GattcStartDiscovery() function with the return of CYBLE_EVT_GATTC_DISCOVERY_COMPLETE event.
            Then I've called CyBle_GattcDiscoverAllPrimaryServices() and  waited the CYBLE_EVT_GATTC_READ_BY_GROUP_TYPE_RSP event, that never appeared.
            This seemed the right way. On my opinion.


            In your example CyBle_GattcStartDiscovery() was never used, instead after the connection, if I've correctly interpreted your code,  you call CyBle_GattcDiscoverAllPrimaryServices() and other.


            I've done the same and I've received CYBLE_EVT_GATTC_READ_BY_GROUP_TYPE_RSP,  two time, and CYBLE_EVT_GATTC_ERROR_RSP at the end, so this indicates that I've two services (not yet analyzed).


            My question is: why CyBle_GattcStartDiscovery() doesn't return what I expected? What is the use of CyBle_GattcStartDiscovery()?


            Regards, Fabrizio

            • 3. Re: GATT services discovery

              The CyBle_GattcStartDiscovery() function has the following listed in the documentation (under BLE_gatt.c where "BLE" is the name of you bluetooth component):


              * Function Name: CyBle_GattcStartDiscovery

              *  Starts the automatic server discovery process. Two events may be generated 
              *  after calling this function - CYBLE_EVT_GATTC_DISCOVERY_COMPLETE or 
              *  generated when the remote device was successfully discovered. The
              *  CYBLE_EVT_GATTC_ERROR_RSP is generated if the device discovery is failed.

              *  \param connHandle: The handle which consists of the device ID and ATT connection ID.

              * \return
              *    CYBLE_API_RESULT_T : Return value indicates if the function succeeded or
              *                        failed. Following are the possible error codes.
              *   <table>    
              *   <tr>
              *      <th>Errors codes</th>
              *      <th>Description</th>
              *    </tr>
              *    <tr>
              *      <td>CYBLE_ERROR_OK</td>
              *      <td>On successful operation</td>
              *    </tr>
              *    <tr>
              *      <td>CYBLE_ERROR_INVALID_PARAMETER</td>
              *      <td>'connHandle' value does not represent any existing entry.</td>
              *    </tr>
              *    <tr>
              *      <td>CYBLE_ERROR_INVALID_OPERATION</td>
              *      <td>The operation is not permitted</td>
              *    </tr>
              *   <tr>
              *      <td>CYBLE_ERROR_MEMORY_ALLOCATION_FAILED</td>
              *      <td>Memory allocation failed</td>
              *    </tr>
              *   <tr>
              *      <td>CYBLE_ERROR_INVALID_STATE</td>
              *      <td>If the function is called in any state except connected or discovered</td>
              *    </tr>
              *   </table>