From 7a789c5e66fd743cd86353a5772c7d80a2c1f3be Mon Sep 17 00:00:00 2001 From: giomba Date: Sat, 16 Nov 2019 16:30:10 +0100 Subject: [PATCH] First draft of client --- client/.classpath | 20 +++++ client/.gitignore | 2 + client/.project | 23 ++++++ client/.settings/org.eclipse.jdt.core.prefs | 8 ++ client/Californium.properties | 59 ++++++++++++++ client/pom.xml | 85 +++++++++++++++++++++ client/src/netpp/client/Main.java | 59 ++++++++++++++ 7 files changed, 256 insertions(+) create mode 100644 client/.classpath create mode 100644 client/.gitignore create mode 100644 client/.project create mode 100644 client/.settings/org.eclipse.jdt.core.prefs create mode 100644 client/Californium.properties create mode 100644 client/pom.xml create mode 100644 client/src/netpp/client/Main.java diff --git a/client/.classpath b/client/.classpath new file mode 100644 index 0000000..149cb3c --- /dev/null +++ b/client/.classpath @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/client/.gitignore b/client/.gitignore new file mode 100644 index 0000000..09e3bc9 --- /dev/null +++ b/client/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/target/ diff --git a/client/.project b/client/.project new file mode 100644 index 0000000..3ee038d --- /dev/null +++ b/client/.project @@ -0,0 +1,23 @@ + + + client + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/client/.settings/org.eclipse.jdt.core.prefs b/client/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..2f5cc74 --- /dev/null +++ b/client/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/client/Californium.properties b/client/Californium.properties new file mode 100644 index 0000000..2098388 --- /dev/null +++ b/client/Californium.properties @@ -0,0 +1,59 @@ +#Californium CoAP Properties file +#Sat Nov 16 16:27:06 CET 2019 +HEALTH_STATUS_INTERVAL=0 +ACK_TIMEOUT=2000 +UDP_CONNECTOR_SEND_BUFFER=0 +ACK_TIMEOUT_SCALE=2.0 +HTTP_SERVER_SOCKET_TIMEOUT=100000 +USE_RANDOM_MID_START=true +BLOCKWISE_STRICT_BLOCK2_OPTION=false +MAX_ACTIVE_PEERS=150000 +PROTOCOL_STAGE_THREAD_COUNT=4 +BLOCKWISE_STATUS_LIFETIME=300000 +MAX_RESOURCE_BODY_SIZE=8192 +HTTP_CACHE_SIZE=32 +UDP_CONNECTOR_DATAGRAM_SIZE=2048 +UDP_CONNECTOR_RECEIVE_BUFFER=0 +DTLS_CONNECTION_ID_NODE_ID= +MAX_TRANSMIT_WAIT=93000 +NOTIFICATION_REREGISTRATION_BACKOFF=2000 +DEDUPLICATOR=DEDUPLICATOR_MARK_AND_SWEEP +COAP_PORT=5683 +MID_TACKER=GROUPED +COAP_SECURE_PORT=5684 +NETWORK_STAGE_RECEIVER_THREAD_COUNT=1 +HTTP_CACHE_RESPONSE_MAX_AGE=86400 +MULTICAST_BASE_MID=65000 +HTTP_SERVER_SOCKET_BUFFER_SIZE=8192 +EXCHANGE_LIFETIME=247000 +TLS_HANDSHAKE_TIMEOUT=10000 +DEDUPLICATOR_AUTO_REPLACE=true +TCP_CONNECTION_IDLE_TIMEOUT=10 +LEISURE=5000 +HTTP_PORT=8080 +DTLS_CONNECTION_ID_LENGTH= +NOTIFICATION_CHECK_INTERVAL=86400000 +CONGESTION_CONTROL_ALGORITHM=Cocoa +RESPONSE_MATCHING=STRICT +MID_TRACKER_GROUPS=16 +TOKEN_SIZE_LIMIT=8 +NETWORK_STAGE_SENDER_THREAD_COUNT=1 +TCP_WORKER_THREADS=1 +SECURE_SESSION_TIMEOUT=86400 +TCP_CONNECT_TIMEOUT=10000 +MAX_RETRANSMIT=4 +MAX_MESSAGE_SIZE=1024 +ACK_RANDOM_FACTOR=1.5 +NSTART=1 +MAX_LATENCY=100000 +PROBING_RATE=1.0 +USE_CONGESTION_CONTROL=false +MAX_SERVER_RESPONSE_DELAY=250000 +CROP_ROTATION_PERIOD=247000 +MAX_PEER_INACTIVITY_PERIOD=600 +UDP_CONNECTOR_OUT_CAPACITY=2147483647 +DTLS_AUTO_RESUME_TIMEOUT=30000 +PREFERRED_BLOCK_SIZE=512 +NON_LIFETIME=145000 +NOTIFICATION_CHECK_INTERVAL_COUNT=100 +MARK_AND_SWEEP_INTERVAL=10000 diff --git a/client/pom.xml b/client/pom.xml new file mode 100644 index 0000000..ea8d6be --- /dev/null +++ b/client/pom.xml @@ -0,0 +1,85 @@ + + 4.0.0 + it.unipi.ing.ce.netpp + client + 2019.11.0 + + + + + org.eclipse.californium + californium-core + 2.0.0-M18 + + + javax.json + javax.json-api + 1.1.4 + + + + org.glassfish + javax.json + 1.1 + + + + + + src + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.9 + + true + false + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.4.1 + + + + jar-with-dependencies + + + + + netpp.client.Main + + + + + + make-assembly + + package + + single + + + + + + + + + diff --git a/client/src/netpp/client/Main.java b/client/src/netpp/client/Main.java new file mode 100644 index 0000000..0811ce5 --- /dev/null +++ b/client/src/netpp/client/Main.java @@ -0,0 +1,59 @@ +package netpp.client; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import javax.json.Json; +import javax.json.JsonArray; +import javax.json.JsonObject; +import javax.json.JsonReader; + +import org.eclipse.californium.core.CoapClient; +import org.eclipse.californium.core.CoapResponse; +import org.eclipse.californium.elements.exception.ConnectorException; + +public class Main { + + public static void main(String[] args) { + if (args.length < 1) { + System.err.println("[F] Bad parameters"); + System.err.println("Usage: "); + System.err.println("$ exe "); + System.err.println(); + System.err.println("Example:"); + System.err.println("$ exe coap://[2001:db8::0]/urn:it.unipi.ing.ce.netpp:c00000003"); + System.exit(1); + } + + /* getting parameter from CLI */ + final String url = args[0]; + + /* subscribe to every node specified */ + System.err.println("[I] GET " + url); + + CoapClient client = new CoapClient(url); + CoapResponse response = null; + try { + response = client.get(); + } catch (ConnectorException | IOException e) { + e.printStackTrace(); + System.exit(1); + } + + /* parse SenML JSON */ + byte[] payload = response.getPayload(); + ByteArrayInputStream bis = new ByteArrayInputStream(payload); + JsonReader reader = Json.createReader(bis); + JsonArray senml = reader.readArray(); + JsonObject measurement = senml.getJsonObject(0); + String resourceName = measurement.getString("n"); + int resourceValue = measurement.getInt("v"); + + /* output result */ + System.out.println("Read Resource"); + System.out.println("name: " + resourceName); + System.out.println("value: " + resourceValue); + + System.exit(0); + } +}