Home » Eclipse Projects » OM2M » data type of content instance
data type of content instance [message #1397300] |
Wed, 09 July 2014 14:19 |
Hao XU Messages: 18 Registered: June 2014 |
Junior Member |
|
|
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] |
Thu, 10 July 2014 01:29 |
Mahdi Ben Alaya Messages: 229 Registered: November 2013 |
Senior Member |
|
|
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 07:43] Report message to a moderator
|
|
|
Re: data type of content instance [message #1397895 is a reply to message #1397641] |
Thu, 10 July 2014 10:08 |
Hao XU Messages: 18 Registered: June 2014 |
Junior Member |
|
|
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 #1397905 is a reply to message #1397895] |
Thu, 10 July 2014 10:20 |
Mahdi Ben Alaya Messages: 229 Registered: November 2013 |
Senior Member |
|
|
1) If CI is created in format text/plain, it will be automatically base64-encoded by the SCL.
This is important, to respect the contentInstance XML representation as described by ETSI.
2) But, as I explained in my first reply, you have two options on how to retrieve the content:
- You can retrieve the full contentInstance and then base64-decode the content.
- Or, you can simply retrieve the decoded text/plain content by just adding "/content" to your request URI. (I prefer this one)
Example:
GET 127.0.0.1:8080/om2m/gscl/applications/DA2/containers/temperature/contentInstances/DA2_tem_CI1/content
The response here will be a text/plain data.
PS: "DA2_tem_CI1" can be replaced by "latest" or "oldest" to get the latest or the oldest contentInstance.
[Updated on: Thu, 10 July 2014 10:27] Report message to a moderator
|
|
| |
Re: data type of content instance [message #1397984 is a reply to message #1397921] |
Thu, 10 July 2014 12:44 |
Mahdi Ben Alaya Messages: 229 Registered: November 2013 |
Senior Member |
|
|
It depends on the subscription resource:
1) If you use a simple subscription representation, example:
<om2m:subscription xmlns:om2m="http://uri.etsi.org/m2m">
<om2m:contact>http://127.0.0.1:1400/monitor</om2m:contact>
</om2m:subscription>
you will receive a Notify resource including the whole contentInstance with a base64-encoded content.
Remark: The Notify resource has a generic representation to contain other types of resources such as application, container, group, accessRight, etc.
2) You can use a more advanced subscription resource to be notified only of the content.
This can be done using the "filterCriteria" and "ifMatch" tags available for the subscription resource.
Example:
<om2m:subscription xmlns:om2m="http://uri.etsi.org/m2m">
<om2m:filterCriteria>
<ifMatch>content</ifMatch>
</om2m:filterCriteria>
<om2m:contact>http://127.0.0.1:1400/monitor</om2m:contact>
</om2m:subscription>
You will receive a Notify resource including just a content.
[Updated on: Thu, 10 July 2014 14:42] Report message to a moderator
|
|
| | | |
Re: data type of content instance [message #1425209 is a reply to message #1406924] |
Wed, 17 September 2014 01:58 |
Pedro Diogo Messages: 3 Registered: September 2014 |
Junior Member |
|
|
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 294 times)
|
|
|
Re: data type of content instance [message #1425573 is a reply to message #1425209] |
Wed, 17 September 2014 13:50 |
Mahdi Ben Alaya Messages: 229 Registered: November 2013 |
Senior Member |
|
|
Hello Pedro,
1) In Postman you should add the following Authorization header with a base64-encoded "admin/admin" like this:
- Name: Authorization
- Value: Basic YWRtaW4vYWRtaW4=
You can import if you want this sample Postman request collection from this link: https://www.getpostman.com/collections/d752700c8a4584e81296
can you show me the representation of the contentInstance created in the DATA container ?
Actually, the OM2M build-in web itnerface is able to parse this kind of oBIX representation:
<obj>
<int name="data" val="27"/>
<int name="unit" val="celsus"/>
</obj>
Otherwise you can send a row data and consume it using your specific client.
2) For your NA, of course it is better to request the NSCL to get resources from the GSCL to be compliant with the ETSI M2M standard.
It is really easy and seamless, all what you have to do is to send the same request to the NSCL ip address (instead of the gscl ip address) like this:
GET nscl_ip:nscl_port/om2m/gscl/applications/98eb/...
The NSCL will automatically retarget the request to the appropriate GSCL.
Your NA will always use the NSCL ip address. It will not even be aware that the request is sent to another machine.
It is like browsing a simple web site, but technically we are browsing a variety of machine in a seamless way.
[Updated on: Wed, 17 September 2014 13:58] Report message to a moderator
|
|
|
Re: data type of content instance [message #1426203 is a reply to message #1397300] |
Thu, 18 September 2014 11:51 |
Pedro Diogo Messages: 3 Registered: September 2014 |
Junior Member |
|
|
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.
|
|
| | | |
Goto Forum:
Current Time: Sun Sep 22 11:28:01 GMT 2024
Powered by FUDForum. Page generated in 0.03801 seconds
|