This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Can a peripheral read a CCCD value?

Hi,

I am wondering if it is possible for a peripheral device to interpret and react to a specific value written to it's CCCD by a central device. In all of the examples I looked at, it appears that this characteristic can simply be NULL or != NULL. From the bas example:

            // CCCD written, call application event handler
        if (p_bas->evt_handler != NULL)
        {
            ble_bas_evt_t evt;

            if (ble_srv_is_notification_enabled(p_evt_write->data))
            {
                evt.evt_type = BLE_BAS_EVT_NOTIFICATION_ENABLED;
            }

            else
            {
                evt.evt_type = BLE_BAS_EVT_NOTIFICATION_DISABLED;
            }

            p_bas->evt_handler(p_bas, &evt);
        }

is it possible to create code where a central device would write 01:00 to the peripheral's CCCD to flash the peripheral's LED1 and write a value of 02:00 to flash the peripheral's LED2?

Parents
  • Hi. First: CCCD is an abbreviation for Client Characteristic Configuration Descriptor. By writing the data to CCCD, the server allows the peripheral to make notifications or indications.

    Second: You can read this value for example like this:

    static void on_write(ble_evt_t* p_ble_evt)
    {
        ble_gatts_evt_write_t* p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
        if (p_evt_write->handle == YOUR_CHARACTERISTIC_HANDLE.cccd_handle)
        {
                /*
                 then in "p_evt_write->data" we have cccd value
                 and in "p_evt_write->len" we have value len, usually is 2 byte len.
                */
        }
    }
    

    And, of course, you may compare p_evt_write->data with 01:00 or 02:00.

    Best, VL.

Reply
  • Hi. First: CCCD is an abbreviation for Client Characteristic Configuration Descriptor. By writing the data to CCCD, the server allows the peripheral to make notifications or indications.

    Second: You can read this value for example like this:

    static void on_write(ble_evt_t* p_ble_evt)
    {
        ble_gatts_evt_write_t* p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
        if (p_evt_write->handle == YOUR_CHARACTERISTIC_HANDLE.cccd_handle)
        {
                /*
                 then in "p_evt_write->data" we have cccd value
                 and in "p_evt_write->len" we have value len, usually is 2 byte len.
                */
        }
    }
    

    And, of course, you may compare p_evt_write->data with 01:00 or 02:00.

    Best, VL.

Children
Related