In a project I worked on using softdevice s110 v. 7.1.0, if the receiver hadn't enabled notifications, sd_ble_gatts_hvx would return an error, so I used the following construct to check whether notifications had been enabled before attempting to send a notification:
uint32_t ble_mysvc_notify_button(ble_mysvc_t *p_mysvc)
{
uint32_t err_code = NRF_SUCCESS;
ble_gatts_hvx_params_t params;
uint16_t cccdv;
ble_gatts_value_t gatts_value;
ble_gatts_value_t cccd_value;
cccd_value.len = sizeof(ble_gatts_value_t);
cccd_value.offset = 0;
sd_ble_gatts_value_get(p_mysvc->conn_handle, p_mysvc->button_char_handles.cccd_handle, &cccd_value);
cccdv = (uint16_t)*(cccd_value.p_value);
if ((cccdv & BLE_GATT_HVX_NOTIFICATION) != 0)
{
uint16_t len = 1;
memset(¶ms, 0, sizeof(params));
params.type = BLE_GATT_HVX_NOTIFICATION;
params.handle = p_mysvc->button_char_handles.value_handle;
params.p_data = &(p_mysvc->button_state);
params.p_len = &len;
return sd_ble_gatts_hvx(p_mysvc->conn_handle, ¶ms);
}
return NRF_SUCCESS;
}
However, this doesn't seem to be working in s110 v. 8.0.0; (cccdv & BLE_GATT_HVX_NOTIFICATION) intermittently returns true or false, regardless of whether notifications are enabled. Moreover, it seems that sd_ble_gatts_hvx no longer actually returns an error if the receiver hasn't enabled notifications.
My questions are:
- should this, in fact, work to detect whether notifications have been enabled?
- has v. 8.0.0 changed such that it is no longer necessary to perform this test?
Thanks in advance for any advice.