all: merge from official Eclipse branch
Change-Id: Iba1502617c1c401217471a52b15273ac4690ac1f
Signed-off-by: BONNARDEL Gregory <gbonnardel.ext@orange.com>
diff --git a/org.eclipse.om2m.client.arduino/onem2m-arduino-light.in b/org.eclipse.om2m.client.arduino/onem2m-arduino-light.in
new file mode 100644
index 0000000..04d9dc7
--- /dev/null
+++ b/org.eclipse.om2m.client.arduino/onem2m-arduino-light.in
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+#include <ESP8266WiFi.h>
+
+// WIFI network
+const char* ssid = "Pi3-AP";
+const char* password = "raspberry";
+
+// Target CSE
+const char* host = "172.24.1.1";
+const int httpPort = 8282;
+
+// AE-ID
+const char* origin = "Clight_ae1";
+
+// AE listening port
+WiFiServer server(80);
+
+void setup() {
+
+ Serial.begin(115200);
+ delay(10);
+
+ // Configure pin 5 for LED control
+ pinMode(5, OUTPUT);
+ digitalWrite(5, 0);
+
+ Serial.println();
+ Serial.println();
+
+ // Connect to WIFI network
+ Serial.print("Connecting to ");
+ Serial.println(ssid);
+
+ WiFi.persistent(false);
+
+ WiFi.begin(ssid, password);
+
+ while (WiFi.status() != WL_CONNECTED) {
+ delay(500);
+ Serial.print(".");
+ }
+ Serial.println();
+ Serial.println("WiFi connected");
+ Serial.println("IP address: ");
+ Serial.println(WiFi.localIP());
+
+ // Start HTTP server
+ server.begin();
+ Serial.println("Server started");
+
+ // Create AE resource
+ String resulat = send("/~/gateway-1/gateway-1",2,"{\"m2m:ae\":{\"rn\":\"light_ae1\",\"acpi\":[\"/gateway-1/gateway-1/MN-CSEAcp\"],\"api\":\"light.company.com\",\"rr\":\"true\",\"poa\":[\"http://"+WiFi.localIP().toString()+":80\"]}}");
+
+ if(resulat=="HTTP/1.1 201 Created"){
+ // Create Container resource
+ send("/~/gateway-1/gateway-1/light_ae1",3,"{\"m2m:cnt\":{\"rn\":\"light\"}}");
+
+ // Create ContentInstance resource
+ send("/~/gateway-1/gateway-1/light_ae1/light",4,"{\"m2m:cin\":{\"con\":\"OFF\"}}");
+
+ // Create Subscription resource
+ send("/~/gateway-1/gateway-1/light_ae1/light",23,"{\"m2m:sub\":{\"rn\":\"lightstate_sub\",\"nu\":[\"Clight_ae1\"],\"nct\":1}}");
+ }
+}
+
+// Method in charge of receiving event from the CSE
+void loop(){
+ // Check if a client is connected
+ WiFiClient client = server.available();
+ if (!client) {
+ return;
+ }
+
+ // Wait until the client sends some data
+ Serial.println("new client");
+ while(!client.available()){
+ delay(1);
+ }
+
+ // Read the request
+ String req = client.readString();
+ Serial.println(req);
+ client.flush();
+
+ // Switch the LED state according to the received value
+ if (req.indexOf("ON") != -1){
+ digitalWrite(5, 1);
+ }else if (req.indexOf("OFF") != -1){
+ digitalWrite(5, 0);
+ }else{
+ Serial.println("invalid request");
+ client.stop();
+ return;
+ }
+
+ client.flush();
+
+ // Send HTTP response to the client
+ String s = "HTTP/1.1 200 OK\r\n";
+ client.print(s);
+ delay(1);
+ Serial.println("Client disonnected");
+
+}
+
+
+// Method in charge of sending request to the CSE
+String send(String url,int ty, String rep) {
+
+ // Connect to the CSE address
+ Serial.print("connecting to ");
+ Serial.println(host);
+
+ WiFiClient client;
+
+ if (!client.connect(host, httpPort)) {
+ Serial.println("connection failed");
+ return "error";
+ }
+
+
+ // prepare the HTTP request
+ String req = String()+"POST " + url + " HTTP/1.1\r\n" +
+ "Host: " + host + "\r\n" +
+ "X-M2M-Origin: " + origin + "\r\n" +
+ "Content-Type: application/json;ty="+ty+"\r\n" +
+ "Content-Length: "+ rep.length()+"\r\n"
+ "Connection: close\r\n\n" +
+ rep;
+
+ Serial.println(req+"\n");
+
+ // Send the HTTP request
+ client.print(req);
+
+ unsigned long timeout = millis();
+ while (client.available() == 0) {
+ if (millis() - timeout > 5000) {
+ Serial.println(">>> Client Timeout !");
+ client.stop();
+ return "error";
+ }
+ }
+
+ // Read the HTTP response
+ String res="";
+ if(client.available()){
+ res = client.readStringUntil('\r');
+ Serial.print(res);
+ }
+ while(client.available()){
+ String line = client.readStringUntil('\r');
+ Serial.print(line);
+ }
+
+ Serial.println();
+ Serial.println("closing connection");
+ Serial.println();
+ return res;
+}
diff --git a/org.eclipse.om2m.client.arduino/onem2m-client2-dht.ino b/org.eclipse.om2m.client.arduino/onem2m-client2-dht.ino
new file mode 100644
index 0000000..8a70252
--- /dev/null
+++ b/org.eclipse.om2m.client.arduino/onem2m-client2-dht.ino
@@ -0,0 +1,227 @@
+/*******************************************************************************
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+#include <ESP8266WiFi.h>
+#include <SimpleDHT.h>
+#include "Timer.h"
+
+Timer t;
+int pinDHT11 = 2;
+SimpleDHT11 dht11;
+
+const char* ssid = "Pi3-AP";
+const char* password = "raspberry";
+
+
+const char* host = "192.168.0.2";
+const int httpPort = 8080;
+const char* origin = "Cae-nodemcu";
+
+WiFiServer server(80);
+
+void setup() {
+
+ Serial.begin(115200);
+ delay(10);
+
+ // prepare GPIO2
+ pinMode(5, OUTPUT);
+ digitalWrite(5, 0);
+ pinMode(4, OUTPUT);
+ digitalWrite(4, 0);
+
+ // We start by connecting to a WiFi network
+ randomSeed(analogRead(0));
+
+ Serial.println();
+ Serial.println();
+ Serial.print("Connecting to ");
+ Serial.println(ssid);
+
+ WiFi.begin(ssid, password);
+
+ while (WiFi.status() != WL_CONNECTED) {
+ delay(500);
+ Serial.print(".");
+ }
+
+ Serial.println("");
+ Serial.println("WiFi connected");
+
+ server.begin();
+ Serial.println("Server started");
+
+ Serial.println("IP address: ");
+ Serial.println(WiFi.localIP());
+
+ String resulat = send("/~/server/server",2,"{\"ae\":{\"rn\":\"MYDEVICE\",\"api\":\"app-test\",\"rr\":\"true\",\"poa\":[\"http://"+WiFi.localIP().toString()+":80\"]}}");
+
+ if(resulat=="HTTP/1.1 201 Created"){
+ send("/~/server/server/MYDEVICE",3,"{\"cnt\":{\"rn\":\"TEMPERATURE\"}}");
+ send("/~/server/server/MYDEVICE/TEMPERATURE",3,"{\"cnt\":{\"rn\":\"DATA\"}}");
+
+ send("/~/server/server/MYDEVICE",3,"{\"cnt\":{\"rn\":\"HUMIDITY\"}}");
+ send("/~/server/server/MYDEVICE/HUMIDITY",3,"{\"cnt\":{\"rn\":\"DATA\"}}");
+
+ send("/~/server/server/MYDEVICE",3,"{\"cnt\":{\"rn\":\"LED\"}}");
+ send("/~/server/server/MYDEVICE/LED",3,"{\"cnt\":{\"rn\":\"DATA\"}}");
+
+ push();
+
+ String dataled = "{\"cin\":{\"con\":\"<obj><str val='Led' name='type'/><bool val='false' name='value'/></obj>\"}}";
+ send("/~/server/server/MYDEVICE/LED/DATA",4,dataled);
+
+ }
+ t.every(1000*60, push);
+}
+
+void loop(){
+ t.update();
+ // Check if a client has connected
+ WiFiClient client = server.available();
+ if (!client) {
+ return;
+ }
+
+ // Wait until the client sends some data
+ Serial.println("new client");
+ while(!client.available()){
+ delay(1);
+ }
+
+ // Read the first line of the request
+ String req = client.readStringUntil('\r');
+ Serial.println(req);
+ client.flush();
+
+ // Match the request
+ int val;
+ int gpio;
+ String state;
+ String type;
+ String cnt;
+ if (req.indexOf("false") != -1){
+ gpio= 5;
+ val = 0;
+ state="false";
+ type="Led";
+ cnt="LED";
+ }else if (req.indexOf("true") != -1){
+ gpio= 5;
+ val = 1;
+ state="true";
+ type="Led";
+ cnt="LED";
+ }else {
+ Serial.println("invalid request");
+ client.stop();
+ return;
+ }
+
+ // Set GPIO2 according to the request
+ digitalWrite(gpio, val);
+
+ String data = String()+"{\"cin\":{\"con\":\"<obj><str val='"+type+"' name='type'/><bool val='"+state+"' name='value'/></obj>\"}}";
+ send(String()+"/~/server/server/MYDEVICE/"+cnt+"/DATA",4,data);
+
+ client.flush();
+
+ // Prepare the response
+ String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
+ s += (val)?"high":"low";
+ s += "</html>\n";
+
+ // Send the response to the client
+ client.print(s);
+ delay(1);
+ Serial.println("Client disonnected");
+
+}
+
+
+void push(){
+ byte temperature = 0;
+ byte humidity = 0;
+
+ if (dht11.read(pinDHT11, &temperature, &humidity, NULL)) {
+ Serial.println("Read DHT11 failed.");
+ delay(1000);
+ return;
+ }
+ Serial.print((int)temperature); Serial.print(" *C, ");
+ Serial.print((int)humidity); Serial.println(" %");
+
+ String datat,datah;
+ datat = String()+"{\"cin\":{\"con\":\"<obj><str val='Temperature' name='type'/><int val='"+(int)temperature+"' name='value'/><str val='Celsius' name='unit'/></obj>\"}}";
+ datah = String()+"{\"cin\":{\"con\":\"<obj><str val='Humidity' name='type'/><int val='"+(int)humidity+"' name='value'/><str val='%' name='unit'/></obj>\"}}";
+ send("/~/server/server/MYDEVICE/TEMPERATURE/DATA",4,datat);
+ send("/~/server/server/MYDEVICE/HUMIDITY/DATA",4,datah);
+
+}
+
+String send(String url,int ty, String rep) {
+
+ Serial.print("connecting to ");
+ Serial.println(host);
+
+ // Use WiFiClient class to create TCP connections
+ WiFiClient client;
+
+ if (!client.connect(host, httpPort)) {
+ Serial.println("connection failed");
+ return "error";
+ }
+
+
+ //Serial.print("Requesting URL: ");
+ //Serial.println(url);
+
+ // This will send the request to the server
+
+ String req = String()+"POST " + url + " HTTP/1.1\r\n" +
+ "Host: " + host + "\r\n" +
+ "X-M2M-Origin: " + origin + "\r\n" +
+ "Content-Type: application/json;ty="+ty+"\r\n" +
+ "Content-Length: "+ rep.length()+"\r\n"
+ "Connection: close\r\n\n" +
+ rep;
+
+ Serial.println(req+"\n");
+
+ client.print(req);
+
+ unsigned long timeout = millis();
+ while (client.available() == 0) {
+ if (millis() - timeout > 5000) {
+ Serial.println(">>> Client Timeout !");
+ client.stop();
+ return "error";
+ }
+ }
+
+ // Read all the lines of the reply from server and print them to Serial
+ String res="";
+ if(client.available()){
+ res = client.readStringUntil('\r');
+ Serial.print(res);
+ }
+ while(client.available()){
+ String line = client.readStringUntil('\r');
+ Serial.print(line);
+ }
+
+ Serial.println();
+ Serial.println("closing connection");
+ Serial.println();
+ return res;
+}
+
+
+
diff --git a/org.eclipse.om2m.client.java/.gitignore b/org.eclipse.om2m.client.java/.gitignore
new file mode 100644
index 0000000..924c569
--- /dev/null
+++ b/org.eclipse.om2m.client.java/.gitignore
@@ -0,0 +1,4 @@
+/bin/
+/.classpath
+/.project
+/.settings/
diff --git a/org.eclipse.om2m.client.java/pom.xml b/org.eclipse.om2m.client.java/pom.xml
new file mode 100644
index 0000000..6d626e7
--- /dev/null
+++ b/org.eclipse.om2m.client.java/pom.xml
@@ -0,0 +1,36 @@
+
+ <!--
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.eclipse.om2m</groupId>
+ <artifactId>org.eclipse.om2m.adn2</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.sun.net.httpserver</groupId>
+ <artifactId>http</artifactId>
+ <version>20070405</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.5.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <version>20160212</version>
+ </dependency>
+ </dependencies>
+
+
+</project>
diff --git a/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/AELight1.java b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/AELight1.java
new file mode 100644
index 0000000..1ad2a9b
--- /dev/null
+++ b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/AELight1.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.om2m.client.java;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.eclipse.om2m.client.java.tools.RestHttpClient;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+public class AELight1 extends TestConfig {
+
+ private static String aeRN = "light_ae1";
+ private static String aeRId = "Clight_ae1";
+ private static int AE_port = 9090;
+ private static String AE_adress = "http://127.0.0.1";
+ private static String CT_name = "light";
+
+ private static String notificationURI = AE_adress+":"+AE_port;
+ private static String subRN = "subAE1";
+
+
+ public static void Init () throws Exception {
+ /** Application registry **/
+ JSONObject obj = new JSONObject();
+ obj.put("rn", aeRN);
+ obj.put("api", "A01.com.company.lightApp01");
+ obj.put("rr", true);
+ JSONArray acpi = new JSONArray();
+ acpi.put("/"+remoteCseId+"/"+remoteCseName+"/MN-CSEAcp");
+ obj.put("acpi", acpi);
+ obj.put("poa", AE_adress+":"+AE_port);
+ JSONObject resource = new JSONObject();
+ resource.put("m2m:ae", obj);
+ RestHttpClient.post(aeRId, csePoa+"/~/"+remoteCseId+"/"+remoteCseName+"?rcn=1", resource.toString(), 2);
+
+ /** container creation **/
+ obj = new JSONObject();
+ obj.put("rn", CT_name);
+ resource = new JSONObject();
+ resource.put("m2m:cnt", obj);
+ RestHttpClient.post(originator, csePoa+"/~/"+remoteCseId+"/"+remoteCseName+"/"+aeRN+"?rcn=2", resource.toString(), 3);
+
+ /** contentInstance creation **/
+ obj = new JSONObject();
+ obj.put("cnf", "application/text");
+ obj.put("con", "OFF");
+ resource = new JSONObject();
+ resource.put("m2m:cin", obj);
+ RestHttpClient.post(originator, csePoa+"/~/"+remoteCseId+"/"+remoteCseName+"/"+aeRN+"/"+CT_name+"?rcn=3", resource.toString(), 4);
+
+ /**Subscription creation **/
+ JSONArray array = new JSONArray();
+ array.put(notificationURI);
+ obj = new JSONObject();
+ obj.put("nu", array);
+ obj.put("rn", subRN);
+ obj.put("nct", 2);
+ resource = new JSONObject();
+ resource.put("m2m:sub", obj);
+ RestHttpClient.post(originator, csePoa+"/~/"+remoteCseId+"/"+remoteCseName+"/"+aeRN+"/"+CT_name, resource.toString(), 23);
+
+ }
+
+ public static void main(String[] args) throws Exception {
+ // TODO Auto-generated method stub
+ /** Starting Server **/
+ HttpServer server = null;
+ try {
+ server = HttpServer.create(new InetSocketAddress(AE_port), 0);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ server.createContext("/", new MyHandler());
+ server.setExecutor(Executors.newCachedThreadPool());
+ server.start();
+
+ /** Initial resources creation **/
+ Init();
+ }
+
+ static class MyHandler implements HttpHandler {
+
+ public void handle(HttpExchange httpExchange) {
+ System.out.println("Event Recieved!");
+
+ try{
+ InputStream in = httpExchange.getRequestBody();
+
+ String requestBody = "";
+ int i;char c;
+ while ((i = in.read()) != -1) {
+ c = (char) i;
+ requestBody = (String) (requestBody+c);
+ }
+
+ System.out.println(requestBody);
+
+ String responseBudy ="";
+ byte[] out = responseBudy.getBytes("UTF-8");
+ httpExchange.sendResponseHeaders(200, out.length);
+ OutputStream os = httpExchange.getResponseBody();
+ os.write(out);
+ os.close();
+
+ } catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/AELight2.java b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/AELight2.java
new file mode 100644
index 0000000..2a784e6
--- /dev/null
+++ b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/AELight2.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.om2m.client.java;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.eclipse.om2m.client.java.tools.RestHttpClient;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+import java.net.InetSocketAddress;
+import java.util.concurrent.Executors;
+
+public class AELight2 extends TestConfig {
+
+ private static String aeRN = "light_ae2";
+ private static String aeRId = "Clight_ae2";
+
+ private static int AE_port = 9191;
+ private static String AE_adress = "http://192.168.0.2";
+ private static String CT_name = "light";
+
+ private static String notificationURI = AE_adress+":"+AE_port;
+ private static String subRN = "subAE2";
+
+
+ public static void Init () throws Exception {
+ /** Application registry **/
+ JSONObject obj = new JSONObject();
+ obj.put("rn", aeRN);
+ obj.put("api", "A01.com.company.lightApp01");
+ obj.put("rr", false);
+ JSONArray acpi = new JSONArray();
+ acpi.put("/"+remoteCseId+"/"+remoteCseName+"/MN-CSEAcp");
+ obj.put("acpi", acpi);
+ obj.put("poa", AE_adress+":"+AE_port);
+ JSONObject resource = new JSONObject();
+ resource.put("m2m:ae", obj);
+ RestHttpClient.post(aeRId, csePoa+"/~/"+remoteCseId+"/"+remoteCseName+"?rcn=1", resource.toString(), 2);
+
+ /** container creation **/
+ obj = new JSONObject();
+ obj.put("rn", CT_name);
+ resource = new JSONObject();
+ resource.put("m2m:cnt", obj);
+ RestHttpClient.post(originator, csePoa+"/~/"+remoteCseId+"/"+remoteCseName+"/"+aeRN+"?rcn=2", resource.toString(), 3);
+
+ /** contentInstance creation **/
+ obj = new JSONObject();
+ obj.put("cnf", "application/text");
+ obj.put("con", "OFF");
+ resource = new JSONObject();
+ resource.put("m2m:cin", obj);
+ RestHttpClient.post(originator, csePoa+"/~/"+remoteCseId+"/"+remoteCseName+"/"+aeRN+"/"+CT_name+"?rcn=3", resource.toString(), 4);
+
+ /**Subscription creation **/
+ JSONArray array = new JSONArray();
+ array.put(notificationURI);
+ obj = new JSONObject();
+ obj.put("nu", array);
+ obj.put("rn", subRN);
+ obj.put("nct", 2);
+ resource = new JSONObject();
+ resource.put("m2m:sub", obj);
+ RestHttpClient.post(originator, csePoa+"/~/"+remoteCseId+"/"+remoteCseName+"/"+aeRN+"/"+CT_name, resource.toString(), 23);
+
+ }
+
+ public static void main(String[] args) throws Exception {
+ /** Starting Server **/
+ HttpServer server = null;
+ try {
+ server = HttpServer.create(new InetSocketAddress(AE_port), 0);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ server.createContext("/", new MyHandler());
+ server.setExecutor(Executors.newCachedThreadPool());
+ server.start();
+
+ /** Initial resources creation **/
+ Init();
+ }
+
+ static class MyHandler implements HttpHandler {
+
+ public void handle(HttpExchange httpExchange) {
+ System.out.println("Event Recieved!");
+
+ try{
+ InputStream in = httpExchange.getRequestBody();
+
+ String requestBody = "";
+ int i;char c;
+ while ((i = in.read()) != -1) {
+ c = (char) i;
+ requestBody = (String) (requestBody+c);
+ }
+
+ System.out.println(requestBody);
+
+ String responseBudy ="";
+ byte[] out = responseBudy.getBytes("UTF-8");
+ httpExchange.sendResponseHeaders(200, out.length);
+ OutputStream os = httpExchange.getResponseBody();
+ os.write(out);
+ os.close();
+
+ } catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+ }
+}
+
diff --git a/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/AEMN.java b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/AEMN.java
new file mode 100644
index 0000000..b37ce74
--- /dev/null
+++ b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/AEMN.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.om2m.client.java;
+
+
+import org.eclipse.om2m.client.java.tools.RestHttpClient;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+public class AEMN extends TestConfig {
+ private static String aeRN = "gateway_ae";
+ private static String aeRId = "Cgateway_ae";
+ private static String aeRN_1 = "light_ae1";
+ private static String aeRId_1 = "Clight_ae1";
+ private static String aeRN_2 = "light_ae2";
+ private static String aeRId_2 = "Clight_ae2";
+ private static String aeRId_3 = "Csmartphone_ae";
+ private static String cnRN = "light";
+ private static String acpRN = "MN-CSEAcp";
+ private static String groupRN = "containers_grp";
+
+ public static void main(String[] args) throws Exception {
+
+ /** Application Registry **/
+ JSONObject obj = new JSONObject();
+ obj.put("rn", aeRN);
+ obj.put("api", "A01.com.company.gatewayApp");
+ obj.put("rr", false);
+ JSONObject resource = new JSONObject();
+ resource.put("m2m:ae", obj);
+ RestHttpClient.post(originator, csePoa+"/~/"+remoteCseId+"/"+remoteCseName+"?rcn=1", resource.toString(), 2);
+
+ /** Access right resource creation **/
+ JSONArray acor = new JSONArray();
+ acor.put(aeRId);
+ acor.put(aeRId_1);
+ acor.put(aeRId_2);
+ acor.put(aeRId_3);
+ acor.put("admin:admin");
+
+ JSONObject item = new JSONObject();
+ item.put("acor", acor);
+ item.put("acop", 63);
+
+ JSONObject acr_1 = new JSONObject();
+ acr_1.put("acr",item);
+
+ acor = new JSONArray();
+ acor.put(aeRN);
+ acor.put("admin:admin");
+
+ item = new JSONObject();
+ item.put("acor", acor);
+ item.put("acop", 63);
+
+ JSONObject acr_2 = new JSONObject();
+ acr_2.put("acr",item);
+
+ JSONObject obj_1 = new JSONObject();
+ obj_1.put("rn", acpRN);
+ obj_1.put("pv", acr_1);
+ obj_1.put("pvs", acr_2);
+
+ resource = new JSONObject();
+ resource.put("m2m:acp", obj_1);
+
+ RestHttpClient.post(originator, csePoa+"/~/"+remoteCseId+"/"+remoteCseName+"/", resource.toString(), 1);
+
+
+ /** Group resource creation **/
+ JSONArray array = new JSONArray();
+ array.put("/"+remoteCseId+"/"+remoteCseName+"/"+aeRN_1+"/"+cnRN);
+ array.put("/"+remoteCseId+"/"+remoteCseName+"/"+aeRN_2+"/"+cnRN);
+ obj = new JSONObject();
+ obj.put("mid", array);
+ obj.put("rn", groupRN);
+ obj.put("mnm", 3);
+ resource = new JSONObject();
+ resource.put("m2m:grp", obj);
+ RestHttpClient.post(originator, csePoa+"/~/"+remoteCseId+"/"+remoteCseName, resource.toString(), 9);
+ }
+
+}
diff --git a/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/INAE.java b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/INAE.java
new file mode 100644
index 0000000..8e94176
--- /dev/null
+++ b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/INAE.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.om2m.client.java;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import org.eclipse.om2m.client.java.tools.RestHttpClient;
+import org.json.JSONObject;
+
+public class INAE extends TestConfig{
+
+ private static String aeRN = "smartphone_ae";
+ private static String aeRId = "Csmartphone_ae";
+ private static String groupRN = "containers_grp";
+
+ public static void main(String[] args) throws Exception {
+ Init();
+ JSONObject obj, resource;
+ while (true) {
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ System.out.print("Switch light (ON/OFF) ");
+ String s = br.readLine();
+
+ obj = new JSONObject();
+ resource = new JSONObject();
+ obj.put("cnf", "application/text");
+ obj.put("con", s);
+ resource.put("m2m:cin", obj);
+ RestHttpClient.post(originator, csePoa+"/~/"+remoteCseId+"/"+remoteCseName+"/"+groupRN+"/"+"fopt", resource.toString(), 4);
+
+ }
+ }
+
+ private static void Init () throws Exception {
+ JSONObject obj = new JSONObject();
+ obj.put("rn", aeRN);
+ obj.put("api", "A01.com.company.lightControlApp");
+ obj.put("rr", "false");
+ JSONObject resource = new JSONObject();
+ resource.put("m2m:ae", obj);
+ RestHttpClient.post(aeRId, csePoa+"/~/"+cseId+"/"+cseName+"?rcn=1", resource.toString(), 2);
+
+ }
+}
diff --git a/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/TestConfig.java b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/TestConfig.java
new file mode 100644
index 0000000..a8ec46c
--- /dev/null
+++ b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/TestConfig.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.om2m.client.java;
+
+public class TestConfig {
+
+ public final static String originator="admin:admin";
+ public final static String cseProtocol="http";
+
+ public final static String cseIp = "192.168.0.2";
+ public final static int csePort = 8080;
+
+ public final static String cseId = "server";
+ public final static String cseName = "server";
+
+ public final static String remoteCseIp = "192.168.0.5";
+ public final static int remoteCSEPort = 8282;
+
+ public final static String remoteCseId = "gateway-1";
+ public final static String remoteCseName = "gateway-1";
+
+ public final static String csePoa = cseProtocol+"://"+cseIp+":"+csePort;
+ public final static String remoteCsePoa = cseProtocol+"://"+remoteCseIp+":"+remoteCSEPort;
+}
diff --git a/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/tools/HttpResponse.java b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/tools/HttpResponse.java
new file mode 100644
index 0000000..1c7beb6
--- /dev/null
+++ b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/tools/HttpResponse.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.om2m.client.java.tools;
+
+public class HttpResponse {
+ private int statusCode;
+ private String body;
+
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ public void setStatusCode(int statusCode) {
+ this.statusCode = statusCode;
+ }
+
+ public String getBody() {
+ return body;
+ }
+
+ public void setBody(String body) {
+ this.body = body;
+ }
+}
diff --git a/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/tools/RestHttpClient.java b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/tools/RestHttpClient.java
new file mode 100644
index 0000000..d092489
--- /dev/null
+++ b/org.eclipse.om2m.client.java/src/main/java/org/eclipse/om2m/client/java/tools/RestHttpClient.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.om2m.client.java.tools;
+
+import java.io.IOException;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.*;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+public class RestHttpClient {
+
+ public static HttpResponse get(String originator, String uri) {
+ System.out.println("HTTP GET "+uri);
+ CloseableHttpClient httpclient = HttpClientBuilder.create()
+ .disableAutomaticRetries()
+ .build();
+ HttpGet httpGet= new HttpGet(uri);
+
+ httpGet.addHeader("x-m2m-ri",generateRI());
+ httpGet.addHeader("x-m2m-origin",originator);
+ httpGet.addHeader("Accept","application/json");
+
+ HttpResponse httpResponse = new HttpResponse();
+
+ try {
+ CloseableHttpResponse closeableHttpResponse = httpclient.execute(httpGet);
+ try{
+ httpResponse.setStatusCode(closeableHttpResponse.getStatusLine().getStatusCode());
+ httpResponse.setBody(EntityUtils.toString(closeableHttpResponse.getEntity()));
+ }finally{
+ closeableHttpResponse.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.out.println("HTTP Response "+httpResponse.getStatusCode()+"\n"+httpResponse.getBody());
+ return httpResponse;
+ }
+
+ public static HttpResponse put(String originator, String uri, String body) {
+ System.out.println("HTTP PUT "+uri+"\n"+body);
+
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpPut httpPut= new HttpPut(uri);
+
+ httpPut.addHeader("X-M2M-RI",generateRI());
+ httpPut.addHeader("X-M2M-Origin",originator);
+ httpPut.addHeader("Content-Type","application/json");
+ httpPut.addHeader("Accept","application/json");
+
+ HttpResponse httpResponse = new HttpResponse();
+ try {
+ CloseableHttpResponse closeableHttpResponse =null;
+ try {
+ httpPut.setEntity(new StringEntity(body));
+ closeableHttpResponse= httpclient.execute(httpPut);
+ httpResponse.setStatusCode(closeableHttpResponse.getStatusLine().getStatusCode());
+ httpResponse.setBody(EntityUtils.toString(closeableHttpResponse.getEntity()));
+
+ }finally{
+ closeableHttpResponse.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.out.println("HTTP Response "+httpResponse.getStatusCode()+"\n"+httpResponse.getBody());
+
+ return httpResponse ;
+ }
+
+ public static HttpResponse post(String originator, String uri, String body, int ty) {
+ System.out.println("HTTP POST "+uri+"\n"+body);
+
+ final CloseableHttpClient httpclient = HttpClientBuilder.create()
+ .disableAutomaticRetries()
+ .build();
+ final HttpPost httpPost = new HttpPost(uri);
+
+ httpPost.addHeader("X-M2M-RI",generateRI());
+ httpPost.addHeader("X-M2M-Origin",originator);
+ httpPost.addHeader("Accept","application/json");
+
+ httpPost.addHeader("Content-Type","application/json;ty="+ty);
+
+ final HttpResponse httpResponse = new HttpResponse();
+
+ try{
+ httpPost.setEntity(new StringEntity(body));
+ try {
+ CloseableHttpResponse closeableHttpResponse=null;
+ closeableHttpResponse = httpclient.execute(httpPost);
+ httpResponse.setStatusCode(closeableHttpResponse.getStatusLine().getStatusCode());
+ httpResponse.setBody(EntityUtils.toString(closeableHttpResponse.getEntity()));
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.out.println("HTTP Response "+httpResponse.getStatusCode()+"\n"+httpResponse.getBody());
+ return httpResponse ;
+ }
+
+ public static HttpResponse delete(String originator, String uri) {
+ System.out.println("HTTP DELETE "+uri);
+
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpDelete httpDelete = new HttpDelete(uri);
+
+ httpDelete.addHeader("X-M2M-RI",generateRI());
+ httpDelete.addHeader("X-M2M-Origin",originator);
+ httpDelete.addHeader("Accept","application/json");
+
+
+ HttpResponse httpResponse = new HttpResponse();
+ try {
+ CloseableHttpResponse closeableHttpResponse = httpclient.execute(httpDelete);
+ try {
+ httpResponse.setStatusCode(closeableHttpResponse.getStatusLine().getStatusCode());
+ httpResponse.setBody(EntityUtils.toString(closeableHttpResponse.getEntity()));
+ }finally{
+ closeableHttpResponse.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.out.println("HTTP Response "+httpResponse.getStatusCode()+"\n"+httpResponse.getBody());
+ return httpResponse ;
+ }
+
+ public static String generateRI(){
+ Integer random = (int)(Math.random()*1000)+100000;
+ return random.toString();
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.om2m.client.js/onem2m-actuator.js b/org.eclipse.om2m.client.js/onem2m-actuator.js
new file mode 100644
index 0000000..a00b067
--- /dev/null
+++ b/org.eclipse.om2m.client.js/onem2m-actuator.js
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+var express = require('express');
+var path = require('path');
+var bodyParser = require('body-parser');
+var request = require('request');
+var app = express();
+app.use(bodyParser.json());
+
+app.listen(4000, function () {
+ console.log('AE Actuator listening on port 4000!');
+});
+
+app.post('/', function (req, res) {
+ console.log("\n◀◀◀◀◀")
+ console.log(req.body);
+ var content = req.body["m2m:sgn"].nev.rep["m2m:cin"].con;
+ console.log("Actuator switched to "+content);
+ res.sendStatus(200);
+});
+
+createAE();
+function createAE(){
+ console.log("\n▶▶▶▶▶");
+ var originator = "Cae-actuator";
+ var method = "POST";
+ var uri= "http://127.0.0.1:8080/~/in-cse/in-name";
+ var resourceType=2;
+ var requestId = "123456";
+ var representation = {
+ "m2m:ae":{
+ "rn":"myactuator",
+ "api":"app.company.com",
+ "rr":"true",
+ "poa":["http://127.0.0.1:4000/"]
+ }
+ };
+
+ console.log(method+" "+uri);
+ console.log(representation);
+
+ var options = {
+ uri: uri,
+ method: method,
+ headers: {
+ "X-M2M-Origin": originator,
+ "X-M2M-RI": requestId,
+ "Content-Type": "application/json;ty="+resourceType
+ },
+ json: representation
+ };
+
+ request(options, function (error, response, body) {
+ console.log("◀◀◀◀◀");
+ if(error){
+ console.log(error);
+ }else{
+ console.log(response.statusCode);
+ console.log(body);
+ createContainer();
+ }
+ });
+}
+
+
+function createContainer(){
+ console.log("\n▶▶▶▶▶");
+ var originator = "Cae-actuator";
+ var method = "POST";
+ var uri= "http://127.0.0.1:8080/~/in-cse/in-name/myactuator";
+ var resourceType=3;
+ var requestId = "123456";
+ var representation = {
+ "m2m:cnt":{
+ "rn":"switch",
+ "mni":100
+
+ }
+ };
+
+ console.log(method+" "+uri);
+ console.log(representation);
+
+ var options = {
+ uri: uri,
+ method: method,
+ headers: {
+ "X-M2M-Origin": originator,
+ "X-M2M-RI": requestId,
+ "Content-Type": "application/json;ty="+resourceType
+ },
+ json: representation
+ };
+
+ request(options, function (error, response, body) {
+ console.log("◀◀◀◀◀");
+ if(error){
+ console.log(error);
+ }else{
+ console.log(response.statusCode);
+ console.log(body);
+ createContentInstance();
+ }
+ });
+}
+
+
+function createContentInstance(){
+ console.log("\n▶▶▶▶▶");
+ var originator = "Cae-actuator";
+ var method = "POST";
+ var uri= "http://127.0.0.1:8080/~/in-cse/in-name/myactuator/switch";
+ var resourceType=4;
+ var requestId = "123456";
+ var representation = {
+ "m2m:cin":{
+ "con": false
+ }
+ };
+
+ console.log(method+" "+uri);
+ console.log(representation);
+
+ var options = {
+ uri: uri,
+ method: method,
+ headers: {
+ "X-M2M-Origin": originator,
+ "X-M2M-RI": requestId,
+ "Content-Type": "application/json;ty="+resourceType
+ },
+ json: representation
+ };
+
+ request(options, function (error, response, body) {
+ console.log("◀◀◀◀◀");
+ if(error){
+ console.log(error);
+ }else{
+ console.log(response.statusCode);
+ console.log(body);
+ }
+ });
+}
+
+
+function createSubscription(){
+ console.log("\n▶▶▶▶▶");
+ var originator = "Cae-monitor-async";
+ var method = "POST";
+ var uri= "http://127.0.0.1:8080/~/in-cse/in-name/mysensor/luminosity";
+ var resourceType=23;
+ var requestId = "123456";
+ var representation = {
+ "m2m:sub": {
+ "rn": "subTest",
+ "nu": ["/server/Cae-actuator"],
+ "nct": 2,
+ "enc": {
+ "net": 3
+ }
+ }
+ };
+
+ console.log(method+" "+uri);
+ console.log(representation);
+
+ var options = {
+ uri: uri,
+ method: method,
+ headers: {
+ "X-M2M-Origin": originator,
+ "X-M2M-RI": requestId,
+ "Content-Type": "application/json;ty="+resourceType
+ },
+ json: representation
+ };
+
+ request(options, function (error, response, body) {
+ console.log("◀◀◀◀◀");
+ if(error){
+ console.log(error);
+ }else{
+ console.log(response.statusCode);
+ console.log(body);
+ }
+ });
+}
+
+
diff --git a/org.eclipse.om2m.client.js/onem2m-monitor-async.js b/org.eclipse.om2m.client.js/onem2m-monitor-async.js
new file mode 100644
index 0000000..f2fce5f
--- /dev/null
+++ b/org.eclipse.om2m.client.js/onem2m-monitor-async.js
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+var express = require('express');
+var path = require('path');
+var bodyParser = require('body-parser');
+var request = require('request');
+var app = express();
+app.use(bodyParser.json());
+
+app.listen(3000, function () {
+ console.log('AE Monitor listening on port 3000!');
+});
+
+app.post('/', function (req, res) {
+ console.log("\n◀◀◀◀◀")
+ console.log(req.body);
+
+ var content = req.body["m2m:sgn"].nev.rep["m2m:cin"].con;
+ console.log("Receieved luminosity: "+content);
+ if(content>5){
+ console.log("High luminosity => Switch lamp OFF");
+ createContenInstance(false);
+ }else{
+ console.log("Low luminosity => Switch lamp ON");
+ createContenInstance(true)
+ }
+ res.sendStatus(200);
+});
+
+createAE();
+function createAE(){
+ console.log("\n▶▶▶▶▶");
+ var originator = "Cae-monitor-async";
+ var method = "POST";
+ var uri= "http://127.0.0.1:8080/~/in-cse/in-name";
+ var resourceType=2;
+ var requestId = "123456";
+ var representation = {
+ "m2m:ae":{
+ "rn":"mymonitor-async",
+ "api":"app.company.com",
+ "rr":"true",
+ "poa":["http://127.0.0.1:3000/"]
+ }
+ };
+
+ console.log(method+" "+uri);
+ console.log(representation);
+
+ var options = {
+ uri: uri,
+ method: method,
+ headers: {
+ "X-M2M-Origin": originator,
+ "X-M2M-RI": requestId,
+ "Content-Type": "application/json;ty="+resourceType
+ },
+ json: representation
+ };
+
+ request(options, function (error, response, body) {
+ console.log("◀◀◀◀◀");
+ if(error){
+ console.log(error);
+ }else{
+ console.log(response.statusCode);
+ console.log(body);
+ createSubscription();
+ }
+ });
+}
+
+
+function createSubscription(){
+ console.log("\n▶▶▶▶▶");
+ var originator = "Cae-monitor-async";
+ var method = "POST";
+ var uri= "http://127.0.0.1:8080/~/in-cse/in-name/mysensor/luminosity";
+ var resourceType=23;
+ var requestId = "123456";
+ var representation = {
+ "m2m:sub": {
+ "rn": "subMonitor",
+ "nu": ["/server/Cae-monitor-async"],
+ "nct": 2,
+ "enc": {
+ "net": 3
+ }
+ }
+ };
+
+ console.log(method+" "+uri);
+ console.log(representation);
+
+ var options = {
+ uri: uri,
+ method: method,
+ headers: {
+ "X-M2M-Origin": originator,
+ "X-M2M-RI": requestId,
+ "Content-Type": "application/json;ty="+resourceType
+ },
+ json: representation
+ };
+
+ request(options, function (error, response, body) {
+ console.log("◀◀◀◀◀");
+ if(error){
+ console.log(error);
+ }else{
+ console.log(response.statusCode);
+ console.log(body);
+ }
+ });
+}
+
+function createContenInstance(value){
+ console.log("\n▶▶▶▶▶");
+ var originator = "Cae-monitor-async";
+ var method = "POST";
+ var uri= "http://127.0.0.1:8080/~/in-cse/in-name/myactuator/switch";
+ var resourceType=4;
+ var requestId = "123456";
+ var representation = {
+ "m2m:cin":{
+ "con": value
+ }
+ };
+
+ console.log(method+" "+uri);
+ console.log(representation);
+
+ var options = {
+ uri: uri,
+ method: method,
+ headers: {
+ "X-M2M-Origin": originator,
+ "X-M2M-RI": requestId,
+ "Content-Type": "application/json;ty="+resourceType
+ },
+ json: representation
+ };
+
+ request(options, function (error, response, body) {
+ console.log("◀◀◀◀◀");
+ if(error){
+ console.log(error);
+ }else{
+ console.log(response.statusCode);
+ console.log(body);
+ }
+ });
+}
+
+
diff --git a/org.eclipse.om2m.client.js/onem2m-monitor-sync.js b/org.eclipse.om2m.client.js/onem2m-monitor-sync.js
new file mode 100644
index 0000000..cae557c
--- /dev/null
+++ b/org.eclipse.om2m.client.js/onem2m-monitor-sync.js
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+var bodyParser = require('body-parser');
+var request = require('request');
+
+createAE();
+
+function createAE(){
+ console.log("\n▶▶▶▶▶");
+ var originator = "Cae-monitor-sync";
+ var method = "POST";
+ var uri= "http://127.0.0.1:8080/~/in-cse/in-name";
+ var resourceType=2;
+ var requestId = "123456";
+ var representation = {
+ "m2m:ae":{
+ "rn":"mymonitor-sync",
+ "api":"app.company.com",
+ "rr":"false"
+ }
+ };
+
+ console.log(method+" "+uri);
+ console.log(representation);
+
+ var options = {
+ uri: uri,
+ method: method,
+ headers: {
+ "X-M2M-Origin": originator,
+ "X-M2M-RI": requestId,
+ "Content-Type": "application/json;ty="+resourceType
+ },
+ json: representation
+ };
+
+ request(options, function (error, response, body) {
+ console.log("◀◀◀◀◀");
+ if(error){
+ console.log(error);
+ }else{
+ console.log(response.statusCode);
+ console.log(body);
+
+ setInterval(function() {
+ retrieveContentInstance();
+ }, 5000);
+ }
+ });
+}
+
+
+function retrieveContentInstance(){
+ console.log("\n▶▶▶▶▶");
+ var originator = "Cae-monitor-sync";
+ var method = "GET";
+ var uri= "http://127.0.0.1:8080/~/in-cse/in-name/mysensor/luminosity/la";
+ var requestId = "123456";
+
+ console.log(method+" "+uri);
+
+ var options = {
+ uri: uri,
+ method: method,
+ headers: {
+ "X-M2M-Origin": originator,
+ "X-M2M-RI": requestId,
+ "Content-Type": "application/json"
+ }
+ };
+
+ request(options, function (error, response, body) {
+ console.log("◀◀◀◀◀");
+ if(error){
+ console.log(error);
+ }else{
+ console.log(response.statusCode);
+ console.log(body);
+ var jsonBody = JSON.parse(body);
+ var value = jsonBody["m2m:cin"].con;
+ console.log("Receieved luminosity: "+value);
+
+ if(value>5){
+ console.log("High luminosity => Switch lamp OFF");
+ createContentInstance(false);
+ }else{
+ console.log("Low luminosity => Switch lamp ON");
+ createContentInstance(true);
+ }
+ }
+ });
+}
+
+function createContentInstance(value){
+ console.log("\n▶▶▶▶▶");
+ var originator = "Cae-monitor-sync";
+ var method = "POST";
+ var uri= "http://127.0.0.1:8080/~/in-cse/in-name/myactuator/switch";
+ var resourceType=4;
+ var requestId = "123456";
+ var representation = {
+ "m2m:cin":{
+ "con": value
+ }
+ };
+
+ console.log(method+" "+uri);
+ console.log(representation);
+
+ var options = {
+ uri: uri,
+ method: method,
+ headers: {
+ "X-M2M-Origin": originator,
+ "X-M2M-RI": requestId,
+ "Content-Type": "application/json;ty="+resourceType
+ },
+ json: representation
+ };
+
+ request(options, function (error, response, body) {
+ console.log("◀◀◀◀◀");
+ if(error){
+ console.log(error);
+ }else{
+ console.log(response.statusCode);
+ console.log(body);
+ }
+ });
+}
diff --git a/org.eclipse.om2m.client.js/onem2m-sensor.js b/org.eclipse.om2m.client.js/onem2m-sensor.js
new file mode 100644
index 0000000..f846e4c
--- /dev/null
+++ b/org.eclipse.om2m.client.js/onem2m-sensor.js
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * Copyright (c) 2016- 2017 SENSINOV (www.sensinov.com)
+ * 41 Rue de la découverte 31676 Labège - France
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+var express = require('express');
+var request = require('request');
+
+createAE();
+function createAE(){
+ console.log("\n▶▶▶▶▶");
+ var originator = "Cae-sensor";
+ var method = "POST";
+ var uri= "http://127.0.0.1:8080/~/in-cse/in-name";
+ var resourceType=2;
+ var requestId = "123456";
+ var representation = {
+ "m2m:ae":{
+ "rn":"mysensor",
+ "api":"app.company.com",
+ "rr":"false"
+ }
+ };
+
+ console.log(method+" "+uri);
+ console.log(representation);
+
+ var options = {
+ uri: uri,
+ method: method,
+ headers: {
+ "X-M2M-Origin": originator,
+ "X-M2M-RI": requestId,
+ "Content-Type": "application/json;ty="+resourceType
+ },
+ json: representation
+ };
+
+ request(options, function (error, response, body) {
+ console.log("◀◀◀◀◀");
+ if(error){
+ console.log(error);
+ }else{
+ console.log(response.statusCode);
+ console.log(body);
+ createContainer();
+ }
+ });
+}
+
+
+function createContainer(){
+ console.log("\n▶▶▶▶▶");
+ var originator = "Cae-sensor";
+ var method = "POST";
+ var uri= "http://127.0.0.1:8080/~/in-cse/in-name/mysensor";
+ var resourceType=3;
+ var requestId = "123456";
+ var representation = {
+ "m2m:cnt":{
+ "rn":"luminosity",
+ "mni":100
+
+ }
+ };
+
+ console.log(method+" "+uri);
+ console.log(representation);
+
+ var options = {
+ uri: uri,
+ method: method,
+ headers: {
+ "X-M2M-Origin": originator,
+ "X-M2M-RI": requestId,
+ "Content-Type": "application/json;ty="+resourceType
+ },
+ json: representation
+ };
+
+ request(options, function (error, response, body) {
+ console.log("◀◀◀◀◀");
+ if(error){
+ console.log(error);
+ }else{
+ console.log(response.statusCode);
+ console.log(body);
+ setInterval(function() {
+ createContentInstance();
+ }, 5000);
+ }
+ });
+}
+
+function createContentInstance(){
+ console.log("\n▶▶▶▶▶");
+ var originator = "Cae-sensor";
+ var method = "POST";
+ var uri= "http://127.0.0.1:8080/~/in-cse/in-name/mysensor/luminosity";
+ var resourceType=4;
+ var requestId = "123456";
+ var representation = {
+ "m2m:cin":{
+ "con": Math.floor(Math.random()*10)
+ }
+ };
+
+ console.log(method+" "+uri);
+ console.log(representation);
+
+ var options = {
+ uri: uri,
+ method: method,
+ headers: {
+ "X-M2M-Origin": originator,
+ "X-M2M-RI": requestId,
+ "Content-Type": "application/json;ty="+resourceType
+ },
+ json: representation
+ };
+
+ request(options, function (error, response, body) {
+ console.log("◀◀◀◀◀");
+ if(error){
+ console.log(error);
+ }else{
+ console.log(response.statusCode);
+ console.log(body);
+ }
+ });
+}
diff --git a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AnnounceableResource.java b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AnnounceableResource.java
index e543b22..3a4f74f 100644
--- a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AnnounceableResource.java
+++ b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AnnounceableResource.java
@@ -69,7 +69,7 @@
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "announceableResource")
@XmlSeeAlso({ LocationPolicy.class, RemoteCSE.class, Node.class, AE.class,
- MgmtObj.class, Group.class, Container.class, AbstractFlexContainer.class })
+ NodeAnnc.class, MgmtObj.class, Group.class, Container.class, AbstractFlexContainer.class })
@MappedSuperclass
public class AnnounceableResource extends RegularResource {
diff --git a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AnnouncedMgmtResource.java b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AnnouncedMgmtResource.java
index 4a89a21..804705c 100644
--- a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AnnouncedMgmtResource.java
+++ b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AnnouncedMgmtResource.java
@@ -66,7 +66,7 @@
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "announcedMgmtResource", propOrder = { "mgmtDefinition",
- "objectIDs", "objectPaths", "description" })
+ "objectIDs", "objectPaths", "description", "subscriptions", "childResource" })
@XmlSeeAlso({ EventLogAnnc.class, RebootAnnc.class, DeviceCapabilityAnnc.class,
DeviceInfoAnnc.class, SoftwareAnnc.class, FirmwareAnnc.class,
AreaNwkDeviceInfoAnnc.class, AreaNwkInfoAnnc.class, BatteryAnnc.class,
@@ -86,6 +86,12 @@
@XmlElement(name = ShortName.DESCRIPTION, namespace="")
protected String description;
+
+ @XmlElement(name = ShortName.CHILD_RESOURCE, namespace="")
+ protected List<ChildResourceRef> childResource;
+
+ @XmlElement(namespace = "http://www.onem2m.org/xml/protocols", name = ShortName.SUB)
+ protected List<Subscription> subscriptions;
/**
* Gets the value of the mgmtDefinition property.
@@ -187,4 +193,64 @@
this.description = value;
}
+ /**
+ * Gets the value of the childResource property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list, not a
+ * snapshot. Therefore any modification you make to the returned list will
+ * be present inside the JAXB object. This is why there is not a
+ * <CODE>set</CODE> method for the childResource property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ *
+ * <pre>
+ * getChildResource().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link ChildResourceRef }
+ *
+ *
+ */
+ public List<ChildResourceRef> getChildResource() {
+ if (childResource == null) {
+ childResource = new ArrayList<ChildResourceRef>();
+ }
+ return this.childResource;
+ }
+
+ /**
+ * Gets the value of the subscription property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list, not a
+ * snapshot. Therefore any modification you make to the returned list will
+ * be present inside the JAXB object. This is why there is not a
+ * <CODE>set</CODE> method for the subscription property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ *
+ * <pre>
+ * getSubscription().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list
+ * {@link Subscription }
+ *
+ *
+ */
+ public List<Subscription> getSubscriptions() {
+ if (subscriptions == null) {
+ subscriptions = new ArrayList<Subscription>();
+ }
+ return this.subscriptions;
+ }
+
}
diff --git a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AreaNwkDeviceInfoAnnc.java b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AreaNwkDeviceInfoAnnc.java
index 87b44ad..4cb6d72 100644
--- a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AreaNwkDeviceInfoAnnc.java
+++ b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AreaNwkDeviceInfoAnnc.java
@@ -76,28 +76,34 @@
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = ShortName.AREA_NWK_DEVICE_INFO_ANNC)
-public class AreaNwkDeviceInfoAnnc extends MgmtObjAnncWithChildren {
+public class AreaNwkDeviceInfoAnnc extends AnnouncedMgmtResource {
@XmlElement(required = false, name = ShortName.DEV_ID, namespace="")
- protected String devID;
+ protected String devID;
+
@XmlElement(required = false, name = ShortName.DEV_TYPE, namespace="")
- protected String devType;
+ protected String devType;
+
@XmlElement(required = false, name = ShortName.AREA_NWK_ID, namespace="")
- @XmlSchemaType(name = "anyURI")
- protected String areaNwkId;
+ @XmlSchemaType(name = "anyURI")
+ protected String areaNwkId;
+
@XmlSchemaType(name = "nonNegativeInteger")
@XmlElement(name = ShortName.SLEEP_INTERVAL, namespace="")
- protected BigInteger sleepInterval;
+ protected BigInteger sleepInterval;
+
@XmlSchemaType(name = "nonNegativeInteger")
@XmlElement(name = ShortName.SLEEP_DURATION, namespace="")
- protected BigInteger sleepDuration;
+ protected BigInteger sleepDuration;
+
@XmlElement(name = ShortName.STATUS, namespace="")
- protected String status;
+ protected String status;
+
@XmlList
@XmlElement(required = false, name = ShortName.LIST_OF_NEIGHBORS, namespace="")
- protected List<String> listOfNeighbors;
-
-
+ protected List<String> listOfNeighbors;
+
+
public AreaNwkDeviceInfoAnnc() {
super();
setMgmtDefinition(MgmtDefinitionTypes.AREA_NWK_DEVICE_INFO);
diff --git a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AreaNwkInfoAnnc.java b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AreaNwkInfoAnnc.java
index a36bd8a..61d2717 100644
--- a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AreaNwkInfoAnnc.java
+++ b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/AreaNwkInfoAnnc.java
@@ -69,20 +69,20 @@
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = ShortName.AREA_NWK_INFO_ANNC)
-public class AreaNwkInfoAnnc extends MgmtObjAnncWithChildren {
+public class AreaNwkInfoAnnc extends AnnouncedMgmtResource {
@XmlElement(name = ShortName.AREA_NWK_TYPE, required = false, namespace="")
- protected String areaNwkType;
-
- @XmlList
- @XmlElement(name = ShortName.LIST_DEVICES, required = false, namespace="")
- protected List<String> listOfDevices;
-
+ protected String areaNwkType;
- public AreaNwkInfoAnnc() {
- super();
- setMgmtDefinition(MgmtDefinitionTypes.AREA_NWK_INFO);
- }
+ @XmlList
+ @XmlElement(name = ShortName.LIST_DEVICES, required = false, namespace="")
+ protected List<String> listOfDevices;
+
+
+ public AreaNwkInfoAnnc() {
+ super();
+ setMgmtDefinition(MgmtDefinitionTypes.AREA_NWK_INFO);
+ }
/**
* Gets the value of the areaNwkType property.
diff --git a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/Battery.java b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/Battery.java
index fc5da09..37bcfae 100644
--- a/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/Battery.java
+++ b/org.eclipse.om2m.commons/src/main/java/org/eclipse/om2m/commons/resource/Battery.java
@@ -71,7 +71,6 @@
@XmlSchemaType(name = "unsignedInt")
@XmlElement(name = ShortName.BATTERY_LEVEL, namespace="")
protected long batteryLevel;
-
@XmlElement(name = ShortName.BATTERY_STATUS, required = true, namespace="")
protected BigInteger batteryStatus;
diff --git a/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/announcer/Announcer.java b/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/announcer/Announcer.java
index d14c9c5..8825eb1 100644
--- a/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/announcer/Announcer.java
+++ b/org.eclipse.om2m.core/src/main/java/org/eclipse/om2m/core/announcer/Announcer.java
@@ -34,6 +34,7 @@
import org.eclipse.om2m.commons.entities.AnnounceableSubordinateEntity;
import org.eclipse.om2m.commons.entities.CreatedAnnouncedResourceEntity;
import org.eclipse.om2m.commons.entities.RemoteCSEEntity;
+import org.eclipse.om2m.commons.entities.ResourceEntity;
import org.eclipse.om2m.commons.exceptions.NotImplementedException;
import org.eclipse.om2m.commons.resource.AE;
import org.eclipse.om2m.commons.resource.AEAnnc;