Hi Ricky,
You are in particular use case where Leshan does not know the
model of your object.
This is not a well supported case of the LWM2M spec.
Currently, when Leshan have no model for an object it supposes
that all resources was a STRING.
For JSON format we can be a bit smarter using type carried by the
format. (There is a PR[1] for this)
This PR will allow you to make READ on custom object from the UI.
The WRITE will not work, because the UI always send String (this
is a UI limitation), but you can use the REST API, e.g. using curl
like this :
>> curl -H "Content-Type: application/json" -X POST -d
"{'id':'10','resources':[{'id':1,'value':12},{'id':3,'value':12.5}]}"
http://localhost:8081/api/clients/testlwm2mclient/1024/10
Client [testlwm2mclient] returned unexpected response code [2.04]%
The other solution is to define model for this object at server
side.
You can define the model of you object in a leshan json format or
xml DDF file format.
Put this file in a folder.
Then set the "MODELS_FOLDER" environment variable to the path of
this folder, then run :
export MODELS_FOLDER="/your/path" && java -jar
leshan-server-demo.jar
Here the json for wakaama 1024 object :
[
{
"name": "My Custom Object",
"id": 1024,
"instancetype": "multiple",
"mandatory": true,
"description": "",
"resourcedefs": [
{
"id": 1,
"name": "My resource 1",
"operations": "RW",
"instancetype": "single",
"mandatory": true,
"type": "integer",
"range": "",
"units": "",
"description": ""
},
{
"id": 3,
"name": "My resource 3",
"operations": "RW",
"instancetype": "single",
"mandatory": true,
"type": "float",
"range": "",
"units": "",
"description": ""
}
]
}
]
HTH, Simon.
[1]https://github.com/eclipse/leshan/pull/74
Le 16/02/2016 02:27, Ricky Liu a
écrit :
Hi David,
Thank you for your prompt reply. :)
I fixed my coding error and got correct response from
leshan. But the test object seems to be leshan server problem.
Could you recommend any server besides leshan?
|