This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

zephyr/ncs: how to tell which attribute has CCCD changed

Hi,

I understand the on_cccd_changed() will be called when CCCD changed. But I can't figure out which attribute it's associated with. I try to print out the UUID which is always 2902.

The code below is from the NCS BLE tutorial.

I have 4 characteristics with notification. I need to know which one was enabled when on_cccd_changed() was called.

Thanks!

static void on_cccd_changed(const struct bt_gatt_attrattruint16_t value)
{
  char uuid_str[50];
  bt_uuid_to_str(attr->uuiduuid_strsizeof(uuid_str));
  LOG_DBG("attr %s value=%d"log_strdup(uuid_str), value);
...
}
// one of the characteristic definition
BT_GATT_SERVICE_DEFINE(my_service,
                       BT_GATT_PRIMARY_SERVICE(BT_UUID_MY_SERVICE),
                      BT_GATT_CHARACTERISTIC(BT_UUID_CHAR_1,
                                              BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
                                              BT_GATT_PERM_READ_AUTHEN,
                                              char_1_read,
                                              NULL,
                                              NULL),
                       BT_GATT_CCC(on_cccd_changedBT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
Parents
  • Hi,

    When you use BT_GATT_CCC that is the CCCD for the characteristic you declared immediately before. To separate between them, use separate callback functions (see for instance zephyr\subsys\bluetooth\audio\vocs.c for an example).

    When the event handler is called (on_cccd_changed() in your case), you get a pointer to the attribute and the value (first and second parameter to the callback function respectively).

  • Right... what as I thinking. I must be too quick copying and pasting same code block four times and start to wonder how I can tell them apart if they're calling the same function...  :-(

    Thanks!

Reply Children
No Data
Related