This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2340R5: How does the Central know the notification and write handles in the data_stream sample code?

Part Number: CC2340R5

Hi TI Experts ,
Using two CC2340R5 boards with the data_stream example (Central & Peripheral roles), how can the Central side find the right req.handle for enabling notifications or sending data? Is there an API for handle discovery?

SDK 9.14.2.16

void EnableNotification(char *index){
    
	attWriteReq_t req;

    bStatus_t status;

    uint8 configData[2] = {0x01,0x00};
    req.pValue = GATT_bm_alloc(app_connection_handle, ATT_WRITE_REQ, 2, NULL);

    // Enable notify for outgoing data
    if (req.pValue != NULL)
    {
        req.handle = 47;//????
        req.len = 2;
        memcpy(req.pValue, configData, 2);
        req.cmd = TRUE;
        req.sig = FALSE;
        status = GATT_WriteNoRsp(app_connection_handle, &req);
        if ( status != SUCCESS )
        {
            GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ);
        }

    }
	
}
static gattAttribute_t dss_attrTbl[] =
{
 /*--------------------type-------------------*/ /*------------permissions-------------*/ /*------------------pValue--------------------*/
   // Data Stream Service
   GATT_BT_ATT( primaryServiceUUID,                 GATT_PERMIT_READ,                        (uint8 *) &dss_service ),

   // DataIn Characteristic Properties
   GATT_BT_ATT( characterUUID,                      GATT_PERMIT_READ,                        &dss_dataIn_props ),
   // DataIn Characteristic Value
   GATT_ATT( dss_dataIn_UUID,                       GATT_PERMIT_WRITE,                       &dss_dataIn_val ),
   // DataIn Characteristic User Description
   GATT_BT_ATT( charUserDescUUID,                   GATT_PERMIT_READ,                        dss_dataIn_userDesp ),

   // DataOut Characteristic Properties
   GATT_BT_ATT( characterUUID,                      GATT_PERMIT_READ,                        &dss_dataOut_props ),
   // DataOut Characteristic Value
   GATT_ATT( dss_dataOut_UUID,                      0,                                       &dss_dataOut_val ),
   // DataOut Characteristic configuration
   GATT_BT_ATT( clientCharCfgUUID,                  GATT_PERMIT_READ | GATT_PERMIT_WRITE,    (uint8 *) &dss_dataOut_config ),
   // DataOut Characteristic User Description
   GATT_BT_ATT( charUserDescUUID,                   GATT_PERMIT_READ,                        dss_dataOut_userDesp ),
};
  • Hi Anthony,

    Thank you for posting your question. Let me take a look and report back with my findings as soon as I have them.

    Regards,

    Ging

  • Hi Ging

    Any updates on this? My Central device fails to re-enable notifications after a reconnection (error 0x16 during GATT_WriteNoRsp). I suspect the handle (previously 47) might be wrong after the link dropped. Are there any APIs to look up the specific attribute handle dynamically?

    Regards,

    Anthony

  • Anthony,

    Apologies for the delay. The recommended way to enable notifications for an attribute is the following:

    1. Discover the services of the GATT table using "GATT_DiscAllPrimaryServices"
    2. Discover the charactersitics of the service you're interested in using "GATT_DiscAllChars"
    3. At this point, you will have access to the handle for each attribute. You can then get the
    CCCD handle you want and call "GATT_WriteNoRsp" to enable notifications.

    You can use this example as reference: github.com/.../README.md

    And for more information, this thread could also be useful: e2e.ti.com/.../cc2340r5-service-discovery

    Regards,
    Ging