Hi,
I am making an application on nRF52840 (SDK 2.2.0) as a BLE peripheral.
When something happens at this peripheral, the application will notify a value to the connected manager.
Below mycode.c:
void chrc_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{
LOG_INF("value: %d", value);
bool notif_enabled = (value == BT_GATT_CCC_NOTIFY);
LOG_INF("Notification: %s", notif_enabled ? "enabled" : "disabled");
LOG_INF("Perm: %d", attr->perm);
bt_gatt_service_val val = btgatservice
}
BT_GATT_SERVICE_DEFINE(remote_srv,
BT_GATT_PRIMARY_SERVICE(BT_UUID_REMOTE_SERVICE),
BT_GATT_CHARACTERISTIC(BT_UUID_REMOTE_BUTTON_CHAR,
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
BT_GATT_PERM_READ,
read_characteristic_cb, NULL, NULL),
BT_GATT_CCC(chrc_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
BT_GATT_CHARACTERISTIC(BT_UUID_REMOTE_MESSAGE_CHAR,
BT_GATT_CHRC_WRITE_WITHOUT_RESP,
BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, NULL, on_written, NULL));
void notify_value(uint8_t value)
{
struct bt_gatt_notify_params params =
{
.attr = &remote_srv.attrs[2],
.data = &value,
.len = sizeof(value),
.func = on_notified,
};
bt_gatt_attr_read()
// ! read the attribute value before sending, to make sure no `err`
int err = bt_gatt_notify_cb(current_conn, ¶ms);
button_value = value;
}
Everything works fine.
Now, in `notify_value()`, before `bt_gatt_notify_cb()`, I want to read the attribute value before notifying. This is to make sure I only notify when the attribute's notification is enabled.
How should I do that?
Regards,