This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reconnect after sd_ble_gap_disconnect

Hi

I am using the nRF52832DK and the BLE_App_Blinky.

I have a stable BLE connection to a phone and then I try to close the connection inside the nRF with sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);.

It do a disconnect, but right after it reconnects again by firing BLE_GAP_EVT_PHY_UPDATE_REQUEST.

Why is this event generated? Do I have some settings that makes it reconnect or should I use another parameter instead of BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION?

Regards,

Morten

  • Hi Morten, 

    Could you let me know at which stage of the connection (for example if it's immediately right after connection) did you call sd_ble_gap_disconnect() ? 

    Could you elaborate more on "but right after it reconnects again by firing BLE_GAP_EVT_PHY_UPDATE_REQUEST." ? You meant the nRF52 got connected to the phone (BLE_GAP_EVT_CONNECTED) and then you receive the event BLE_GAP_EVT_PHY_UPDATE_REQUEST? 

    If your device (nRF52) start to advertises after it disconnected, there is a chance that the phone automatically re-connect to it. 

    I would suggest to capture a sniffer trace so we get to understand what happens over the air. 

  • I do a connect and then it triggers a BLE_GAP_EVT_PHY_UPDATE_REQUEST. Then the connection runs for 5 minutes before I call sd_ble_gap_disconnect(). This triggers the BLE_GAP_EVT_DISCONNECTED, so the connection is closed.

    A few milliseconds after that it reconnects which again triggers BLE_GAP_EVT_PHY_UPDATE_REQUEST.

    I would like to close down the connection entirely, so that the phone cannot reconnect to it after I disconnect.

    If I do a reset of the system, then it starts up with advertising disabled and the phone doesn't connect until I start advertising. I would think it is possible to shut it down without a reset?

  • Hi again Morten, 

    If you don't want to advertise after you disconnect you can turn off config -> ble_adv_on_disconnect_disabled when you initialize advertising in advertising_init() (if you use ble_advertising module).

    If you don't use ble_advertising module, then there must be a call some where in the code for advertising start when the application handle BLE_GAP_EVT_DISCONNECTED event.

  • Thanks for your reply.

    I haven't had time to test it yet. But if I turn off config -> ble_adv_on_disconnect_disabled does that mean that it also will not reconnect if the phone gets out of reach and then back into reach?

    The thing I want to accomplish is that a phone connects to the nRF. When the nRF is finished sending data to the phone, the nRF disconnect the link to the phone.

  • Hi Morten, 
    In that case you would need to handle the re-advertising on your own. 
    What you need to do is to set a flag when the nRF52 actively disconnect the connection. In that case you don't re-advertise (start advertising after disconnected). If the flag is not set, then you can start advertise in the BLE_GAP_EVT_DISCONNECTED  event.

    To be able to handle the task manually you need to disable ble_adv_on_disconnect_disabled. 

Related