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?

Parents
  • 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). 

  • Hi , thanks for your reply. Can the peripheral ends the connection with a timeout while is still sending data through notifications?

    Can you check the reply i did to Simonr about the same? it seems my variable that saves the pointer of the struct bt_conn * is not functioning properly. What are your thoughts about this?

    Regards!

  • The peripheral can disconnect at any time. But let's put that aside for a while then since you seem to have some other error there.

    If the address is not printed properly something is very wrong. Probably some memory corruption, but of a very strange kind. Are other examples working as expected for you?

    Perhaps log the address often and see when it gets corrupted. Or remove some parts of the code and see if the error still happens. If you can share a short example which reproduces the problem it would be easy to help you, but without that, we can just guess.

Reply
  • The peripheral can disconnect at any time. But let's put that aside for a while then since you seem to have some other error there.

    If the address is not printed properly something is very wrong. Probably some memory corruption, but of a very strange kind. Are other examples working as expected for you?

    Perhaps log the address often and see when it gets corrupted. Or remove some parts of the code and see if the error still happens. If you can share a short example which reproduces the problem it would be easy to help you, but without that, we can just guess.

Children
No Data
Related