How to disconnect central(Mobile App) from NRF52(Both central and Peripheral) using ble_app_hrs_rscs_relay example

Hello Team, 

I am working on the ble_app_hrs_rscs_relay example, in which NRF act both as a central and peripheral. My peripheral is a heart sensor (Polar H10) and my central is Mobile App. I have successfully disconnected the peripheral (Polar H10) by short pressing a button by calling sd_ble_gap_disconnect(m_conn_handle_hrs_c, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); function, but I am unable to disconnect the central (Mobile App) by calling sd_ble_gap_disconnect(m_advertising.adv_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); Is this the correct connection handler I have passed here? I am confused about the connection handler(which is to be passed in the disconnect function) for the central (mobile app). I am stuck with this issue for the last 7 days. Any help regarding this issue will be highly appreciated. I am using SDK 17.02 and soft devices S140.

Actually, I want to disconnect both peripheral and central from the NRF52 device by short pressing of a button, I come back to functional by pressing the same button again.

  • Disconnecting simply involves calling sd_ble_gap_disconnect() with the connection handle for the connection you want to disconnect from. This is the same for central and peripheral links. And the connection handle you get with the BLE_GAP_EVT_CONNECTED event, and all subsequent events that involve that connection. Similarly, and API call you make that involves a connection has the connection handle as an input parameter, so that you can tell the stack which connection you are operating on (in case there are more).

    Is this the correct connection handler I have passed here?

    I do not see enough of your code to day. If this is the connection handle you got from the BLE_GAP_EVT_CONNECTED, then yes. If this is some other value you got from somewhere else, it is not correct. If you can have multiple connections concurrently (which is likely as I see your device can act both as a central and peripheral - ref old thread), then you may have multiple connection handles and must keep track of them. You can for instance make an array of handles, and if you want to disconnect form all, iterate through it and call sd_ble_gap_disconnect() for each.

Related