thingy91 - lwm2m Client Resource Instance Creation

Good day

I am currently trying to adapt the lwm2m  client sample from Zephyr and was wondering if there was a way to create multiple resource instances for the generic sensor object without changing the library.  Also , I was able to create multiple instances from the sensor value resource using this within the object creation:

// 	     NULL, NULL, NULL, sensor_value_write_cb, NULL);
	INIT_OBJ_RES(SENSOR_VALUE_RID, res[index], i, res_inst[index], j, 3,
		     true, true, &sensor_value[index], sizeof(*sensor_value),
		     NULL, NULL, NULL, sensor_value_write_cb, NULL);

However, I cant do the same for the timestamp resource.  When using this :

 INIT_OBJ_RES(TIMESTAMP_RID, res[index], i, res_inst[index], j, 3,
		     true, true, NULL, NULL,
		     NULL, NULL, NULL, NULL, NULL);

I seem to be getting this error on the Leshan demo server:

Any explanation or thoughts would be very helpful.

thank you! 

Kind regards, 

Hassan

Parents
  • Hi, 

    was wondering if there was a way to create multiple resource instances for the generic sensor object without changing the library.

    My colleague Didrik already showed you in this post. 

    With a modem trace, you can see what the device sends, which might give some hints. If you use DTLS, see how to decode the packets here: https://academy.nordicsemi.com/topic/lesson-7-exercise-2/

    Regards,
    Amanda H.

  • HI Amanda

    Apologies I don't think I was clear enough in my post.  I am referring to a resource instance.  I am asking about creating multiple resource instances (e.g sensor value ) inside one object instance. 

    Thank you.

    Kind regards,

    Hassan

  • Hi Hassan,

    I think there is now misunderstanding about LwM2M specification.

    First, you need to check whether the object in fact support multiple resource instances of given resource or not.
    For example IPSO Generic sensor has only a single instance of 

    Name Object ID
    Generic Sensor 3300

    Resource definitions

    ID Name Operations Instances Mandatory Type Range or Enumeration Units Description
    5700 Sensor Value R Single Mandatory Float Last or Current Measured Value from the Sensor.
    5701 Sensor Units R Single Optional String Measurement Units Definition.

    (Rest of the resources left out from the table above)

    As you can see from above the Sensor Value resource is marked as a single instance. So by the definition, you cannot create multiple instances of it.

    Then, for example object that do support multiple resource instances, lets take example of Device object

    Name Object ID Object Version LWM2M Version
    Device 3 1.1 1.1

    Resource Definitions

    ID Name Operations Instances Mandatory Type Range or Enumeration Units Description
    0 Manufacturer R Single Optional String Human readable manufacturer name
    6 Available Power Sources R Multiple Optional Integer 0..7 0: DC power
    1: Internal Battery
    2: External Battery
    3: Fuel Cell
    4: Power over Ethernet
    5: USB
    6: AC (Mains) power
    7: Solar
    The same Resource Instance ID MUST be used to associate a given Power Source (Resource ID:6) with its Present Voltage (Resource ID:7) and its Present Current (Resource ID:8)
    7 Power Source Voltage R Multiple Optional Integer Present voltage for each Available Power Sources Resource Instance. The unit used for this resource is in mV.

    Left out some uninteresting resources. You can see that resources 6 and 7 are marked as supporting multipple instances.

    Now the object it self, when it defines all the resources, must tell LwM2M engine that those resources are multi-instance and how many instances can be created. See example of creating those resources here: https://github.com/zephyrproject-rtos/zephyr/blob/e1e2228e9cc4dcebaba31da6d8e4681aa0ae33b0/subsys/net/lib/lwm2m/lwm2m_obj_device.c#L235-L240

    I see that you tried to create more resources using those macros, but that is wrong. When the object is defined, and registered to engine, it should not be altered anymore. So if any changes to it are required, you need to modify the object source code itself.

    Then when the engine knows how many of those resources are supported, in our application code, we use following LwM2M API lwm2m_create_res_inst()

    See example of its use from: https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/net/lwm2m_client/src/lwm2m-client.c#L137-L149 which creates the resources introduced in the table above.

    I hope this helps you to get going.
    Conclusion is that if you need multiple sensor values, you should create multiple sensor object instances.

Reply
  • Hi Hassan,

    I think there is now misunderstanding about LwM2M specification.

    First, you need to check whether the object in fact support multiple resource instances of given resource or not.
    For example IPSO Generic sensor has only a single instance of 

    Name Object ID
    Generic Sensor 3300

    Resource definitions

    ID Name Operations Instances Mandatory Type Range or Enumeration Units Description
    5700 Sensor Value R Single Mandatory Float Last or Current Measured Value from the Sensor.
    5701 Sensor Units R Single Optional String Measurement Units Definition.

    (Rest of the resources left out from the table above)

    As you can see from above the Sensor Value resource is marked as a single instance. So by the definition, you cannot create multiple instances of it.

    Then, for example object that do support multiple resource instances, lets take example of Device object

    Name Object ID Object Version LWM2M Version
    Device 3 1.1 1.1

    Resource Definitions

    ID Name Operations Instances Mandatory Type Range or Enumeration Units Description
    0 Manufacturer R Single Optional String Human readable manufacturer name
    6 Available Power Sources R Multiple Optional Integer 0..7 0: DC power
    1: Internal Battery
    2: External Battery
    3: Fuel Cell
    4: Power over Ethernet
    5: USB
    6: AC (Mains) power
    7: Solar
    The same Resource Instance ID MUST be used to associate a given Power Source (Resource ID:6) with its Present Voltage (Resource ID:7) and its Present Current (Resource ID:8)
    7 Power Source Voltage R Multiple Optional Integer Present voltage for each Available Power Sources Resource Instance. The unit used for this resource is in mV.

    Left out some uninteresting resources. You can see that resources 6 and 7 are marked as supporting multipple instances.

    Now the object it self, when it defines all the resources, must tell LwM2M engine that those resources are multi-instance and how many instances can be created. See example of creating those resources here: https://github.com/zephyrproject-rtos/zephyr/blob/e1e2228e9cc4dcebaba31da6d8e4681aa0ae33b0/subsys/net/lib/lwm2m/lwm2m_obj_device.c#L235-L240

    I see that you tried to create more resources using those macros, but that is wrong. When the object is defined, and registered to engine, it should not be altered anymore. So if any changes to it are required, you need to modify the object source code itself.

    Then when the engine knows how many of those resources are supported, in our application code, we use following LwM2M API lwm2m_create_res_inst()

    See example of its use from: https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/net/lwm2m_client/src/lwm2m-client.c#L137-L149 which creates the resources introduced in the table above.

    I hope this helps you to get going.
    Conclusion is that if you need multiple sensor values, you should create multiple sensor object instances.

Children
No Data
Related