This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

I combined Bonding in the UART example, but after autoconnect, the notification is not enabled.

I applied Bonding to the UART example(ble_app_uart).

Bonding combined with the UART example works well, but there is one problem.

1. I did Bonding first.
2. After that I set Notification Enable.
3. Rebooted the device and reconnected to the application using Auto connect.
4. On the NRF Connect, it is marked as Notification Enable, but the device did not send the notification.

I checked the code point where the problem was occurring.

I found that is_notification_enabled is still false after auto-connect.

uint32_t ble_nus_string_send(ble_nus_t * p_nus, uint8_t * p_string, uint16_t length)

{
ble_gatts_hvx_params_t hvx_params;

VERIFY_PARAM_NOT_NULL(p_nus);

if ((p_nus->conn_handle == BLE_CONN_HANDLE_INVALID) || (!p_nus->is_notification_enabled))
{
return NRF_ERROR_INVALID_STATE;
}

if (length > BLE_NUS_MAX_DATA_LEN)
{
return NRF_ERROR_INVALID_PARAM;
}

memset(&hvx_params, 0, sizeof(hvx_params));

hvx_params.handle = p_nus->rx_handles.value_handle;
hvx_params.p_data = p_string;
hvx_params.p_len = &length;
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;

return sd_ble_gatts_hvx(p_nus->conn_handle, &hvx_params);
}

I tried to ignore this part of the conditional statement, but then the device didn't work properly.

If possible, please help resolve the problem.

  • This is my code in ble_nus.c

  • What SDK version is this ?

    In the latest SDK versions we read the CCCD value in the function on_connect() with sd_ble_gatts_value_get(), and then we update the variable is_notification_enabled. Some SDKs might have a bug here though, ref this post.

    Snippet:

  • SDK 12.3, Softdevice is S130 2.0.1

  • Ok, then if you want is_notification_enabled to be true after auto-connect, then you need to implement the functionally shown in the snippet. You might also need to bond to the device for it to work.