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 Reply Children
  • Hi Charlie,

    I searched the code to see how the objects are created and replicated that for this object

    /* LWM2M object variables */
    static struct lwm2m_engine_obj remote_sim_provisioning;
    
    static struct lwm2m_engine_obj_field remote_sim_provisioning_fields[] = {
    	OBJ_FIELD_DATA(LWM2M_REMOTE_SIM_PROVISIONING_ICCID_ID, R, STRING),
    };

    After this, inicialized the object

    static int 
    UC_LWM2M_Remote_SIM_Provisioning_Init(const struct device *dev)
    {
    	/* Declare unused arguments */
    	ARG_UNUSED(dev);
    	
    	/* Create and register LwM2M object type */
    	remote_sim_provisioning.obj_id = LWM2M_REMOTE_SIM_PROVISIONING_ID;
    	remote_sim_provisioning.version_major = LWM2M_PROTOCOL_VERSION_MAJOR;
    	remote_sim_provisioning.version_minor = LWM2M_PROTOCOL_VERSION_MINOR;
    	remote_sim_provisioning.is_core = true;
    	remote_sim_provisioning.fields = remote_sim_provisioning_fields;
    	remote_sim_provisioning.field_count = ARRAY_SIZE(remote_sim_provisioning_fields);
    	remote_sim_provisioning.max_instance_count = LWM2M_REMOTE_SIM_PROVISIONING_INSTANCE_COUNT;
    	remote_sim_provisioning.create_cb = UC_LWM2M_Remote_SIM_Provisioning_Create;
    	lwm2m_register_obj(&remote_sim_provisioning);
    
    	return NRF_SUCCESS;
    }
    
    /* Initialiase LWM2M object type */
    SYS_INIT(UC_LWM2M_Remote_SIM_Provisioning_Init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);

    and this function is called when an instance is created

    static struct lwm2m_engine_obj_inst*
    UC_LWM2M_Remote_SIM_Provisioning_Create(uint16_t obj_inst_id)
    {
    	/* Initialise function variables */
    	int index, i = 0, j = 0;
    	
    	/* Only allow the default instance ID to be created */
    	if (LWM2M_REMOTE_SIM_PROVISIONING_DEFAULT_INSTANCE != obj_inst_id) {
    		LOG_ERR("Can not create instance %u for this object", obj_inst_id);
    		return NULL;
    	}
    
    	/* Check that there is no other instance with this ID */
    	for (index = 0; index < LWM2M_REMOTE_SIM_PROVISIONING_INSTANCE_COUNT; index++) {
    		if (inst[index].obj && inst[index].obj_inst_id == obj_inst_id) {
    			LOG_ERR("Can not create instance - already existing: %u", obj_inst_id);
    			return NULL;
    		}
    	}
    	
    	
    	/* Check if the maximum number of instances hasn't been reached */
    	if (index >= LWM2M_REMOTE_SIM_PROVISIONING_INSTANCE_COUNT) {
    		LOG_ERR("Can not create instance - no more room: %u", obj_inst_id);
    		return NULL;
    	}
    
    	/* Set default resource values */
    	memset(iccid[index], 0, ICCID_STRING_LENGTH);
    	
    	/* Zero-initialiase instance resource object */
    	(void)memset(res[index], 0, sizeof(res[index][0]) * ARRAY_SIZE(res[index]));
    	init_res_instance(res_inst[index], ARRAY_SIZE(res_inst[index]));
    
    	/* Initialise resource instance data */
    	INIT_OBJ_RES_MULTI_DATA(LWM2M_REMOTE_SIM_PROVISIONING_ICCID_ID, res[index], i, res_inst[index], j,
                    LWM2M_REMOTE_SIM_PROVISIONING_ICCID_INSTANCE_COUNT, true,
    		        &iccid[index], ICCID_STRING_LENGTH);
    
                    
    	inst[index].resources = res[index];
    	inst[index].resource_count = i;
    	
    	LOG_DBG("Created LwM2M Remote SIM Provisioning instance: %d", obj_inst_id);
    	
    	return &inst[index];
    }

    After all this, when connected to Leshan, a function is called to inicialize the object and resorce instance

    static void
    UC_LWM2M_Remote_SIM_Provisioning_InitInstance(struct k_work *work) {
    
    ...
    
        return_code = lwm2m_engine_create_obj_inst(LWM2M_REMOTE_SIM_PROVISIONING_INSTANCE);	
        		
        /* Register callbacks only if the instance was successfully created */
        if (NRF_SUCCESS == return_code || -EEXIST == return_code || -ENOMEM == return_code) {
            for (int idx = 0; idx < LWM2M_REMOTE_SIM_PROVISIONING_ICCID_INSTANCE_COUNT; idx++) {
                /* Generate the resource path being read */
                sprintf((char*)remote_sim_provisioning_resource_path,
                        LWM2M_REMOTE_SIM_PROVISIONING_INSTANCE_CUSTOM_RESOURCE_TEMPLATE, LWM2M_REMOTE_SIM_PROVISIONING_ICCID_ID, idx);
                
                return_code += lwm2m_engine_create_res_inst(remote_sim_provisioning_resource_path);
                
                return_code += 
                lwm2m_engine_register_read_callback(remote_sim_provisioning_resource_path, 
                                                      UC_LWM2M_Remote_SIM_Provisioning_ReadCallback);
            }
    	
    		/* Trigger update so that the server is immediately notified of the new instance */
    		engine_trigger_update(true);
    		
    		if (NRF_SUCCESS == return_code) {
    			LOG_DBG("Init OK: LwM2M Remote SIM Provisioning %u", 
    				LWM2M_REMOTE_SIM_PROVISIONING_DEFAULT_INSTANCE);
    				return;
    		}
    	}
    }

    At this point when i go to Leshan server i have the problem explained on the firt post

  • Hi ICM_UC,

    After some investigation, I do not think Nordic as the SoC producer can help you debug this issue. We can only provide your samples about how to write the implements for one lwm2m object.  As Remote SIM provisioning Wikipedia explains, this is an eSIM speciation realized by GSMA. You need to check with your SIM card provider to see if this is supported by their products, or as a SIM card provider you need internal cooperation to find the cause of the issue.

    Where did you get those codes? Can you get help from the provider? If you are a SIM card solution provider, please give us more background knowledge about your project. You can contact our local sales team to get more suggestions about your development.

    Best regards,

    Charlie

Related