Problem bl_conn_disconnect NRF52 - disconnection

Hi y'all.

I've been developing in Zephyr NRF52840. My code is based in Central_HR_Coded (SDK 2.6.1, Toolchain 2.7.0). I had some issues with the bt_conn_disconnect function. This function is being called after a command in the uart stack that triggers this function in this way:

ISR UART -> Work Queue (with k_work_summit) -> callback of disconnection request:

static void disconnection_request(void)
{
	if (curr_connection) {
        int err = bt_conn_disconnect(curr_connection, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
        if (err) {
            LOG_ERR("Disconnection failed (err %d)", err);
			send_err_data(FRONTEND_ERR_DISCONNECTION, err);
        } else {
            LOG_INF("Disconnection requested");
        }
    } else {
        LOG_INF("No active connection to disconnect");
    }
}

curr_connection variable is define using bt_conn_le_create. The issue is I'm getting Error -128 in the bt_conn_disconnect function, which means literally ENOTCONN /* Socket is not connected */.

This is happening because curr_connection.state property is retrieving BT_CONN_DISCONNECTED, but i can assure that both devices are connected due to notifications in a service. I already discard the fact I'm possibly using this function in a interrupt routine. (105524/bt_conn_disconnect-got-errors).

I want to know why this error is popping and also how can i workaround it. What gives?

  • I see. To me it sounds like the application is doing something wrong. But it is very hard to tell from the code you have shared.

    That said, if the connection actually is already closed (perhaps because a timeout or the other end terminated it), and you call bt_conn_disconnect, and it returns -ENOTCONN, then it is very much expected and not an error that has to be handled (or even reported). 

Related