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

Prevent BLE connection

I'm having a advertising device and then I want to stop advertising and prevent BLE connection from device that would have received the advertisement. It seems to work by using this:

err_code = sd_ble_gap_adv_stop(m_advertising.adv_handle);
nrf_sdh_disable_request();

Problem appears when I want to start advertising again. When I using this:

err_code = nrf_sdh_enable_request();
APP_ERROR_CHECK(err_code);

err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);

In ble_advertising_start(...) sd_ble_gap_adv_set_configure(...) return 0x3001 (having a doubt about the error code but can't reproduce right now). How should I proceed to prevent BLE connection. Should I force disconnection on connect event or there's a nicer wait to do it? Using s132 SDK 15.3

Thank you for your help!

Parents Reply Children
  • I called nrf_sdh_disable_request() to disable the Softdevice and prevent Bluetooth connection from device which had received the advertisement before I stop advertising. Since I want to prevent Bluetooth connection as well it seems that nrf_sdh_disable_request() service this purpose.

    The first issue is to prevent Bluetooth connection from device that have advertisement data.

  • Frederic said:
    prevent Bluetooth connection from device which had received the advertisement before I stop advertising

     If a device connects in this time window, then maybe you could instead try to set a flag/variable, and when this flag is set to true, you will on the BLE_GAP_EVT_CONNECTED event have a if-test that could disconnect the device if it connected ?

    Snippet:

    .
    .
    .
    case BLE_GAP_EVT_CONNECTED:
        if(prevent_connection)
        {
            err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
        }
    .
    .
    .
    .
    .
    .
    
    

  • ok I will do this. I though there were a easy was to prevent connection in the Softdevice in such situation but I will follow your advice and disconnect the remote device in the BLE_GAP_EVT_CONNECTED event.

    Tahnk a lot!

Related