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

I have a question about sd_ble_gap_disconnect() problem.

Hello!

I have created a function that cancels the connection by pressing and holding the button when Bluetooth is connected.

static void app_button_event_generator(void)
{
  ret_code_t err_code;

  if ((pressed_duration >= 3000) && (pressed_duration < 10000000)) //over 3sec
  { 
    NRF_LOG_INFO("Button pressed for 3sec...");
    printf("Long button, Pairing reset!\n");
    do_play_buzzer(); 

    err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); //disconnect pairing
    APP_ERROR_CHECK(err_code);
  }

  app_button_init_time_variable();
}

The use of this code allows the connection to be terminated by pressing the button when the Bluetooth connection is successful.

But there's a problem.
If I use this feature when Bluetooth is not connected yet, the board will stop completely.

How do I prevent errors when using this feature when Bluetooth is not connected yet?  

Thank you.

Parents Reply Children
Related