BLE Enable a custom characteristic's notification in code (CCCD)

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

cross mob
lock attach
Attachments are accessible only for community members.
chcac_2757786
Level 1
Level 1

I'm trying to enable the notifications on a custom characteristic via code (not through the schematic UI).  I'm using the BLE Navigation sample project for a PSoC6 Pioneer Kit and PSoC Creator  4.2 (4.2.0.641).

I create this function to update CCCD values..

static void updateCccdValue(cy_ble_gatt_db_attr_handle_t attrHandle, uint8_t val)

{

    cy_stc_ble_gatt_handle_value_pair_t handle;

    cy_en_ble_gatt_err_code_t errCode;

    uint8 cccdValue[1];

   

    cccdValue[0] = val;

   

    handle.attrHandle = attrHandle;

    handle.value.val = cccdValue;

    handle.value.len = sizeof(uint8);

   

    /* Update CCCD characteristic value */          

    errCode = Cy_BLE_GATTS_WriteAttributeValueLocal(&handle);

    DBG_PRINTF("updateCCCDValue ERROR: %d, attrHandle: 0x%x, value: %d\r\n", errCode, handle.attrHandle, *handle.value.val);

}

I call updateCccdValue() from the CY_BLE_EVT_GATTS_INDICATION_ENABLED stack handler...

        case CY_BLE_EVT_GATTS_INDICATION_ENABLED:

            DBG_PRINTF("CY_BLE_EVT_GATTS_INDICATION_ENABLED \r\n");

           

            updateCccdValue(CY_BLE_CUSTOM_SERVICE_CUSTOM_CHARACTERISTIC_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE, 1);

           

            break;

When updateCccdValue() executes, it prints out the following:

updateCCCDValue error: 1, attrHandle: 0x2a, value: 1

I believe error code 1 is CY_BLE_GATT_ERR_INVALID_HANDLE.  However, the attrHandle of 0x2a does match the CY_BLE_CUSTOM_SERVICE_CUSTOM_CHARACTERISTIC_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE definitions. 

I've also attached a screenshot of the CUSTOM_CHARACTERISTIC's configuration

Any ideas if this is the right approach?

0 Likes
1 Solution
chcac_2757786
Level 1
Level 1

I found the issue.  To update a CCCD value, you have to use Cy_BLE_GATTS_WriteAttributeValuePeer().

View solution in original post

0 Likes
1 Reply
chcac_2757786
Level 1
Level 1

I found the issue.  To update a CCCD value, you have to use Cy_BLE_GATTS_WriteAttributeValuePeer().

0 Likes