diff --git a/iot/tp1/.gitignore b/iot/tp1/.gitignore new file mode 100644 index 0000000..8f764ee --- /dev/null +++ b/iot/tp1/.gitignore @@ -0,0 +1,2 @@ +acme-onem2m +venv \ No newline at end of file diff --git a/iot/tp1/main.py b/iot/tp1/main.py new file mode 100644 index 0000000..e69de29 diff --git a/iot/tp1/requirements.txt b/iot/tp1/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/iot/tp1/run.sh b/iot/tp1/run.sh new file mode 100755 index 0000000..c4627d1 --- /dev/null +++ b/iot/tp1/run.sh @@ -0,0 +1,12 @@ +#!/bin/sh +set -e +cd "$(dirname "$(realpath "$0")")" + + +if ! [ -d acme-onem2m ] +then ./setup.sh +fi + + +cd acme-onem2m +python3 -m acme diff --git a/iot/tp1/setup.sh b/iot/tp1/setup.sh new file mode 100755 index 0000000..7a93ed8 --- /dev/null +++ b/iot/tp1/setup.sh @@ -0,0 +1,41 @@ +#!/bin/sh +set -e +cd "$(dirname "$(realpath "$0")")" + + +rm -fr ./venv +rm -fr acme-onem2m +python -m venv ./venv +source ./venv/bin/activate +git clone https://github.com/ankraft/ACME-oneM2M-CSE.git acme-onem2m +python -m pip install --requirement=./acme-onem2m/requirements.txt +python -m pip install --requirement=./requirements.txt + +echo " +[basic.config] +cseType=IN +cseID=id-in +cseName=cse-in +adminID=CAdmin +dataDirectory=\${baseDirectory} +networkInterface=0.0.0.0 +cseHost=10.75.69.114 +httpPort=8080 +logLevel=debug +databaseInMemory=True +consoleTheme=dark + +[cse.registration] +; Edit this to add more allowed originators. +allowedCSROriginators=id-in,id-mn,id-asn + +[textui] +startWithTUI=false + +[cse.operation.requests] +enable=true + +[http] +enableUpperTesterEndpoint=true +enableStructureEndpoint=true +" > acme-onem2m/acme.ini diff --git a/iot/tp1/src/part_2/step_a.sh b/iot/tp1/src/part_2/step_a.sh new file mode 100755 index 0000000..cc30e44 --- /dev/null +++ b/iot/tp1/src/part_2/step_a.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +curl -X POST \ + -H 'X-M2M-Origin:Cmysensor' \ + -H 'X-M2M-RI:123' \ + -H 'X-M2M-RVI:3' \ + -H'Content-Type:application/json;ty=2' \ + -H 'Accept:application/json' \ + -d '{"m2m:ae": {"rn":"MySensor", "api": "NMysensor", "rr": true, "srv": ["3"]}}' \ + http://127.0.0.1:8080/cse-in diff --git a/iot/tp1/src/part_2/step_b.sh b/iot/tp1/src/part_2/step_b.sh new file mode 100755 index 0000000..769395f --- /dev/null +++ b/iot/tp1/src/part_2/step_b.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +curl -X POST \ + -H 'X-M2M-Origin:Cmysensor' \ + -H 'X-M2M-RI:123' \ + -H 'X-M2M-RVI:3' \ + -H 'Content-Type:application/json;ty=3' \ + -H 'Accept:application/json' \ + -d '{"m2m:cnt": {"rn":"Container"}}' \ + http://127.0.0.1:8080/cse-in/MySensor diff --git a/iot/tp1/src/part_2/step_c.sh b/iot/tp1/src/part_2/step_c.sh new file mode 100755 index 0000000..0a0a577 --- /dev/null +++ b/iot/tp1/src/part_2/step_c.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +curl -X POST \ + -H 'X-M2M-Origin:Cmysensor' \ + -H 'X-M2M-RI:123' \ + -H 'X-M2M-RVI:3' \ + -H 'Content-Type:application/json;ty=4' \ + -H 'Accept:application/json' \ + -d '{"m2m:cin": {"cnf": "text/plain:0","con": "{\"unit\": \"celsius\", \"value\": \"22\"}"}}' \ + http://localhost:8080/cse-in/MySensor/Container diff --git a/iot/tp1/src/part_2/step_d.sh b/iot/tp1/src/part_2/step_d.sh new file mode 100755 index 0000000..d16852a --- /dev/null +++ b/iot/tp1/src/part_2/step_d.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +curl -X GET \ + -H 'X-M2M-Origin:Cmysensor' \ + -H 'X-M2M-RI:123' \ + -H 'X-M2M-RVI:3' \ + -H 'Content-Type:application/json' \ + -H 'Accept:application/json' \ + http://localhost:8080/cse-in/MySensor/Container/la diff --git a/iot/tp1/src/part_2/step_e.sh b/iot/tp1/src/part_2/step_e.sh new file mode 100755 index 0000000..39d010e --- /dev/null +++ b/iot/tp1/src/part_2/step_e.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +curl -X PUT -H 'X-M2M-Origin:Cmysensor' -H 'X-M2M-RI:123' -H 'X-M2M-RVI:3' -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"m2m:cnt": {"mni": 10}}' http://localhost:8080/cse-in/MySensor/Container diff --git a/iot/tp1/src/part_2/step_f.sh b/iot/tp1/src/part_2/step_f.sh new file mode 100755 index 0000000..eca693a --- /dev/null +++ b/iot/tp1/src/part_2/step_f.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -e + +curl -X DELETE -H 'X-M2M-Origin:Cmysensor' -H 'X-M2M-RI:123' -H 'X-M2M-RVI:3' -H 'Content-Type:application/json' -H 'Accept:application/json' http://localhost:8080/cse-in/MySensor/Container diff --git a/iot/tp1/src/part_3/step_a.sh b/iot/tp1/src/part_3/step_a.sh new file mode 100755 index 0000000..96c669a --- /dev/null +++ b/iot/tp1/src/part_3/step_a.sh @@ -0,0 +1,28 @@ +#!/bin/sh +set -e +alias log="echo ' +[step_a.sh]'" + + +RN_NAME="CINwithLabel" + + +log creates container +curl -X POST \ + -H 'X-M2M-Origin:Cmysensor' \ + -H 'X-M2M-RI:123' \ + -H 'X-M2M-RVI:3' \ + -H'Content-Type:application/json;ty=2' \ + -H 'Accept:application/json' \ + -d '{"m2m:ae": {"rn":"'$RN_NAME'", "api": "NMysensor", "rr": true, "srv": ["3"]}}' \ + http://127.0.0.1:8080/cse-in + +log emit notification +curl -X POST \ + -H 'X-M2M-Origin:Cmysensor' \ + -H 'X-M2M-RI:123' \ + -H 'X-M2M-RVI:3' \ + -H 'Content-Type:application/json;ty=4' \ + -H 'Accept:application/json' \ + -d '{"m2m:cin": {"rn":"CINwithLabel", "lbl": ["tag:temperature"], "cnf": "text/plain:0", "con": "{\"unit\": \"celsius\",\"value\": \"22\"}"}}' \ + http://127.0.0.1:8080/cse-in/MySensor/Container