LwM2M Custom Opaque Object Error

Hi,

I am following the tutorials on SDK documentation to create a new object type for communications between my LwM2M server and nrf9160. My object is a byte array, with only one instsance, and is defined as below:

/*
 * Copyright (c) 2022 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

#define LOG_MODULE_NAME net_lwm2m_obj_myobj
#define LOG_LEVEL CONFIG_LWM2M_LOG_LEVEL

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <string.h>
#include <zephyr/init.h>

#include "lwm2m_object.h"
#include "lwm2m_engine.h"

#define OBJECT_ID 7276
#define OBJECT_VERSION_MAJOR 1
#define OBJECT_VERSION_MINOR 0

/* myobj object resource IDs */
#define RESOURCE_DATA               0

#define RESOURCES_MAX_ID            1
#define RESOURCE_INSTANCE_COUNT (RESOURCES_MAX_ID)

#define myobj_BUFF_SIZE  1024

/* Storage variables to hold myobj values. */
static char data[myobj_BUFF_SIZE];

static struct lwm2m_engine_obj object;
static struct lwm2m_engine_obj_field fields[] = {
    OBJ_FIELD_DATA(RESOURCE_DATA, RW, OPAQUE)
};

static struct lwm2m_engine_obj_inst inst;
static struct lwm2m_engine_res res[RESOURCES_MAX_ID];
static struct lwm2m_engine_res_inst res_inst[RESOURCE_INSTANCE_COUNT];

static struct lwm2m_engine_obj_inst *object_create(uint16_t obj_inst_id)
{
    int i = 0, j = 0;

    init_res_instance(res_inst, ARRAY_SIZE(res_inst));

    /* Initialize object instance resource data */
    INIT_OBJ_RES_DATA(RESOURCE_DATA, res, i, res_inst, j,
              data, sizeof(data));

    inst.resources = res;
    inst.resource_count = i;

    LOG_DBG("Created a myobj object: %d", obj_inst_id);
    return &inst;
}
static int object_init(const struct device *dev)
{
    struct lwm2m_engine_obj_inst *obj_inst = NULL;
    int ret = 0;

    object.obj_id = OBJECT_ID;
    object.version_major = OBJECT_VERSION_MAJOR;
    object.version_minor = OBJECT_VERSION_MINOR;
    object.is_core = false;
    object.fields = fields;
    object.field_count = ARRAY_SIZE(fields);
    object.max_instance_count = 1U;
    object.create_cb = object_create;
    lwm2m_register_obj(&object);

    ret = lwm2m_create_obj_inst(OBJECT_ID, 0, &obj_inst);
    if (ret < 0) {
        LOG_ERR("Create myobj object error: %d", ret);
        return ret;
    }

    return 0;
}

SYS_INIT(object_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);

From what I can see in the logs, the object is created and behaves as expected. My object is an opaque byte array which appears to be sent in chunks, via multiple calls to the callback I am registering for it. On the device side, I have no problem in receiving the chunks, concatenating them together, and using the data once last_block is true. However, once the callback function returns after processing the whole data (after the last call with last_block set to true), I see the below error in the output log:

[00:00:39.373,260] <err> net_lwm2m_message_handling: Cannot find block context

I've gone over the source code for LwM2M engine, and the only place I can find for this message is in handle_request() function (line 2051 in SDK v.2.2.0) in lwm2m_message_handling.c source file. Could you please advise what can cause this error to be raised?

Kind Regards,
Iman

Parents Reply Children
Related