Hi everyone,
How could I disable notifications from a characteristic when the peer is get disconnected from the the peripheral? My problem is that when notification are enabled and a disconnection occurs then notifications remains enabled. This leads to the problem that when peer connect again with the peripheral the notifications are enabled (because they were enabled before disconnection)
This is the function for handiling write events
static void on_write(ble_cus_t *p_cus, ble_evt_t const *p_ble_evt) {
ble_gatts_evt_write_t const *p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
static ble_cus_evt_t evt;
enum gatt_handles gatt_handle;
// Here we check if the handle that has been written matches the handle of the CCCD and that the value has the correct length (2bytes). For indications and notifications len must be 2
if ((p_evt_write->handle == p_cus->custom_value_handles.cccd_handle) && (p_evt_write->len == 2)) {
// CCCD written, call application event handler
if (p_cus->evt_handler != NULL) { // na - check that the event handler function is pointing somewhere (in our case on on_cus_evt function, see main.c)
gatt_handle = CCCD_HANDLE; // na - assign the CCCD_HANDLE value
// Here we need to check if the notification enabled or disabled
if (p_evt_write->data[0] == 0x01) {
evt.evt_type = BLE_CUS_EVT_NOTIFICATION_ENABLED;
} else if (p_evt_write->data[0] == 0x00) {
evt.evt_type = BLE_CUS_EVT_NOTIFICATION_DISABLED;
} else {
evt.evt_type = BLE_CUS_EVT_INVALID_INPUT;
NRF_LOG_INFO("Invalid State");
}
p_cus->evt_handler(p_cus, &evt, gatt_handle); // na - Call the application event handler.
}
}
}
This is the state when the peer is connected back with the peripheral. As you can see the CCCD value is 1. I want to be 0 (notifications disabled) when there is a reconnection.

How could I handle this?
Thanks in advance
Nick