Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
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

How to register/add notify callbacks dynamically on the Peripheral?

I would like to add dynamically notify callbacks on a given characteristic.

Currently I can only register one callback on the creation of the characteristic:

static void active_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) {
	ARG_UNUSED(attr);

	bool notif_enabled = (value == BT_GATT_CCC_NOTIFY);

	LOG_INF("ACTIVE notifications %s", notif_enabled ? "enabled" : "disabled");
}

...

BT_GATT_CCC(active_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE)

How can I add a callback for ccc changes during runtime for a given characteristic?

Parents
  • Hi,

    I do not see how it would be possible to add a callback at a later point. May I ask why you want to do that? In what use case is that useful? Could you not add a callback in the first place, but make it return without doing anything except when you need it to do something?

Reply
  • Hi,

    I do not see how it would be possible to add a callback at a later point. May I ask why you want to do that? In what use case is that useful? Could you not add a callback in the first place, but make it return without doing anything except when you need it to do something?

Children
  • Hi Einar,

    Thanks for your quick response. If the central changes data of of the peripheral characteristics, I would like to e.g. turn on a LED on the peripheral device.

    Can you give an example, how you would add this callback in a later moment?

    It would be nice, if I could set this callback during runtime, independent of the service implementation.

  • Felix41382 said:
    Thanks for your quick response. If the central changes data of of the peripheral characteristics, I would like to e.g. turn on a LED on the peripheral device.

    I see.

    Felix41382 said:

    Can you give an example, how you would add this callback in a later moment?

    It would be nice, if I could set this callback during runtime, independent of the service implementation.

    I am not able to see how that would be possible. I suggest you do as I proposed in my previous post: Have the callback there from the start, but do nothing in it when not relevant.

  • Such a shame. Anyway, thanks for you help!

Related