This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
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

How can I close a open BLE connection properly from peripheral side

Hello,

in our final device, I want to give the user the opportunity, to close an opened BLE connection between our device and another smart device. This should be done by pushing a button. At the moment, if the button is pressed, I call the "closeBLEconnection" function.

uint32_t stopAdvertising(void){
uint32_t err_code;

err_code = sd_ble_gap_adv_stop();
	if(err_code != NRF_SUCCESS)
	{
  ble_dbg_printf("stop dvertising error code: %x\r", err_code);
	}

	return err_code;}

uint32_t closeBLEconnection(void){
	uint32_t err_code;

err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION);
	if(err_code != NRF_SUCCESS)
	{
  ble_dbg_printf("Connection close error code: %d\r", err_code);
	}
	err_code = stopAdvertising();
	
	return err_code;}

But if I use the functions like this, I will get NRF_ERRORS from both functions. Connection close returns with error code "7" and stop advertising function returns error code 8. How can I change the disconnection sequenze to get a proper result? It seems, that "BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION" is not a valid parameter for sd_ble_gap_disconnect!?

Regards, BTprogrammer

PS: I use the S120 softdevice as an peripheral.

Parents
  • Hi, yes I also tried "BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION" then I will get no error for the sd_ble_gap_disconnect function. But stopAdvertising still returns error 8. Another question for me is, what does nordic mean with "REMOTE_USER". The person that uses the device or the connected receiver? For my understanding, LOCAL_HOST would be the more logical value...

Reply
  • Hi, yes I also tried "BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION" then I will get no error for the sd_ble_gap_disconnect function. But stopAdvertising still returns error 8. Another question for me is, what does nordic mean with "REMOTE_USER". The person that uses the device or the connected receiver? For my understanding, LOCAL_HOST would be the more logical value...

Children
No Data
Related