lwm2m.device.oir.write

The lwm2m.device.oir.write command is used to write a resource on a device or multiple resources at once, based on the presence/absence of the <resId> parameter.

TR50 Request
{
   "1": {
	"command": "lwm2m.device.oir.write",
	"params": {
	  "thingKey": "mydevice",
	  "objId": 1,
	  "instId": 0,
	  "resId": 6,
	  "encoding": 11542,
	  "data": true
      }
   }
} 

Multiple resources can be written using two formats: Array and Map. The difference in behavior between the two are:

  • Array: will lead to a write of a list of values without specifying the index to the device. The first value will be written in position 1, the second in position 2 and so on for the consecutive positions;

  • Map: will lead to a write where the values will be written in relation to a specific key index. Positions can be consecutive or not, this will follow the key index reported in the API.

Array example when the request involves "resId" data field
{
  "1": {
    "command": "lwm2m.device.oir.write",
    "params": {
      ...,
      "objId": <objID>,
      "instId": <instId>,
      "data": {
        "resID": [
          <value1>,
          ...,
          <valueN>
        ],
        "encoding" : <encodingType>
      }
    }
  }
}
Array example when the request does not involve "resId" data field
{
  "1": {
    "command": "lwm2m.device.oir.write",
    "params": {
      ...,
      "objId": <objID>, 
      "instId": <objInstID>,
      "data": {
        "resId": <value>,
        "<resIDMultipleResource>": [
          <value1>,
          ...,
          <valueN>
        ]
      },
      "encoding" : <encodingType>
    }
  }
}
Map example when the request involves "resId" data field
{
  "1": {
    "command": "lwm2m.device.oir.write",
    "params": {
      ...,
      "objId": <objID>,
      "instId": <objInstID>,
      "resId": <ResID>,
      "data": {
        "<keyIndex1>": <value1>,
        ...,
        "<keyIndexN>": <valueN>
      },
      "encoding" : <encodingType>
    }
  }
} 
Map example when the request does not involve "resId" data field
{
  "1": {
    "command": "lwm2m.device.oir.write",
    "params": {
      ...,
      "objId": <objID>,
      "instId": <instId>,
      "data": {
        "resID": {
          "<keyIndex1>": <value1>,
          ...,
          "<keyIndexN>": <valueN>
        }
      }
      "encoding" : <encodingType>
    }
  }
}

Request Parameters

Name Type Required Description
id String Yes* The id of the device.
thingId String The id of the device.
thingKey String The thingKey of the device.
esn String The ESN of the device.
iccid String The ICCID of the device.
imei String The IMEI of the device.
imsi String The IMSI of the device.
meid String The MEID of the device.
msisdn String The MSISDN of the device.
*One of the above fields must be used to identify the device.
objId Integer Yes The object ID.
instId Integer Yes The instance ID.
resId Integer   The resource ID.
resIdx Integer   Introduced in the LwM2M 1.1 spec. Its usage is recommended only for devices supporting a LwM2M enabler version >= 1.1, otherwise, an error may be returned from the device leading the request to fail.
encoding Integer  

Message containing data must specify the payload encoding by using one of the supported data format. For more information on encoding, see Navigating Object browser.

  • PlainText (0) - (only on single resources)

  • Opaque (42) - (only on single opaque resources)

  • CBOR (60) - (only on single resources)**

  • SenML+JSON (110)**

  • SenML+CBOR (112)**

  • TLV (11542)

  • JSON (11543)

** Only for devices supporting a LwM2M enabler version >= 1.1, otherwise, an error may be returned from the device leading the request to fail.

partial Boolean   Default behavior when the resId parameter is set is to completely replace the array of values in a multi-value resource. Use this parameter and set it to true if only the fields specified should be added/updated. Setting parameter to false will result in an error. Cannot be used with the replace parameter (the partial and replace parameters are mutually exclusive).
replace Boolean   Default behavior when the resId parameter is not set is to only update the fields specified, adding/updating values within the array of values of a multi-value resource. Use this parameter and set it to true if the passed values should completely replace any existing values. Setting parameters to false will result in an error. Cannot be used with the partial parameter (the partial and replace parameters are mutually exclusive).
data Mixed* Yes+ The data to write.
+When the data is not sent, will default to empty. Empty will be defined based on the field type: for strings it is an empty string, for floats and integers it will be zero, for boolean it will be false, and for other data structures it will be nil (an empty set or empty array).

Data type examples

Resource type Expected encoding Example
boolean true, false "<resID>": false
unsigned integers [0 - 255] / [0 - 65,535] / [0 - 4,294,967,295] / [0 - 18,446,744,073,709,551,615] ( see note "a") "<resID>" : 5
opaque Must be provided as a base64 string. "<resID>" : "TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu"
string Sequence of characters between quotes. "<resID>" : "hello"
integer A number that is not a fraction. "<resID>" : 8
float Numeric value with floating decimal points. "<resID>" : -2434.545
time RFC 3339 formatted string with double quotes, or unix timestamp "<resID>" : "2022-05-10T16:08:12.00Z" or "<resID>" : 1652198892
object link String encoding with specific format. '{ "instId": <ObjInstIdentifier>,"objId": <ObjIdentifier>}'"
(a) based on the resource type definition as 8, 16, 32 or 64-bit unsigned integer

To write an empty string to a resource or resource instance, use the Unicode string termination character "\u0000" as the value.

If the command is sent successfully a success message <other information> is returned. Otherwise, an error and error message will be returned.

TR50 Response
{
  "1": {
    "success": true
  }
}