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

How to disconnect Peripheral device after sending a packet to central using sd_ble_gap_disconnect()

Hi Nordic Team,

     Requirement-

     Connect->Send 1 packet->Disconnect->Connect...

 

     I am Sending a data packet to central using Timer handler and trying to disconnect using sd_ble_gap_disconnect() in same timer handler.

     But i am getting <error> app: ERROR 12290 [Unknown error code] using disconnect function in handler.

     Below is the snippet

    /*Timer Handler */
static void HT_notification_timeout_handler(void * p_context)
{
    bool erase_bonds;
     ret_code_t err_code;
     UNUSED_PARAMETER(p_context);

     sprintf(THL_data,"%d%d%d",10,20,30);
     printf("thl_value %s\n",THL_data);
     err_code =  ble_THL_value_update(&m_cus, &THL_data);
     APP_ERROR_CHECK(err_code);


     err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
     APP_ERROR_CHECK(err_code);
}

Is it correct to use disconnect function in timer handler ?, or where can i use this function to disconnect after sending a packet to central.

I am using nrf52832 board and sdk 15.2.0

regards

  • Hi,

    The error code 12290 = 0x3002 is:

    #define BLE_ERROR_INVALID_CONN_HANDLE    (NRF_ERROR_STK_BASE_NUM+0x002) /**< Invalid connection handle. */

    In other words it seems that m_conn_handle is wrong in this case. Maybe you are already disconnected?

    You should likely want some delay between Send 1 packet->Disconnect, either a fixed delay (e.g. 100ms), or wait for notification sent event before disconnect.

    Best regards,
    Kenneth

Related