Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
OM2M/REST API
< OM2M
Revision as of 11:50, 20 April 2014 by Unnamed Poltroon (Talk) (→Create the sensor description contentInstance)
Contents
- 1 Install a rest client
- 2 Retrieve a resource
- 3 Discover resources based on their search strings
- 4 Create the "MY_SENSOR" application
- 5 Create the DESCRIPTOR container
- 6 Create a description contentInstance
- 7 Create the DATA container
- 8 Create a sensed data contentInstance
- 9 Subscribe to MY_SENSOR data
Install a rest client
- For this section, you need a REST client to send HTTP request (GET, POST, UPDATE, DELETE) to the OM2M platform.
- You can use the "Client REST Simple" (https://chrome.google.com/webstore/detail/simple-rest-client/fhjcajmcbmldlhcimfajhfbgofnpcjmb), or Postman (http://www.getpostman.com) google chrome extension or any other rest client.
- OM2M supports Basic access authentication to enforce access controls to web resources. Client username/password must be encoded to base64 then entered as a Basic Authorization header. You can use www.base64encode.org for base64 encryption. e.g. base64(admin/admin) = YWRtaW4vYWRtaW4=
Retrieve a resource
- HTTP request:
Field | Value |
URL | http://127.0.0.1:8080/om2m/gscl |
Method | GET |
Header | Authorization: Basic YWRtaW4vYWRtaW4= |
Body | (empty) |
- HTTP response:
Field | Value |
Status | 200 OK |
Body | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <om2m:sclBase xmlns:om2m="http://uri.etsi.org/m2m" xmlns:xmime="http://www.w3.org/2005/05/xmlmime"> <om2m:accessRightID>gscl/accessRights/AR_ADMIN</om2m:accessRightID> <om2m:searchStrings> <om2m:searchString>ResourceType/SclBase</om2m:searchString> <om2m:searchString>ResourceID/gscl</om2m:searchString> </om2m:searchStrings> <om2m:creationTime>2014-04-07T14:45:33.935+02:00</om2m:creationTime> <om2m:lastModifiedTime>2014-04-07T14:45:33.991+02:00</om2m:lastModifiedTime> <om2m:sclsReference>gscl/scls</om2m:sclsReference> <om2m:applicationsReference>gscl/applications</om2m:applicationsReference> <om2m:containersReference>gscl/containers</om2m:containersReference> <om2m:groupsReference>gscl/groups</om2m:groupsReference> <om2m:accessRightsReference>gscl/accessRights</om2m:accessRightsReference> <om2m:subscriptionsReference>gscl/subscriptions</om2m:subscriptionsReference> <om2m:discoveryReference>gscl/discovery</om2m:discoveryReference> </om2m:sclBase> |
Discover resources based on their search strings
- You can discover available resources based on their search strings using the discovery resource.
- HTTP request:
Field | Value |
URL | http://127.0.0.1:8080/om2m/gscl/discovery?searchString=resourcetype/sclbase |
Method | GET |
Header | Authorization: Basic YWRtaW4vYWRtaW4= |
Body | (empty) |
- HTTP response:
Field | Value |
Status | 200 OK |
Body | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <om2m:discovery xmlns:om2m="http://uri.etsi.org/m2m" xmlns:xmime="http://www.w3.org/2005/05/xmlmime"> <om2m:matchSize>1</om2m:matchSize> <om2m:discoveryURI> <reference>gscl</reference> </om2m:discoveryURI> </om2m:discovery> |
Create the "MY_SENSOR" application
- Send a HTTP request with the following parameters to create the "MY_SENSOR" application on the gateway.
Field | Value |
URL | http://127.0.0.1:8080/om2m/gscl/applications |
Method | POST |
Header | Authorization: Basic YWRtaW4vYWRtaW4= |
Body | <om2m:application xmlns:om2m="http://uri.etsi.org/m2m" appId="MY_SENSOR"> <om2m:searchStrings> <om2m:searchString>Type/sensor</om2m:searchString> <om2m:searchString>Category/temperature</om2m:searchString> <om2m:searchString>Location/Home</om2m:searchString> </om2m:searchStrings> </om2m:application> |
- You can check the created application on the web interface.
Create the DESCRIPTOR container
- Send a HTTP request with the following parameters to create the "DESCRIPTOR" container resource under the "MY_SENSOR" application.Field Value
Field | Value |
URL | http://127.0.0.1:8080/om2m/gscl/applications/MY_SENSOR/containers |
Method | POST |
Header | Authorization: Basic YWRtaW4vYWRtaW4= |
Body | <om2m:container xmlns:om2m="http://uri.etsi.org/m2m" om2m:id="DESCRIPTOR"> </om2m:container> |
- Check the created container on the web interface.
Create a description contentInstance
- Send a HTTP request with the following parameters to create the description content instance resource under the "DESCRIPTOR" container.
Field Value | |
URL | http://127.0.0.1:8080/om2m/gscl/applications/MY_SENSOR/containers/DESCRIPTOR/contentIntances |
Method | POST |
Header | Authorization: Basic YWRtaW4vYWRtaW4= |
Body | <obj> <str name="type" val="Temperature_Sensor"/> <str name="location" val="Home"/> <str name="appId" val="MY_SENSOR"/> <op name="getValue" href="gscl/applications/MY_SENSOR/containers/DATA/contentInstances/latest/content" in="obix:Nil" out="obix:Nil" is="retrieve"/> </obj> |
- Check the created content instance on the web interface.
Create the DATA container
- Send a HTTP request with the following parameters to create the "DATA" container resource under the "MY_SENSOR" application.
Field | Value |
URL | http://127.0.0.1:8080/om2m/gscl/applications/MY_SENSOR/containers |
Method | POST |
Header | Authorization: Basic YWRtaW4vYWRtaW4= |
Body | <om2m:container xmlns:om2m="http://uri.etsi.org/m2m" om2m:id="DATA"> </om2m:container> |
- Check the created container on the web interface.
Create a sensed data contentInstance
- Send a HTTP request with the following parameters to create a data content instance resource under the "DATA" container.
Field | Value |
URL | http://127.0.0.1:8080/om2m/gscl/applications/MY_SENSOR/containers/DATA/contentIntances |
Method | POST |
Header | Authorization: Basic YWRtaW4vYWRtaW4= |
Body | <obj> <str name="appId" val="MY_SENSOR"/> <str name="category" val="temperature "/> <int name="data" val="27"/> <int name="unit" val="celsus"/> </obj> |
- Check the created content instance on the web interface.
- Click on the "getValue" button to retrieve the created sensor data.
Subscribe to MY_SENSOR data
- Go to “om2m/monitor” directory.
- You can configure the Monitor listening port and context using the "config.properties"
- Start the Monitor application using "start.bat" for Windows, "start.sh" for Linux, or directly using "java -jar monitor.jar" command. By default the monitor starts listening on port=1400 and context=/monitor.
- Send a HTTP request with the following parameters to create a "Subscription" resource for receive asynchronously events from "MY_SENSOR" application. The monitor listening URL (http://127.0.0.1:1400/monitor) is added on the "om2m:contact" tag of the subscription representation.
Field | Value |
URL | http://127.0.0.1:8080/om2m/gscl/applications/MY_SENSOR/containers/DATA/contentIntances/subscriptions |
Method | POST |
Header | Authorization: Basic YWRtaW4vYWRtaW4= |
Body | <om2m:subscription xmlns:om2m="http://uri.etsi.org/m2m"> <om2m:contact>http://127.0.0.1:1400/monitor</om2m:contact> </om2m:subscription> |
- Check the created subscription on the web interface.
- Create a new event content instance resource under the "DATA" container.
- The new event is published to interested subscribers by the gateway. You should see a message box, opened by the monitor, displaying the received event.