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

BLE disconnection

Hi,

I'm using NRF52840, and my application connects with BLE mobile application. After a minute, connection is lost.

I tried to find which functions called sd_ble_gap_disconnect, but I didn't find.

I think the reason may be the min and max connection interval. What are the recommended values?

Thanks!

Parents
  • I think the reason may be the min and max connection interval. What are the recommended values?

     That may in fact be the case. What does your log from the nRF52840 say?

    Perhaps you can add this line to your BLE_GAP_EVT_DISCONNECTED event in the ble_evt_handler()

    NRF_LOG_INFO("disconnect reason %d", p_ble_evt->evt.gap_evt.params.disconnected.reason);

    As you may or may not know, it is the central (typically the phone) that decides the connection parameters. If this is not within the desired connection parameters of the peripheral, it can request new connection parameters, but they may be declined. Then the peripheral can choose whether to accept these connection parameters, or to disconnect. 

    Basically it will try to update the connection interval 3 times (by default), and then, based on disconnect_on_fail it will either disconnect, or stay connected:

    static void update_timeout_handler(void * p_context)
    {
        uint32_t                     conn_handle = (uint32_t)p_context;
        ble_conn_params_instance_t * p_instance  = instance_get(conn_handle);
    
        if (p_instance != NULL)
        {
            // Check if we have reached the maximum number of attempts
            if (p_instance->update_count < m_conn_params_config.max_conn_params_update_count)
            {
                bool update_sent = send_update_request(conn_handle, &p_instance->preferred_conn_params);
                if (update_sent)
                {
                    p_instance->update_count++;
                }
            }
            else
            {
                p_instance->update_count = 0;
    
                // Negotiation failed, disconnect automatically if this has been configured
                if (m_conn_params_config.disconnect_on_fail)
                {
                    ret_code_t err_code;
    
                    err_code = sd_ble_gap_disconnect(conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
                    ...

    The default value of disconnect_on_fail depends on what SDK version you are using. In 15.3.0 it looks like it is set to false by default, but that may vary from example to example. 

    So what does your log say? And what is your disconnect_on_fail? 

    And by the way, what is your conn_interval min and max setting? Try setting it to 7.5 and 30 ms. That should cover the connection interval of most phones.

    Best regards,

    Edvin

Reply
  • I think the reason may be the min and max connection interval. What are the recommended values?

     That may in fact be the case. What does your log from the nRF52840 say?

    Perhaps you can add this line to your BLE_GAP_EVT_DISCONNECTED event in the ble_evt_handler()

    NRF_LOG_INFO("disconnect reason %d", p_ble_evt->evt.gap_evt.params.disconnected.reason);

    As you may or may not know, it is the central (typically the phone) that decides the connection parameters. If this is not within the desired connection parameters of the peripheral, it can request new connection parameters, but they may be declined. Then the peripheral can choose whether to accept these connection parameters, or to disconnect. 

    Basically it will try to update the connection interval 3 times (by default), and then, based on disconnect_on_fail it will either disconnect, or stay connected:

    static void update_timeout_handler(void * p_context)
    {
        uint32_t                     conn_handle = (uint32_t)p_context;
        ble_conn_params_instance_t * p_instance  = instance_get(conn_handle);
    
        if (p_instance != NULL)
        {
            // Check if we have reached the maximum number of attempts
            if (p_instance->update_count < m_conn_params_config.max_conn_params_update_count)
            {
                bool update_sent = send_update_request(conn_handle, &p_instance->preferred_conn_params);
                if (update_sent)
                {
                    p_instance->update_count++;
                }
            }
            else
            {
                p_instance->update_count = 0;
    
                // Negotiation failed, disconnect automatically if this has been configured
                if (m_conn_params_config.disconnect_on_fail)
                {
                    ret_code_t err_code;
    
                    err_code = sd_ble_gap_disconnect(conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
                    ...

    The default value of disconnect_on_fail depends on what SDK version you are using. In 15.3.0 it looks like it is set to false by default, but that may vary from example to example. 

    So what does your log say? And what is your disconnect_on_fail? 

    And by the way, what is your conn_interval min and max setting? Try setting it to 7.5 and 30 ms. That should cover the connection interval of most phones.

    Best regards,

    Edvin

Children
Related