iot tp3 coap
This commit is contained in:
parent
0bb5ae732f
commit
1395fdd566
23 changed files with 575 additions and 0 deletions
29
iot/tp3/occitanium-client/.gitignore
vendored
Normal file
29
iot/tp3/occitanium-client/.gitignore
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
8
iot/tp3/occitanium-client/.idea/.gitignore
generated
vendored
Normal file
8
iot/tp3/occitanium-client/.idea/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
6
iot/tp3/occitanium-client/.idea/misc.xml
generated
Normal file
6
iot/tp3/occitanium-client/.idea/misc.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" default="true" project-jdk-name="22" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
iot/tp3/occitanium-client/.idea/modules.xml
generated
Normal file
8
iot/tp3/occitanium-client/.idea/modules.xml
generated
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/occitanium-client.iml" filepath="$PROJECT_DIR$/occitanium-client.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
iot/tp3/occitanium-client/.idea/vcs.xml
generated
Normal file
6
iot/tp3/occitanium-client/.idea/vcs.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
37
iot/tp3/occitanium-client/Californium.properties
Normal file
37
iot/tp3/occitanium-client/Californium.properties
Normal file
|
@ -0,0 +1,37 @@
|
|||
#Californium CoAP Properties file
|
||||
#Wed Apr 10 19:25:41 CEST 2024
|
||||
ACK_RANDOM_FACTOR=1.5
|
||||
ACK_TIMEOUT=2000
|
||||
ACK_TIMEOUT_SCALE=2
|
||||
CROP_ROTATION_PERIOD=2000
|
||||
DEDUPLICATOR=DEDUPLICATOR_MARK_AND_SWEEP
|
||||
DEFAULT_BLOCK_SIZE=512
|
||||
DEFAULT_COAP_PORT=5683
|
||||
DEFAULT_ENDPOINT_THREAD_COUNT=1
|
||||
DEFAULT_LEISURE=5000
|
||||
EXCHANGE_LIFECYCLE=247000
|
||||
HTTP_CACHE_RESPONSE_MAX_AGE=86400
|
||||
HTTP_CACHE_SIZE=32
|
||||
HTTP_PORT=8080
|
||||
HTTP_SERVER_SOCKET_BUFFER_SIZE=8192
|
||||
HTTP_SERVER_SOCKET_TIMEOUT=100000
|
||||
MARK_AND_SWEEP_INTERVAL=10000
|
||||
MAX_MESSAGE_SIZE=1024
|
||||
MAX_RETRANSMIT=4
|
||||
MAX_TRANSMIT_WAIT=93000
|
||||
NOTIFICATION_CHECK_INTERVAL=86400000
|
||||
NOTIFICATION_CHECK_INTERVAL_COUNT=100
|
||||
NOTIFICATION_MAX_AGE=128000
|
||||
NOTIFICATION_REREGISTRATION_BACKOFF=2000
|
||||
NSTART=1
|
||||
PROBING_RATE=1.0
|
||||
SERVER_THRESD_NUMER=8
|
||||
UDP_CONNECTOR_DATAGRAM_SIZE=2000
|
||||
UDP_CONNECTOR_LOG_PACKETS=false
|
||||
UDP_CONNECTOR_OUT_CAPACITY=2147483647
|
||||
UDP_CONNECTOR_RECEIVER_THREAD_COUNT=1
|
||||
UDP_CONNECTOR_RECEIVE_BUFFER=0
|
||||
UDP_CONNECTOR_SENDER_THREAD_COUNT=1
|
||||
UDP_CONNECTOR_SEND_BUFFER=0
|
||||
USE_RANDOM_MID_START=true
|
||||
USE_RANDOM_TOKEN_START=true
|
BIN
iot/tp3/occitanium-client/lib/californium-core-1.0.0-SNAPSHOT.jar
Executable file
BIN
iot/tp3/occitanium-client/lib/californium-core-1.0.0-SNAPSHOT.jar
Executable file
Binary file not shown.
BIN
iot/tp3/occitanium-client/lib/element-connector-1.0-SNAPSHOT.jar
Executable file
BIN
iot/tp3/occitanium-client/lib/element-connector-1.0-SNAPSHOT.jar
Executable file
Binary file not shown.
29
iot/tp3/occitanium-client/occitanium-client.iml
Normal file
29
iot/tp3/occitanium-client/occitanium-client.iml
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library" exported="">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/lib/californium-core-1.0.0-SNAPSHOT.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library" exported="">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/lib/element-connector-1.0-SNAPSHOT.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
39
iot/tp3/occitanium-client/src/Main.java
Normal file
39
iot/tp3/occitanium-client/src/Main.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
import org.eclipse.californium.core.CoapClient;
|
||||
import org.eclipse.californium.core.CoapHandler;
|
||||
import org.eclipse.californium.core.CoapResponse;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
var light_client = new CoapClient("coap://localhost:5683/light");
|
||||
var lamp_client = new CoapClient("coap://localhost:5683/light/lamp");
|
||||
while (true) {
|
||||
var relation = light_client.observe(new LampUpdateHandler(lamp_client));
|
||||
relation.wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LampUpdateHandler implements CoapHandler {
|
||||
static String ON = "On";
|
||||
static String OFF = "Off";
|
||||
|
||||
CoapClient lamp_client;
|
||||
public LampUpdateHandler(CoapClient lamp_client_) {
|
||||
lamp_client = lamp_client_;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad(CoapResponse coapResponse) {
|
||||
var content = coapResponse.getResponseText();
|
||||
var level = Integer.parseInt(content);
|
||||
System.out.println("Light at " + level);
|
||||
var state = OFF;
|
||||
if (level < 5) state = ON;
|
||||
System.out.println("Sending state " + state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError() {
|
||||
System.err.println("Owno :s");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue