Connect devices to your gateway [message #1641034] |
Sat, 28 February 2015 11:08 |
Mahdi Ben Alaya Messages: 229 Registered: November 2013 |
Senior Member |
|
|
There are two mechanisms to connect devices to your gateway.
1) Connect HTTP or CoAP enabled devices using simple re-targeting.
Let's suppose that you have a HTTP-enabled plug device with IP address 192.168.0.4 and listening on port 9090.
Let's suppose that you can also monitor and control this plug using this two specific HTTP requests:
GET http://192.168.0.4:9090/power: To get the power consumption value from the plug.
POST http://192.168.0.4:9090/toggle: To switch on/off the plug.
Since, by default OM2M offers the HTTP binding, then you can create an application resource called MY_DEVICE containing "http://192.168.0.4:9090" as specific Application Point of Contact Path (aPoCPath).
HTTP request example:
POST 127.0.0.1:8080/om2m/gscl/applications
<om2m:application xmlns:om2m="[url]http://uri.etsi.org/m2m[/url]" appId="MY_DEVICE">
<om2m:aPoCPaths>
<om2m:aPoCPath>
<om2m:path>http://192.168.0.4:9090</om2m:path>
</om2m:aPoCPath>
</om2m:aPoCPaths>
</om2m:application>
That's all. Now when you can send a HTTP GET request to the GSCL with this URI "127.0.0.1:8080/om2m/gscl/applications/MY_DEVICE/power", the GSCL will automatically translate it to http://192.168.0.4:9090/power based on the information stored on the APoC.
Then, the HTTP request is automatically re-targeted to your plug device, and the HTTP response containing the power consumption is returned to you.
If you send a HTTP POST request with empty body to the GSCL with this URI "127.0.0.1:8080/om2m/gscl/applications/MY_DEVICE/toggle", it will be automatically translated to http://192.168.0.4:9090/toggle and re-targeted to your device to toggle it.
In addition, you can create an oBIX XML description for the MY_DEVICE application within a specific container to advertise your device operations and simplify their discovery.
Let's suppose that the "DESCRIPTOR" container is already created in this URL: /gscl/applications/MY_DEVICE/containers/DESCRIPTOR
HTTP request example:
POST 127.0.0.1:8080/om2m/gscl/applications/MY_DEVICE/containers/DESCRIPTOR/contentInstances
<obj>
<str name="type" val="xxxx"/>
<str name="location" val="yyyy"/>
<op name="get" href="gscl/applications/MY_DEVICE/spower" is="retrieve"/>
<op name="toggle" href="gscl/applications/MY_DEVICE/toggle" is="execute"/>
</obj>
If you check the created contentInstance on the OM2M web interface, you will find the device attributes and nice buttons that you can use to monitor and control your device.
You can use also use "create" (is="create") and delete (is="delete") operations if needed.
Since OM2M implements the CoAP communication binding, CoAP-enabled devices can be integrated using the same approach explained for HTTP.
2) Connect legacy devices using an Interworking Proxy Unit (IPU) Plugin
To integrate IP-enabled devices speaking other protocols like MQTT or non IP-enabled devices like Zigbee, you need to create a specific Interworking Proxy Unit (IPU) plugin to make the required mapping.
You can create an application resource called MY_DEVICE containing the string "ipu-id" as specific aPoCPath.
HTTP request example:
POST 127.0.0.1:8080/om2m/gscl/applications
<om2m:application xmlns:om2m="http://uri.etsi.org/m2m" appId="MY_DEVICE">
<om2m:aPoCPaths>
<om2m:aPoCPath>
<om2m:path>ipu-id</om2m:path>
</om2m:aPoCPath>
</om2m:aPoCPaths>
</om2m:application>
Now, if you send a HTTP request to the GSCL to this URI "127.0.0.1:8080/om2m/gscl/applications/MY_DEVICE/ipu-id/...", it will be delegated to the IPU plugin with ID "ipu-id" and handled specifically by the IPU Controller class.
The IPU lamps plugin already provided in the OM2M source code shows a good example on how to integrated specific devices using the inter-working proxy mechanism.
Check the following developer guide to learn how to add a new plugin to OM2M and implement you own IPU with a basic sensor and actuator:
https://wiki.eclipse.org/OM2M/Developer
Hope this can help
Mahdi,
[Updated on: Tue, 12 May 2015 14:07] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04719 seconds