Read / Write lwm2m resource instance

Hi all,

I'm implementing a lwm2m client on a NRF9160 and have a problem with read/write resource instances. I use Leshan demo server to test the object and a came across a problem on ‘Remote SIM Provisioning’ object 504. When I read ‘504/0/11’ it reads all instances of this resource, but when I try to read a single instance of this resource, got an error. See images blow

Read resource insntances OK

Read single resource instace NOK.

This is my first problem, because after i need to write.

Can anybody help?

Parents
  • Hi Charlie,

    The changes in order to read a specific resource instance are minor.

    In the file 'lwm2m_engine.c' function 'lwm2m_read_handler'

    Need to change 2 thing

    first <> from this

    for (i = 0; i < loop_max; i++) {
    		if (res->res_instances[i].res_inst_id ==
    		    RES_INSTANCE_NOT_CREATED) {
    			continue;
    		}
    
    		if (res->res_inst_count > 1) {
    			msg->path.res_inst_id =
    				res->res_instances[i].res_inst_id;
    		}
    
    		/* setup initial data elements */
    		data_ptr = res->res_instances[i].data_ptr;
    		data_len = res->res_instances[i].data_len;

    to this

    for (i = 0; i < loop_max; i++) {
    		if (res->res_instances[i].res_inst_id ==
    		    RES_INSTANCE_NOT_CREATED) {
    			continue;
    		}
    
    		if (res->res_inst_count > 1) {
                if ((msg->path.level > 3U) && 
                    (res->res_instances[i].res_inst_id != msg->path.res_inst_id)) {
                    continue;
                }
    			msg->path.res_inst_id =
    				res->res_instances[i].res_inst_id;
    		}
    
    		/* setup initial data elements */
    		data_ptr = res->res_instances[i].data_ptr;
    		data_len = res->res_instances[i].data_len;

    second <> From this

        if (res->multi_res_inst) {
            engine_put_end_ri(&msg->out, &msg->path);
    		msg->path.res_inst_id = res_inst_id_tmp;
    	}
    
    	return 0;
    }

    To

        if (res->multi_res_inst) {
            if (msg->path.level < 4U) {
              engine_put_end_ri(&msg->out, &msg->path);
            }
    		msg->path.res_inst_id = res_inst_id_tmp;
    	}
    
    	return 0;
    }

Reply
  • Hi Charlie,

    The changes in order to read a specific resource instance are minor.

    In the file 'lwm2m_engine.c' function 'lwm2m_read_handler'

    Need to change 2 thing

    first <> from this

    for (i = 0; i < loop_max; i++) {
    		if (res->res_instances[i].res_inst_id ==
    		    RES_INSTANCE_NOT_CREATED) {
    			continue;
    		}
    
    		if (res->res_inst_count > 1) {
    			msg->path.res_inst_id =
    				res->res_instances[i].res_inst_id;
    		}
    
    		/* setup initial data elements */
    		data_ptr = res->res_instances[i].data_ptr;
    		data_len = res->res_instances[i].data_len;

    to this

    for (i = 0; i < loop_max; i++) {
    		if (res->res_instances[i].res_inst_id ==
    		    RES_INSTANCE_NOT_CREATED) {
    			continue;
    		}
    
    		if (res->res_inst_count > 1) {
                if ((msg->path.level > 3U) && 
                    (res->res_instances[i].res_inst_id != msg->path.res_inst_id)) {
                    continue;
                }
    			msg->path.res_inst_id =
    				res->res_instances[i].res_inst_id;
    		}
    
    		/* setup initial data elements */
    		data_ptr = res->res_instances[i].data_ptr;
    		data_len = res->res_instances[i].data_len;

    second <> From this

        if (res->multi_res_inst) {
            engine_put_end_ri(&msg->out, &msg->path);
    		msg->path.res_inst_id = res_inst_id_tmp;
    	}
    
    	return 0;
    }

    To

        if (res->multi_res_inst) {
            if (msg->path.level < 4U) {
              engine_put_end_ri(&msg->out, &msg->path);
            }
    		msg->path.res_inst_id = res_inst_id_tmp;
    	}
    
    	return 0;
    }

Children
No Data
Related