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

p_client->is_notification_enabled value keeps enable when disconnect and reconnect.

Hi, Nordic,

I am using the ble_app_uart example in the SDK15.2.

I find a issue that when the device,  which p_client->is_notification_enabled is already true, is disconnect by the phone, then reconnect again without enabling notification action,the device's p_client->is_notification_enabled value still keeps true, but at this condition, when sending the data by using the  ble_nus_data_send function, will cause Fatal error, err_code= 0x3401.

I want to know how to get the real state of the notification.

TKS!

  • Hi Zhong, 

    the CCCD value of the TX characteristic should be reset to 0x00 when you disconnect 

    However, you could check the TX characteristics CCCD value on connection by adding the following code to on_connect() in ble_nus.c

     /* Check the hosts CCCD value to inform of readiness to send data using the TX characteristic */
        memset(&gatts_val, 0, sizeof(ble_gatts_value_t));
        gatts_val.p_value = cccd_value;
        gatts_val.len     = sizeof(cccd_value);
        gatts_val.offset  = 0;
    
        err_code = sd_ble_gatts_value_get(p_ble_evt->evt.gap_evt.conn_handle,
                                          p_nus->tx_handles.cccd_handle,
                                          &gatts_val);
    
        if ((err_code == NRF_SUCCESS)     &&
            (p_nus->data_handler != NULL) &&
            ble_srv_is_notification_enabled(gatts_val.p_value))
        {
            if (p_client != NULL)
            {
                p_client->is_notification_enabled = true;
            }
        }else{
            p_client->is_notification_enabled = false;
        }
        

Related