First draft of client
This commit is contained in:
parent
21ce0d17ff
commit
7a789c5e66
20
client/.classpath
Normal file
20
client/.classpath
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
2
client/.gitignore
vendored
Normal file
2
client/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/bin/
|
||||
/target/
|
23
client/.project
Normal file
23
client/.project
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>client</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
8
client/.settings/org.eclipse.jdt.core.prefs
Normal file
8
client/.settings/org.eclipse.jdt.core.prefs
Normal file
@ -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
|
59
client/Californium.properties
Normal file
59
client/Californium.properties
Normal file
@ -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
|
85
client/pom.xml
Normal file
85
client/pom.xml
Normal file
@ -0,0 +1,85 @@
|
||||
<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>it.unipi.ing.ce.netpp</groupId>
|
||||
<artifactId>client</artifactId>
|
||||
<version>2019.11.0</version>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.californium</groupId>
|
||||
<artifactId>californium-core</artifactId>
|
||||
<version>2.0.0-M18</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.json</groupId>
|
||||
<artifactId>javax.json-api</artifactId>
|
||||
<version>1.1.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish</groupId>
|
||||
<artifactId>javax.json</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.9</version>
|
||||
<configuration>
|
||||
<downloadSources>true</downloadSources>
|
||||
<downloadJavadocs>false</downloadJavadocs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Set a compiler level -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Maven Assembly Plugin -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.4.1</version>
|
||||
<configuration>
|
||||
<!-- get all project dependencies -->
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<!-- MainClass in mainfest make a executable jar -->
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>netpp.client.Main</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<!-- bind to the packaging phase -->
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
59
client/src/netpp/client/Main.java
Normal file
59
client/src/netpp/client/Main.java
Normal file
@ -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 <url>");
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user