Restart advertising fails with -ENOMEM

We have thousands of devices live in production and we sometimes encounter the situation that we cannot restart bluetooth advertising anymore after a connection attempt.

bt_le_adv_start will then return -12 (-ENOMEM). The only way to get out of this situation is a software reset of the device. This is done automatically now, so customer impact is limited. However we would really like to know why this is happening sometimes. 

We use the ble peripheral role and we allow only one connection (CONFIG_BT_MAX_CONN=1). bt_le_adv_start is called in a separate thread, so not in the connection callbacks.

The firmware is based on nRF Connect 3.1.1

Please find relevant code below:
BT_CONN_CB_DEFINE(conn_callbacks) = {
    .connected          = ble_connected,
    .disconnected       = ble_disconnected,
    .recycled           = ble_recycled};
    
static void ble_connected(bt_conn *conn, uint8_t err)
{
    if(current_connection != nullptr) {
        LOG_WRN("Already connected, unref old connection");
        bt_conn_unref(current_connection);
    }

    if(err != 0) {
        LOG_WRN("Connection failed (err %d), restart advertising", err);
        restart_advertising();
        return;
    }

    current_connection = bt_conn_ref(conn);
}

static void ble_disconnected(bt_conn *conn, uint8_t reason)
{
    if(current_connection != nullptr) {
        bt_conn_unref(current_connection);
        current_connection = nullptr;
    }
}

static void ble_recycled()
{
    LOG_INF("BLE recycled, restart advertising");

    restart_advertising();
}    


Any suggestions to fix this issue for real so we can remove the workaround?
Parents Reply Children
  • Hi  thanks for your response!

    I will investigate the ticket you mentioned. But it is still weird that you can only get out of this situation with a reset of the device, right? I can imagine that I will get errors if I try to start or update advertising when it is still busy, but I would expect it to be working again if I try a little bit later. That's not what happening, once I will get the -ENOMEM error, the only way to get out of it is a reset of the device. Is this a known issue? 

  • Hi Bert,

    So, it's not possible to restart advertising directly in the disconnected callback, as this callback is running in interrupt context.

    This could be worth a shot, but could you maybe try setting

    CONFIG_BT_MAX_CONN=4 

    Then check if you still get the error?

    -Priyanka

Related