Hi in the code below I successfully register multiple custom services (m_cus and m_cus2) using NRF_SDH_BLE_OBSERVERS(). In my original code when notifications is turned on for custom characteristic of m_cus the characteristic value would increment every second. However, now I notice that the characteristic value for m_cus no longer increments every second when notifications is turned on. If I turn on the notifications for the characteristic of m_cus2, strangely it will increment.
#main.c
BLE_CUS_DEF(m_cus, 0);
BLE_CUS_DEF(m_cus2, 1);
static void notification_timeout_handler(void * p_context)
{
UNUSED_PARAMETER(p_context);
ret_code_t err_code;
// Increment the value of m_custom_value before notifying it.
m_custom_value++;
if(notif_bool == 1){
err_code = ble_cus_custom_value_update(&m_cus, m_custom_value);
APP_ERROR_CHECK(err_code);
}
}
//ble_cus.h
#define BLE_CUS_DEF(_name, _cnt) \
static ble_cus_t _name[_cnt]; \
NRF_SDH_BLE_OBSERVERS(_name ## _obs, \
BLE_HRS_BLE_OBSERVER_PRIO, \
ble_cus_on_ble_evt, &_name, _cnt)
I further check the definition for ble_cus_custom_value_update() and it is supposed to only modify the characteristic value for the custom service passed into parameter 'p_cus'. In the 'notification_timeout_handler' code above, the event handler code only passes in m_cus into the 'p_cus' parameter of ble_cus_custom_value_update().
sd_ble_gatts_value_set(p_cus->conn_handle,
p_cus->custom_value_handles.value_handle,
&gatts_value);
sd_ble_gatts_hvx(p_cus->conn_handle, &hvx_params);
If m_cus has a different conn_handle and custom_value_handles.value_handle, then m_cus2 the custom characteristic value updates should not be mixed up between different custom services/characteristics.
However, right now the most confusing issue is why m_cus2 is getting its custom characteristic value incremented after notifications are turned on, when this behavior was supposed to be for m_cus only. Any suggestions? Thank you.
Project files and code attached below.