Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

How to stop advertising and go into a non-connectable state?

I want to stop advertising and be in a non-connectable state, if someone connected sends the wrong data through a characteristic three times in a row. I will start a timer, and after x amount of seconds, start advertising again for people to connect.

I've tried calling sd_ble_gap_disconnect() and sd_ble_gap_adv_stop(), but the device goes straight into advertising again. How can I stop this?

// Stop advertising
sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
m_conn_handle = BLE_CONN_HANDLE_INVALID;
NRF_LOG_INFO("Stopping advertising");
sd_ble_gap_adv_stop(m_advertising.adv_handle)

  • Hi Jerome, 

    We would need to have a look on how you start advertising. Did you use ble_advertising module ? Or you use the sd_ble_gap_adv directly ? 
    If you use ble_advertising, you can change ble_adv_on_disconnect_disabled configuration in init.config when you setting up advertising in advertising_init(). 

    If you use the softdevice API directly you need to check you code when you handle the BLE_GAP_EVT_DISCONNECTED event, usually in ble_evt_handler() . Most likely the start of new advertising after disconnected is located there.  

    Calling sd_ble_gap_adv_stop() right after sd_ble_gap_disconnect() doesn't work because at that moment the link is not actually disconnected yet. Advertising will restarted when BLE_GAP_EVT_DISCONNECTED event is triggered. 

Related