LwM2M Custom Opaque Object Error


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

#include <zephyr/logging/log.h>
#include <string.h>
#include <zephyr/init.h>

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

#define OBJECT_ID 7276

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

#define RESOURCES_MAX_ID            1

#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[] = {

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;

    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;


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,

  • Hi,

    I have tried adding your code to the lwm2m_client but I could not see the object being created on the server. 

    Could you provide your project so I could try to reproduce your issue? If you have some sensitive information that you would not like to share publicly, please let me know and I'll make the case private.

    Best regards,

  • Hi Dejan,

    I have added this object to asset tracker project. Let me try and clean it up a little bit and I will attach it to the ticket.

    Kind Regards,

  • Hi,

    ibiglari said:
    I have added this object to asset tracker project. Let me try and clean it up a little bit and I will attach it to the ticket.

    Thank you. Please let me know when you attach the project.

    Do you need this case to be private?

    Best regards,

  • Hi,

    I don't think there is a need to make the ticket private. The project I am working on is a fork of Asset Tracker v2, trying to proxy SUPL data through my own LwM2M server.

    The issue is, I am not sure how to simulate SUPL data via a public Leshan server. My own server sends SUPL data in response to LwM2M object 33625. The project is attached and you need to use `aeroluminate.conf` Kconfig fragment.

    I have also attached a log file which shows when the error happens. Line 479 of the log file shows the error message. If you look at the source code, the error occurs after the final call to my callback method.

    If you want to test the code, I'd need to add your device's IMEI to my server. In that case you might want to convert the ticket to private so that the IMEI is not public.

    Kind Regards,

  • Hi,

    Just to clarify, I am trying to understand why that error is being triggered. Unfortunately it is not documented. I understand that it is very likely that either my server, or the modifications I have made to Asset Tracker source code are the root cause of this error. Perhaps a member of your LwM2M team could shed a light on what can cause this error to be triggered?

    Kind Regards,