diff --git a/events/2020.06.Online/TDs/Hitachi/README.md b/events/2020.06.Online/TDs/Hitachi/README.md new file mode 100644 index 00000000..0129b354 --- /dev/null +++ b/events/2020.06.Online/TDs/Hitachi/README.md @@ -0,0 +1,77 @@ +# Hitachi - June 2020 Online Plugfest + +We provide a simple LED lamp. + +![image of a simple LED lamp](simpleled.gif) + +## Web of Things from scratch + +Parts list: +- 1 RaspberryPi model B +- 1 breadboard +- 1 switch +- 1 LED +- 1 1k ohm resistor +- 4 wires + +1. create a circuit as follows: + +![schematic](schematic.svg) + +2. [install Node-RED](https://nodered.org/docs/getting-started/raspberrypi). + +3. [install node-red-node-discovery](https://flows.nodered.org/node/node-red-node-discovery) + +4. write a flow. + +![flow diagram](flow.png) +- [source file](flows.json) + +5. deploy. + + +## TD Discovery + +1. browse `_wot._tcp` service on plug-fest VPN. for example: +``` +% avahi-browse -r _wot._tcp ++ if0 IPv6 myRasPiLED _wot._tcp local ++ if0 IPv4 myRasPiLED _wot._tcp local += if0 IPv6 myRasPiLED _wot._tcp local + hostname = [ktorpi.local] + address = [xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx] + port = [1880] + txt = ["retrieve=/.well-known/wot-td"] += if0 IPv4 myRasPiLED _wot._tcp local + hostname = [ktorpi.local] + address = [xxx.xxx.xxx.xxx] + port = [1880] + txt = ["retrieve=/.well-known/wot-td"] +``` + +2. retrieve TD using above information +``` +% curl -u user:pass http://ktorpi.local:1880/.well-known/wot-td > hitachi-led.jsonld +``` + +### If you can't get a TD ... + +please use [this](./hitachi-led.jsonld). + +## Authentication + +Basic security scheme is supported. + +The credential will be posted on member's mailing list. + +## API + +* `GET /led`: read status of LED. + - OFF: `{"value": 0}` + - ON: `{"value": 1}` +* `PUT /led`: write status of LED. + - input value is same as above . +* websocket `/ws/toggled`: emit a LED status when switch is toggled + - emitting value is same as above. +* mDNS advertisement `myRasPiLED._wot._tcp` + - Because the discovery-node doesn't support subtypes, we didn't use subtypes. diff --git a/events/2020.06.Online/TDs/Hitachi/flow.png b/events/2020.06.Online/TDs/Hitachi/flow.png new file mode 100644 index 00000000..2954b538 Binary files /dev/null and b/events/2020.06.Online/TDs/Hitachi/flow.png differ diff --git a/events/2020.06.Online/TDs/Hitachi/flows.json b/events/2020.06.Online/TDs/Hitachi/flows.json new file mode 100644 index 00000000..b46298cc --- /dev/null +++ b/events/2020.06.Online/TDs/Hitachi/flows.json @@ -0,0 +1,319 @@ +[ + { + "id": "4214c046.c2618", + "type": "tab", + "label": "Simple Thing", + "disabled": false, + "info": "" + }, + { + "id": "aebf68cb.1c40b8", + "type": "rpi-gpio in", + "z": "4214c046.c2618", + "name": "Switch(GPIO25)", + "pin": "22", + "intype": "down", + "debounce": "25", + "read": true, + "x": 140, + "y": 80, + "wires": [ + [ + "59b8bbe9.a70264" + ] + ] + }, + { + "id": "3d450721.2e8e28", + "type": "rpi-gpio out", + "z": "4214c046.c2618", + "name": "LED(GPIO17)", + "pin": "11", + "set": true, + "level": "0", + "freq": "", + "out": "out", + "x": 730, + "y": 80, + "wires": [] + }, + { + "id": "59b8bbe9.a70264", + "type": "function", + "z": "4214c046.c2618", + "name": "toggle and write ledStatus", + "func": "let status = flow.get(\"ledStatus\") || 0;\n\nif (msg.payload === 1) {\n status ^= 1;\n flow.set(\"ledStatus\", status);\n msg.payload = status;\n} else {\n msg = null;\n}\n\nreturn msg;", + "outputs": 1, + "noerr": 0, + "x": 440, + "y": 80, + "wires": [ + [ + "3d450721.2e8e28", + "df85785b.4b7da8" + ] + ] + }, + { + "id": "366406e0.79f4ba", + "type": "http in", + "z": "4214c046.c2618", + "name": "", + "url": "/led", + "method": "get", + "upload": false, + "swaggerDoc": "", + "x": 120, + "y": 180, + "wires": [ + [ + "7e27775c.242258" + ] + ] + }, + { + "id": "d9cf26c5.386ee8", + "type": "http response", + "z": "4214c046.c2618", + "name": "", + "statusCode": "", + "headers": {}, + "x": 710, + "y": 180, + "wires": [] + }, + { + "id": "fe4718b2.4c4398", + "type": "http in", + "z": "4214c046.c2618", + "name": "", + "url": "/led", + "method": "put", + "upload": false, + "swaggerDoc": "", + "x": 120, + "y": 280, + "wires": [ + [ + "d6724a5b.49b248" + ] + ] + }, + { + "id": "83f00d03.a4b5a", + "type": "http response", + "z": "4214c046.c2618", + "name": "", + "statusCode": "", + "headers": {}, + "x": 710, + "y": 280, + "wires": [] + }, + { + "id": "7e27775c.242258", + "type": "function", + "z": "4214c046.c2618", + "name": "fetch ledStatus", + "func": "let status = flow.get(\"ledStatus\") || 0;\n\nmsg.payload = {value: status};\n\nreturn msg;", + "outputs": 1, + "noerr": 0, + "x": 400, + "y": 180, + "wires": [ + [ + "d9cf26c5.386ee8" + ] + ] + }, + { + "id": "4993753e.fe40ec", + "type": "http in", + "z": "4214c046.c2618", + "name": "", + "url": "/.well-known/wot-td", + "method": "get", + "upload": false, + "swaggerDoc": "", + "x": 170, + "y": 480, + "wires": [ + [ + "4645080f.1f98b8" + ] + ] + }, + { + "id": "4645080f.1f98b8", + "type": "function", + "z": "4214c046.c2618", + "name": "generate TD", + "func": "let ipaddress= \"ktorpi.local\";\n\nmsg.payload = {\n \"@context\": \"https://www.w3.org/2019/wot/td/v1\",\n id: \"urn:dev:mac:b827ebfffe4b6d0b\",\n title: \"myRasPiLED\",\n securityDefinitions: {\n basic_sc: {\n scheme: \"basic\",\n \"in\": \"header\"\n },\n no_sc: {\n scheme: \"nosec\"\n }\n },\n security: [\"basic_sc\"],\n properties: {\n led: {\n type: \"object\",\n properties: {\n value: { type: \"number\" },\n },\n forms: [\n {\n href: `http://${ipaddress}:1880/led`,\n op: [\n \"readproperty\",\n \"writeproperty\"\n ],\n contentType: \"application/json\",\n }\n ]\n }\n },\n events: {\n toggled: {\n data: {type: \"object\" },\n properties: {value: {type: \"numbber\" }},\n forms: [{\n href: `ws://${ipaddress}:1880/ws/toggled`,\n op: \"subscribeevent\",\n contentType: \"application/json\",\n security: [\"no_sc\"]\n }]\n }\n }\n};\n\nreturn msg;", + "outputs": 1, + "noerr": 0, + "x": 390, + "y": 480, + "wires": [ + [ + "3a8a42cf.f429ee" + ] + ] + }, + { + "id": "3a8a42cf.f429ee", + "type": "http response", + "z": "4214c046.c2618", + "name": "", + "statusCode": "", + "headers": {}, + "x": 710, + "y": 480, + "wires": [] + }, + { + "id": "d6724a5b.49b248", + "type": "function", + "z": "4214c046.c2618", + "name": "update ledStatus", + "func": "let msg1 = null;\n\nif (msg.payload.hasOwnProperty(\"value\")) {\n let s = msg.payload.value;\n if (s === 1 || s === 0) {\n msg1 = {payload: s}\n flow.set(\"ledStatus\", s);\n } \n}\n\nreturn [msg1, msg];", + "outputs": 2, + "noerr": 0, + "x": 410, + "y": 280, + "wires": [ + [ + "3d450721.2e8e28", + "df85785b.4b7da8" + ], + [ + "83f00d03.a4b5a" + ] + ] + }, + { + "id": "dfb4c4dc.65eb58", + "type": "websocket out", + "z": "4214c046.c2618", + "name": "", + "server": "1dfa7788.d62758", + "client": "", + "x": 740, + "y": 380, + "wires": [] + }, + { + "id": "df85785b.4b7da8", + "type": "function", + "z": "4214c046.c2618", + "name": "make event message", + "func": "msg.payload = {value: msg.payload};\nreturn msg;", + "outputs": 1, + "noerr": 0, + "x": 420, + "y": 380, + "wires": [ + [ + "dfb4c4dc.65eb58" + ] + ] + }, + { + "id": "c5a3bded.cf0f2", + "type": "comment", + "z": "4214c046.c2618", + "name": "toggle a LED with a swich", + "info": "", + "x": 130, + "y": 40, + "wires": [] + }, + { + "id": "19506a16.883ed6", + "type": "comment", + "z": "4214c046.c2618", + "name": "read property", + "info": "", + "x": 90, + "y": 140, + "wires": [] + }, + { + "id": "77bb239b.01dd5c", + "type": "comment", + "z": "4214c046.c2618", + "name": "write property", + "info": "", + "x": 90, + "y": 240, + "wires": [] + }, + { + "id": "a51ad130.98d64", + "type": "comment", + "z": "4214c046.c2618", + "name": "subscribe event", + "info": "", + "x": 100, + "y": 340, + "wires": [] + }, + { + "id": "4e72a6cf.5dcb18", + "type": "comment", + "z": "4214c046.c2618", + "name": "TD self hosting", + "info": "", + "x": 100, + "y": 440, + "wires": [] + }, + { + "id": "8edace6a.a9bde", + "type": "announce", + "z": "4214c046.c2618", + "name": "myRasPiLED", + "service": "_wot._tcp", + "port": "1880", + "txt": "\"retrieve\":\"/.well-known/wot-td\"", + "x": 730, + "y": 580, + "wires": [] + }, + { + "id": "598d290b.ec5288", + "type": "inject", + "z": "4214c046.c2618", + "name": "", + "topic": "", + "payload": "true", + "payloadType": "bool", + "repeat": "60", + "crontab": "", + "once": true, + "onceDelay": "5", + "x": 130, + "y": 580, + "wires": [ + [ + "8edace6a.a9bde" + ] + ] + }, + { + "id": "ed917734.6426a8", + "type": "comment", + "z": "4214c046.c2618", + "name": "Advertise this thing using mDNS", + "info": "", + "x": 150, + "y": 540, + "wires": [] + }, + { + "id": "1dfa7788.d62758", + "type": "websocket-listener", + "z": "", + "path": "/ws/toggled", + "wholemsg": "false" + } +] \ No newline at end of file diff --git a/events/2020.06.Online/TDs/Hitachi/hitachi-led.jsonld b/events/2020.06.Online/TDs/Hitachi/hitachi-led.jsonld new file mode 100644 index 00000000..0887c75e --- /dev/null +++ b/events/2020.06.Online/TDs/Hitachi/hitachi-led.jsonld @@ -0,0 +1,78 @@ +{ + "@context": "https://www.w3.org/2019/wot/td/v1", + "id": "urn:dev:mac:b827ebfffe4b6d0b", + "title": "myRasPiLED", + "titles": { + "en": "myRasPiLED", + "ja": "私のラズパイLED" + }, + "description": "Simple LED Lamp using Node-RED", + "descriptions": { + "en": "Simple LED Lamp using Node-RED", + "ja": "Node-REDをつかったシンプルなLEDランプ" + }, + "securityDefinitions": { + "basic_sc": { + "scheme": "basic", + "in": "header" + }, + "no_sc": { + "scheme": "nosec" + } + }, + "security": [ + "basic_sc" + ], + "properties": { + "led": { + "title": "LED status", + "titles": { + "en": "LED status", + "jp": "LEDの状態" + }, + "type": "object", + "properties": { + "value": { + "type": "number" + } + }, + "forms": [ + { + "href": "http://ktorpi.local:1880/led", + "op": [ + "readproperty", + "writeproperty" + ], + "contentType": "application/json" + } + ] + } + }, + "events": { + "toggled": { + "title": "switch is toggled", + "titles": { + "en": "switch is toggled", + "ja": "スイッチがトグルされた" + }, + "data": { + "type": "object" + }, + "properties": { + "value": { + "type": "number" + } + }, + "forms": [ + { + "href": "ws://ktorpi.local:1880/ws/toggled", + "op": "subscribeevent", + "contentType": "application/json", + "security": [ + "no_sc" + ] + } + ] + } + } +} diff --git a/events/2020.06.Online/TDs/Hitachi/schematic.svg b/events/2020.06.Online/TDs/Hitachi/schematic.svg new file mode 100644 index 00000000..f0eeab9f --- /dev/null +++ b/events/2020.06.Online/TDs/Hitachi/schematic.svg @@ -0,0 +1 @@ +ACBDEFGHIJ123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657to GPIO17to GNDto 3.3Vto GPIO251KLED \ No newline at end of file diff --git a/events/2020.06.Online/TDs/Hitachi/simpleled.gif b/events/2020.06.Online/TDs/Hitachi/simpleled.gif new file mode 100644 index 00000000..22234309 Binary files /dev/null and b/events/2020.06.Online/TDs/Hitachi/simpleled.gif differ diff --git a/events/2020.06.Online/TDs/active.csv b/events/2020.06.Online/TDs/active.csv index 4fc42790..9f9fef3f 100644 --- a/events/2020.06.Online/TDs/active.csv +++ b/events/2020.06.Online/TDs/active.csv @@ -1,2 +1,3 @@ "Org", "Name", "Active" "Intel", "camera", "yes" +"Hitachi","led", "yes" \ No newline at end of file diff --git a/events/2020.06.Online/data/impl/Hitachi/impl.csv b/events/2020.06.Online/data/impl/Hitachi/impl.csv index c4845010..35daa0b2 100644 --- a/events/2020.06.Online/data/impl/Hitachi/impl.csv +++ b/events/2020.06.Online/data/impl/Hitachi/impl.csv @@ -1,3 +1,4 @@ "Implementation", "Name", "Roles" "nodegen", "Node generator for Node-RED", "consumer" +"led", "Simple LED Lamp", "producer" diff --git a/systems/README.md b/systems/README.md index fd123702..b289c776 100644 --- a/systems/README.md +++ b/systems/README.md @@ -5,8 +5,9 @@ Online systems and examples available for testing. ### Frameworks * [node-wot]() -* [nodegen]() -* [NodeRED WoT Module](https://www.npmjs.com/package/node-red-contrib-web-of-things) +* [Node-RED Node Generator](https://github.com/node-red/node-red-nodegen) + * Given a TD, generates a custom Node-RED node. +* [Node-RED WoT Module](https://www.npmjs.com/package/node-red-contrib-web-of-things) ### Online Systems