Home » Eclipse Projects » OM2M » data type of content instance
data type of content instance [message #1397300] |
Wed, 09 July 2014 10:19  |
Eclipse User |
|
|
|
Hello, evryone:
I have deploied my GA on the GSCL OM2M, then but I found some thing strange when GA create new content instance, below is the trace:
juil. 09, 2014 11:37:43 AM org.eclipse.om2m.comm.http.RestHttpServlet service
Infos: HttpRequest [method=POST, URI=/gscl/applications/DA2/containers/temperatu
re/contentInstances/, representation=<?xml version="1.0" encoding="UTF-8"?><m2m:
contentInstance xmlns:m2m="http://uri.etsi.org/m2m" xmlns:xm="http://www.w3.org/
2005/05/xmlmime" href="http://www.company.org/cum/sonoras" m2m:id="DA2_tem_CI1">
<m2m:content xm:contentType="string">
<m2m:textContent>1.0</m2m:textContent>
</m2m:content>
</m2m:contentInstance>, Authorization=Basic YWRtaW4vYWRtaW4=, queryString=null]
juil. 09, 2014 11:37:43 AM org.eclipse.om2m.core.router.Router doRequest
Infos: RequestIndication [method=CREATE, base=null, targetID=/gscl/applications/
DA2/containers/temperature/contentInstances/, representation=<?xml version="1.0"
encoding="UTF-8"?><m2m:contentInstance xmlns:m2m="http://uri.etsi.org/m2m" xmln
s:xm="http://www.w3.org/2005/05/xmlmime" href="http://www.company.org/cum/sonora
s" m2m:id="DA2_tem_CI1">
<m2m:content xm:contentType="string">
<m2m:textContent>1.0</m2m:textContent>
</m2m:content>
</m2m:contentInstance>, requestingEntity=admin/admin, protocol=http]
juil. 09, 2014 11:37:43 AM org.eclipse.om2m.core.router.Router doRequest
Infos: ResourceController [ContentInstanceController]
juil. 09, 2014 11:37:44 AM org.eclipse.om2m.core.dao.DAO$1 run
Infos: Transaction committed successfully
juil. 09, 2014 11:37:44 AM org.eclipse.om2m.core.router.Router doRequest
Infos: ResponseConfirm [statusCode=STATUS_CREATED, representation=<?xml version=
"1.0" encoding="UTF-8" standalone="yes"?>
<om2m:contentInstance xmlns:om2m="http://uri.etsi.org/m2m" xmlns:xmime="http://w
ww.w3.org/2005/05/xmlmime" om2m:id="CI_9950409" href="gscl/applications/DA2/cont
ainers/temperature/contentInstances/CI_9950409">
<om2m:creationTime>2014-07-09T11:37:44.167+02:00</om2m:creationTime>
<om2m:lastModifiedTime>2014-07-09T11:37:44.168+02:00</om2m:lastModifiedTime>
<om2m:delayTolerance>2014-07-09T14:57:44.161+02:00</om2m:delayTolerance>
<om2m:contentSize>334</om2m:contentSize>
<om2m:content xmime:contentType="application/xml">PD94bWwgdmVyc2lvbj0iMS4wIi
BlbmNvZGluZz0iVVRGLTgiPz48bTJtOmNvbnRlbnRJbnN0YW5jZSB4bWxuczptMm09Imh0dHA6Ly91cm
kuZXRzaS5vcmcvbTJtIiB4bWxuczp4bT0iaHR0cDovL3d3dy53My5vcmcvMjAwNS8wNS94bWxtaW1lIi
BocmVmPSJodHRwOi8vd3d3LmNvbXBhbnkub3JnL2N1bS9zb25vcmFzIiBtMm06aWQ9IkRBMl90ZW1fQ0
kxIj4NCiAgDQogIDxtMm06Y29udGVudCB4bTpjb250ZW50VHlwZT0ic3RyaW5nIj4NCiAgICA8bTJtOn
RleHRDb250ZW50PjEuMDwvbTJtOnRleHRDb250ZW50Pg0KICA8L20ybTpjb250ZW50Pg0KPC9tMm06Y2
9udGVudEluc3RhbmNlPg==</om2m:content>
</om2m:contentInstance>
, resourceURI=gscl/applications/DA2/containers/temperature/contentInstances/CI_9
950409]
juil. 09, 2014 11:37:44 AM org.eclipse.om2m.comm.http.RestHttpServlet service
Infos: HttpResponse [statusCode=201]
juil. 09, 2014 11:37:44 AM org.eclipse.om2m.core.dao.DAO$1 run
Infos: Transaction committed successfully
There are two things which I can't understand:
1. GA has defined contentInstanceID when it send the request, but GSCL ignores it and create a new contentInstanceID.
2. In the response, GSCL coding all the CI xml into a presentation Base64. I think that it should take out the content part and conding it into base64.
I have tried to find something in the specification, but it's hard.
So could anyone help me?
Thanks.
Hao XU
|
|
|
Re: data type of content instance [message #1397641 is a reply to message #1397300] |
Wed, 09 July 2014 21:29   |
Eclipse User |
|
|
|
Hi Hao,
The ETSI M2M specification defines two methods to create a contentInstance:
1) Create a contentInstance using a contentInstance representation.
In this method, the content tag must be base64 encoded.
Example, if you want to create a contentInstance with a "hello world" content, you should use this request:
POST 127.0.0.1:8080/om2m/gscl/applications/DA2/containers/temperature/contentInstances
<om2m:contentInstance xmlns:om2m="http://uri.etsi.org/m2m" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" om2m:id="DA2_tem_CI1">
<om2m:content xmime:contentType="application/xml">aGVsbG8gd29ybGQ=</om2m:content>
</om2m:contentInstance>
Remark: Base64(hello world)= "aGVsbG8gd29ybGQ=".
Here, the content tag must be base64-encoded to avoid putting together ETSI and non ETSI tags, otherwise the XML XSD validation will automatically fail.
In most scenarios, it is not necessary to specify an id for your contentInstance. Remember that you can retrieve the "latest" or the "oldest" contentInstance using this request:
GET 127.0.0.1:8080/om2m/gscl/applications/DA2/containers/temperature/contentInstances/latest
you can also retrieve directly the latest content using this request:
GET 127.0.0.1:8080/om2m/gscl/applications/DA2/containers/temperature/contentInstances/latest/content
2)Create a contentInstance uisng a plaing text content.
In this method, the content can be sent directly in the body of your request. OM2M will create the contentInstance resource for you with all required attributes.
This is useful because it is lighter and simplifies a lot pushing sensors data to the platform.
Example: to create a contentInstance with a "hello world" content, you should use this request:
POST 127.0.0.1:8080/om2m/gscl/applications/DA2/containers/temperature/contentInstances
hello world
Of course, it is always better to structure your payload. ETSI advices to use the oBIX format to structure the content (www.obix.org).
Example of oBIX content:
<obj>
<int name="data" val="27"/>
<str name="location" val="Home"/>
</obj>
Actually, the om2m web interface understand the obix format and is able to display all the obix attributes in a nice table.
You can take a look at this tutorial: http://wiki.eclipse.org/OM2M/REST_API for a detailed example.
[Updated on: Thu, 10 July 2014 03:43] by Moderator
|
|
|
Re: data type of content instance [message #1397895 is a reply to message #1397641] |
Thu, 10 July 2014 06:08   |
Eclipse User |
|
|
|
Hi, Mahdi Ben Alaya
Thanks very much for your response, this is very clear.
I have tried sending in text/plain, but in the response the response type is xml/application, and the content is codage Base64.
juil. 10, 2014 12:03:54 PM org.eclipse.om2m.comm.http.RestHttpServlet service
Infos: HttpRequest [method=POST, URI=/gscl/applications/DA1/containers/temperatu
re/contentInstances/, representation=1.0, Authorization=Basic YWRtaW4vYWRtaW4=,
queryString=null]
juil. 10, 2014 12:03:54 PM org.eclipse.om2m.core.router.Router doRequest
Infos: RequestIndication [method=CREATE, base=null, targetID=/gscl/applications/
DA1/containers/temperature/contentInstances/, representation=1.0, requestingEnti
ty=admin/admin, protocol=http]
juil. 10, 2014 12:03:54 PM org.eclipse.om2m.core.router.Router doRequest
Infos: ResourceController [ContentInstanceController]
juil. 10, 2014 12:03:54 PM org.eclipse.om2m.core.dao.DAO$1 run
Infos: Transaction committed successfully
juil. 10, 2014 12:03:54 PM org.eclipse.om2m.core.router.Router doRequest
Infos: ResponseConfirm [statusCode=STATUS_CREATED, representation=<?xml version=
"1.0" encoding="UTF-8" standalone="yes"?>
<om2m:contentInstance xmlns:om2m="http://uri.etsi.org/m2m" xmlns:xmime="http://w
ww.w3.org/2005/05/xmlmime" om2m:id="CI_602230661" href="gscl/applications/DA1/co
ntainers/temperature/contentInstances/CI_602230661">
<om2m:creationTime>2014-07-10T12:03:54.949+02:00</om2m:creationTime>
<om2m:lastModifiedTime>2014-07-10T12:03:54.950+02:00</om2m:lastModifiedTime>
<om2m:delayTolerance>2014-07-10T15:23:54.948+02:00</om2m:delayTolerance>
<om2m:contentSize>3</om2m:contentSize>
<om2m:content xmime:contentType="application/xml">MS4w</om2m:content>
</om2m:contentInstance>
, resourceURI=gscl/applications/DA1/containers/temperature/contentInstances/CI_6
02230661]
juil. 10, 2014 12:03:55 PM org.eclipse.om2m.comm.http.RestHttpServlet service
Infos: HttpResponse [statusCode=201]
juil. 10, 2014 12:03:55 PM org.eclipse.om2m.core.dao.DAO$1 run
Infos: Transaction committed successfully
Does this mean that even if CI is created in format text/plain, when GSCL recerive the content, it will be coded in the Base64? So when I retrieve this CI, I always have to do decoding?
|
|
| | | | | | |
Re: data type of content instance [message #1425209 is a reply to message #1406924] |
Tue, 16 September 2014 21:58   |
Eclipse User |
|
|
|
Hello there.
I'm hijacking this thread as I was about to create a new topic to ask pretty much the same thing. I will do it here since I still don't understand a few things.
I've successfully deployed a nodejs app which creates a new application whenever an Arduino node sends a specific CoAP PUT (had to use Ponte, because there is still no official CoAP-HTPP binding). However, I now need to create a web page to interact with my GSCL (it should actually be a NA interacting with NSCL, but I'm just testing it right now)...and that is where the problem resides. I've tried to GET the /latest/content using the built-in Web App, but I did not succeed as you can see in the print screen. I wanted to try it using Postman (or any other client), but I don't know how to, since I can not enter admin/admin (encoded to base64) in that GUI... Could anyone help me here? :\ I need to test if I can get the response in plain text. This will also be the path to where Arduino sends the temperature value.
Thanks in advance!
Off-topic but important: If I wanted to this the right ETSI standard way, what would be the correct procedure when deploying the web page (NA). I'm guessing the NA should contact NSCL which in turn possesses the value sent by the Arduino via GSCL - am I right?
Best regards,
Pedro.
Attachment: om2m.png
(Size: 639.75KB, Downloaded 304 times)
|
|
| |
Re: data type of content instance [message #1426203 is a reply to message #1397300] |
Thu, 18 September 2014 07:51   |
Eclipse User |
|
|
|
Great! Thanks a lot for the reply.
1) I did manage to get POSTman to work afterwards. The problem I had had to do with the default login being "admin/admin" instead of "admin:admin". If you use POSTman web interface for username and password field, the result is the encoded "admin:admin" instead of "admin/admin". Anyway, it works now.
The representation is now working. It was a coding syntax error...I forgot to add " " in my javascript code, and that was why the web interface could not then parse the representation.
2) About the NA - that is super. Didn't know the standard would work like that but it makes total sense!
Some more questions: ( )
a) I can auth myself when interacting with GSCL, but shouldn't it (the GSCL) auth itself too with the NSCL? In the GSCL's config file we have only IP, Port, ID and context - not username and password. Is that ETSI-compliant?
b) Also, will there be a way to change the default username and password authentication?
c) My NA used to connect itself to a MQTT broker via WebSockets, but now I want to work as closely as possible with the standards. I know OM2M has been working on MQTT bindings - in the future, will this be part of this framework? When I connected directly to the broker, it was much more efficient...now I have to create a subscription at the GSCL and point it to a nodejs application so I can get real-time updates in my web application (NA). In the future, how will this MQTT binding defined by OM2M work exactly? Because I already have nodejs's Ponte installed which can do this binding, but I don't want to interact directly with it, I want to communicate with NSCL only.
Sorry for the long questions, but I find this project much interesting and I want it to keep up with it and the whole M2M standards as much as possible. 
Best regards,
Pedro.
|
|
| | |
Re: data type of content instance [message #1694934 is a reply to message #1694802] |
Sat, 09 May 2015 16:52  |
Eclipse User |
|
|
|
Hello Daniel,
Yes, it is ETSI-complaint. This is caled:
Partial Addressing: the parts of the resource are identified using normal URIs, where the components correspond to the names of the attributes.
For more details you can check: ETSI TS 102 690 V2.1.1 9.3.2.29 Partial addressing
In general, partial Addressing can be used to address attribute of all resources, but in OM2M we implemented it just for contentInstance content because it more useful here.
Mahdi
|
|
|
Goto Forum:
Current Time: Tue Jul 22 11:02:34 EDT 2025
Powered by FUDForum. Page generated in 0.08979 seconds
|