OMA_LwM2M_for_Developers
OMA_LwM2M_for_Developers copied to clipboard
Conflict Write(Update)/Execute again ?
Answering to #526, I just see that at least since LWM2M 1.2 (transport§6-4-4-Device-Management-and-Service-Enablement-Interface) POST on /{Object ID}/{Object Instance ID}/{Resource ID}
have several meaning.
So, a client must know the model to be able to interpret it.
I'm not totally sure if allowing POST for partial write on resource was done on purpose because the spec is a bit contradictory : It seems to alllow it here :
Operation | CoAP Method and Content Formats | Path |
---|---|---|
Write (Replace) | PUT Content Format: see [LwM2M-CORE] | /{Object ID}/{Object Instance ID} /{Object ID}/{Object Instance ID}/{Resource ID} /{Object ID}/{Object Instance ID}/{Resource ID}/{Resource Instance ID} |
Write (Partial Update) | POST Content Format: see [LwM2M-CORE] | /{Object ID}/{Object Instance ID} /{Object ID}/{Object Instance ID}/{Resource ID} only for Multiple-Instance Resources |
but not there :
An Object Instance, a Resource or a Resource Instance are written by sending a CoAP PUT request to the corresponding path. The request includes the value to be written in the corresponding Plain Text, Opaque, TLV, LwM2M CBOR, SenML CBOR, or SenML JSON format according to the Content-Format option which MUST be specified [CoAP]. In addition, an Object Instance can be written by sending a CoAP POST request; in that case the specified Content-Format MUST be one of the TLV, LwM2M CBOR, SenML CBOR or SenML JSON formats. CoAP PUT is used for Replace. CoAP POST or CoAP iPatch is used for Partial Update.
(meaning POST is only for Object Instance)
A similar problem was raised several years ago(see https://github.com/OpenMobileAlliance/OMA_LwM2M_for_Developers/issues/29). It was considered as an issue and fixed. This new addition reintroduce this kind of problem.
Thanks for spotting this issue. We will clarify the sentence in the v1.2.1 bugfix release.
I'm not sure I was clear but the real issue for me is more that a POST on /{Object ID}/{Object Instance ID}/{Resource ID}
could be an EXECUTE or a PARTIAL WRITE.
Operation | CoAP Method and Content Formats | Path |
---|---|---|
Write (Partial Update) | POST Content Format: see [LwM2M-CORE] | /{Object ID}/{Object Instance ID} /{Object ID}/{Object Instance ID}/{Resource ID} only for Multiple-Instance Resources |
Execute | POST Content Format: none, or text/plain (see [LwM2M-CORE]) | /{Object ID}/{Object Instance ID}/{Resource ID} |
Meaning that implementation need to know the model to understand it. This was considered as a bad idea previously (see #29).
When receiving a POST on /{Object ID}/{Object Instance ID}/{Resource ID}, the algorithm is:
- if the resource is executable then this is an Execute operation
- if the resource is writable and multiple, then this is a Write (Partial Update) operation
- else the operation is not allowed
So yes the implementation needs to know the list of allowed operations, and the multiplicity or not of the targeted resource. But this information is present in the implementation anyway.
Another possibility: the format of the payload can be used to determine if the POST is an Execute or a Write (Partial Update) operation:
- an Execute has no payload or a text/plain payload
- a Write (Partial Update) uses TLV, SenML CBOR, SenML JSON, or LwM2M CBOR (as the payload must contain the Resource Instance information).
So yes the implementation needs to know the list of allowed operations, and the multiplicity or not of the targeted resource. But this information is present in the implementation anyway.
My point is that was not considered as a such good idea by the past : https://github.com/OpenMobileAlliance/OMA_LwM2M_for_Developers/issues/29#issuecomment-165720937
Another possibility: the format of the payload can be used to determine if the POST is an Execute or a Write (Partial Update) operation:
This can do the tricks, thanks for sharing the idea :pray: Hoping a new feature will not break this tricks.