otSetStateChangedCallback gives OT_ERROR_NO_BUFS error

When I call the function after connecting to the thread network I get a NoBufs error:

openthread_context *threadContext = openthread_get_default_context();
error = otSetStateChangedCallback(gInstance, HandleThreadStateChanged, threadContext);
if (error != OT_ERROR_NONE) {
LOG_ERR("Failed to set state changed callback: %s", otThreadErrorToString(error));
return;
}
My handler:
void HandleThreadStateChanged(otChangedFlags flags, void *context)
{
    if (flags & OT_CHANGED_THREAD_ROLE)
    {
        otDeviceRole role = otThreadGetDeviceRole(static_cast<otInstance *>(context));
        LOG_INF("Thread role changed: %d", role);

        switch (role)
        {
        case OT_DEVICE_ROLE_DISABLED:
            LOG_INF("Thread network is disabled");
            break;
        case OT_DEVICE_ROLE_DETACHED:
            LOG_INF("Thread network is detached");
            break;
        case OT_DEVICE_ROLE_CHILD:
            LOG_INF("Thread network is connected as a child");
            break;
        case OT_DEVICE_ROLE_ROUTER:
            LOG_INF("Thread network is connected as a router");
            break;
        case OT_DEVICE_ROLE_LEADER:
            LOG_INF("Thread network is connected as a leader");
            break;
        default:
            LOG_INF("Unknown Thread role");
            break;
        }
    }
}

I'm using an nrf52840-DK and am guessing that it needs more resources, does anyone know which configs to update? 
  • Hello,

    Can you please try to set the handler before you join the thread network? That is, before you start the network provisioning?

    If that doesn't work, can you please upload the application that you are working on, so that I can have a look?

    Alternatively, you can look at how it is done in the coap_client sample found in NCS\samples\openthread\coap_client, in src\coap_client_utils.c -> openthread_state_changed_cb_register().

    Best regards,

    Edvin

Related