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

[BLE] why restart advertising after disconnect?

Hi, 

My project is combined 'Multi-link Central Example' and 'ble_app_uart', so that it is a central that can be connected to multiple peripherals and a peripheral that can be connected to a single central.

When I disconnect from the central which is mobile phone, it immediately restarts advertising. 

(This is BLE_GAP_EVT_DISCONNECTED case in ble_advertising_on_ble_evt function.) 

static void on_disconnected(ble_advertising_t * const p_advertising, ble_evt_t const * p_ble_evt)
{
    uint32_t ret;

    p_advertising->whitelist_temporarily_disabled = false;


    if (p_ble_evt->evt.gap_evt.conn_handle == p_advertising->current_slave_link_conn_handle &&
        p_advertising->adv_modes_config.ble_adv_on_disconnect_disabled == false)
    {
       ret = ble_advertising_start(p_advertising, BLE_ADV_MODE_DIRECTED_HIGH_DUTY);
       if ((ret != NRF_SUCCESS) && (p_advertising->error_handler != NULL))
       {
           p_advertising->error_handler(ret);
       }
    }
}

1. my question is, what is meaning of

" if (p_ble_evt->evt.gap_evt.conn_handle == p_advertising->current_slave_link_conn_handle &&
       p_advertising->adv_modes_config.ble_adv_on_disconnect_disabled == false) "

and why it restart advertising?

And, when it restarts advertising because of above code part, BLE_GAP_EVT_DISCONNECTED case in the ble_evt_handler is not triggered. 

(but it triggered well if I erase restart advertising code part..) 

2. Does this mean that it didn't disconnected properly? Why this problem happening?

BR,

lyrics

Parents
  • Hi Lyrics,

    1. my question is, what is meaning of

    " if (p_ble_evt->evt.gap_evt.conn_handle == p_advertising->current_slave_link_conn_handle &&
           p_advertising->adv_modes_config.ble_adv_on_disconnect_disabled == false) "

    and why it restart advertising?

    The reason the advertising module supports automatically starting to advertise upon a disconnect is that this is a very common scenario. However this is configurable and if you do not want it, you can disable it. Looking at the code snippet you posed, you see the ble_adv_on_disconnect_disabled  field is what is relevant here. This can be set in the configuration struct before you call ble_advertising_init(), as is demonstrated in <SDK 17.0.2>\examples\ble_peripheral\experimental\ble_app_cgms\main.c. You can also set it at a later point if you want it normally on, but to disable it at a specific point, as demonstrated in for instance <SDK17.0.2>\examples\ble_peripheral\ble_app_buttonless_dfu\main.c.

    And, when it restarts advertising because of above code part, BLE_GAP_EVT_DISCONNECTED case in the ble_evt_handler is not triggered. 

    (but it triggered well if I erase restart advertising code part..) 

    2. Does this mean that it didn't disconnected properly? Why this problem happening?

    I did not get that. You should always get the BLE_GAP_EVT_DISCONNECTED if there as been a disconnect. Can you explain in more detail? Where do you look for the event, and in what situation? Please elaborate. 

Reply
  • Hi Lyrics,

    1. my question is, what is meaning of

    " if (p_ble_evt->evt.gap_evt.conn_handle == p_advertising->current_slave_link_conn_handle &&
           p_advertising->adv_modes_config.ble_adv_on_disconnect_disabled == false) "

    and why it restart advertising?

    The reason the advertising module supports automatically starting to advertise upon a disconnect is that this is a very common scenario. However this is configurable and if you do not want it, you can disable it. Looking at the code snippet you posed, you see the ble_adv_on_disconnect_disabled  field is what is relevant here. This can be set in the configuration struct before you call ble_advertising_init(), as is demonstrated in <SDK 17.0.2>\examples\ble_peripheral\experimental\ble_app_cgms\main.c. You can also set it at a later point if you want it normally on, but to disable it at a specific point, as demonstrated in for instance <SDK17.0.2>\examples\ble_peripheral\ble_app_buttonless_dfu\main.c.

    And, when it restarts advertising because of above code part, BLE_GAP_EVT_DISCONNECTED case in the ble_evt_handler is not triggered. 

    (but it triggered well if I erase restart advertising code part..) 

    2. Does this mean that it didn't disconnected properly? Why this problem happening?

    I did not get that. You should always get the BLE_GAP_EVT_DISCONNECTED if there as been a disconnect. Can you explain in more detail? Where do you look for the event, and in what situation? Please elaborate. 

Children
Related