[ { "id": "39762897d44d522d", "type": "tab", "label": "初期設定", "disabled": false, "info": "", "env": [] }, { "id": "b1538c3ab3866983", "type": "tab", "label": "証明書の登録", "disabled": false, "info": "", "env": [] }, { "id": "64a255ac39e07aba", "type": "tab", "label": "MQTT通信", "disabled": false, "info": "", "env": [] }, { "id": "85d90fcb63c14e3b", "type": "group", "z": "39762897d44d522d", "style": { "stroke": "#999999", "stroke-opacity": "1", "fill": "none", "fill-opacity": "1", "label": true, "label-position": "nw", "color": "#a4a4a4" }, "nodes": [ "26bd97b9d01fdabf", "01aa9aa58cc8f03e", "556186ca2af2bb49", "44e8248a7b02dc36" ], "x": 194, "y": 59, "w": 712, "h": 142 }, { "id": "a23c018868c7a4ef", "type": "group", "z": "39762897d44d522d", "style": { "stroke": "#999999", "stroke-opacity": "1", "fill": "none", "fill-opacity": "1", "label": true, "label-position": "nw", "color": "#a4a4a4" }, "nodes": [ "0520ecd2ea2b30ae", "ad2f0a52fbf07f02", "47983960e45a6fb2", "d8fd9bd391a310d2", "6606f55dd4422350", "670ba7d17c8e8e94" ], "x": 514, "y": 259, "w": 952, "h": 182 }, { "id": "b8cbb4abc2f82ea5", "type": "group", "z": "39762897d44d522d", "style": { "stroke": "#999999", "stroke-opacity": "1", "fill": "none", "fill-opacity": "1", "label": true, "label-position": "nw", "color": "#a4a4a4" }, "nodes": [ "118a283fc244ca5d", "ed58d50564a867fd", "367bacdaf920538b", "a679607a2eaeb9c4", "15885712fdf918fe", "9f641d746dd80a37" ], "x": 114, "y": 519, "w": 1132, "h": 142 }, { "id": "63c7c3f192e476f9", "type": "group", "z": "39762897d44d522d", "style": { "stroke": "#999999", "stroke-opacity": "1", "fill": "none", "fill-opacity": "1", "label": true, "label-position": "nw", "color": "#a4a4a4" }, "nodes": [ "80affed8266d005f", "b7ba4753a7dd5462" ], "x": 194, "y": 259, "w": 292, "h": 142 }, { "id": "663678a0d751bd7e", "type": "global-config", "name": "global-config", "env": [ { "name": "AWS_ACCESS_KEY_ID", "value": "*****", "type": "str" }, { "name": "AWS_SECRET_ACCESS_KEY", "value": "*****", "type": "str" }, { "name": "THING_NAME", "value": "DJIOTM01", "type": "str" }, { "name": "POLICY_NAME", "value": "DJIOTM01-policy", "type": "str" }, { "name": "AWS_SESSION_TOKEN", "value": "", "type": "str" } ] }, { "id": "f5cf78070dcb215c", "type": "ui_base", "theme": { "name": "theme-light", "lightTheme": { "default": "#0094CE", "baseColor": "#0094CE", "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif", "edited": true, "reset": false }, "darkTheme": { "default": "#097479", "baseColor": "#097479", "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif", "edited": false }, "customTheme": { "name": "Untitled Theme 1", "default": "#4B7930", "baseColor": "#4B7930", "baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif" }, "themeState": { "base-color": { "default": "#0094CE", "value": "#0094CE", "edited": false }, "page-titlebar-backgroundColor": { "value": "#0094CE", "edited": false }, "page-backgroundColor": { "value": "#fafafa", "edited": false }, "page-sidebar-backgroundColor": { "value": "#ffffff", "edited": false }, "group-textColor": { "value": "#1bbfff", "edited": false }, "group-borderColor": { "value": "#ffffff", "edited": false }, "group-backgroundColor": { "value": "#ffffff", "edited": false }, "widget-textColor": { "value": "#111111", "edited": false }, "widget-backgroundColor": { "value": "#0094ce", "edited": false }, "widget-borderColor": { "value": "#ffffff", "edited": false }, "base-font": { "value": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif" } }, "angularTheme": { "primary": "indigo", "accents": "blue", "warn": "red", "background": "grey", "palette": "light" } }, "site": { "name": "Node-RED Dashboard", "hideToolbar": "false", "allowSwipe": "false", "lockMenu": "false", "allowTempTheme": "true", "dateFormat": "DD/MM/YYYY", "sizes": { "sx": 48, "sy": 48, "gx": 6, "gy": 6, "cx": 6, "cy": 6, "px": 0, "py": 0 } } }, { "id": "c6c46a395a782fc4", "type": "tls-config", "name": "test mqtt", "cert": "", "key": "", "ca": "", "certname": "9fd72c9175c8caa70448135e7b52a78717dfc55ab309af2cbe3aeb82d4798516-certificate.pem.crt", "keyname": "9fd72c9175c8caa70448135e7b52a78717dfc55ab309af2cbe3aeb82d4798516-private.pem.key", "caname": "AmazonRootCA1.pem", "servername": "", "verifyservercert": false, "alpnprotocol": "" }, { "id": "e894cd50b6f2fa81", "type": "mqtt-broker", "name": "test", "broker": "a3djrqhqnehhjh-ats.iot.ap-northeast-1.amazonaws.com", "port": "8883", "tls": "c6c46a395a782fc4", "clientid": "", "autoConnect": true, "usetls": true, "protocolVersion": "4", "keepalive": "60", "cleansession": true, "autoUnsubscribe": true, "birthTopic": "", "birthQos": "0", "birthRetain": "false", "birthPayload": "", "birthMsg": {}, "closeTopic": "", "closeQos": "0", "closeRetain": "false", "closePayload": "", "closeMsg": {}, "willTopic": "", "willQos": "0", "willRetain": "false", "willPayload": "", "willMsg": {}, "userProps": "", "sessionExpiry": "" }, { "id": "04e6f0e8f889f6c5", "type": "mqtt-broker", "name": "test2", "broker": "test2", "port": "8883", "tls": "5f20b7f42fa178bd", "clientid": "", "autoConnect": true, "usetls": true, "protocolVersion": "3", "keepalive": "60", "cleansession": true, "autoUnsubscribe": true, "birthTopic": "", "birthQos": "0", "birthRetain": "false", "birthPayload": "", "birthMsg": {}, "closeTopic": "", "closeQos": "0", "closeRetain": "false", "closePayload": "", "closeMsg": {}, "willTopic": "", "willQos": "0", "willRetain": "false", "willPayload": "", "willMsg": {}, "userProps": "", "sessionExpiry": "" }, { "id": "5f20b7f42fa178bd", "type": "tls-config", "name": "test2", "cert": "/root/pem_files/device_cert.pem", "key": "/root/pem_files/refkey.pem", "ca": "/root/pem_files/AmazonRootCA1.pem", "certname": "", "keyname": "", "caname": "", "servername": "", "verifyservercert": true, "alpnprotocol": "" }, { "id": "0520ecd2ea2b30ae", "type": "exec", "z": "39762897d44d522d", "g": "a23c018868c7a4ef", "command": "echo $SERIALNUM | tr -d '\\n'", "addpay": "", "append": "", "useSpawn": "false", "timer": "", "winHide": false, "oldrc": false, "name": "Armadilloのシリアル番号を取得", "x": 670, "y": 360, "wires": [ [ "d8fd9bd391a310d2" ], [], [] ] }, { "id": "370e9a567df9afa9", "type": "inject", "z": "39762897d44d522d", "name": "", "props": [], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "x": 90, "y": 160, "wires": [ [ "26bd97b9d01fdabf" ] ] }, { "id": "ad2f0a52fbf07f02", "type": "function", "z": "39762897d44d522d", "g": "a23c018868c7a4ef", "name": "モノの名前を設定", "func": "msg.payload = env.get(\"THING_NAME\")+\"-\"+msg.payload;\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1150, "y": 360, "wires": [ [ "47983960e45a6fb2" ] ] }, { "id": "47983960e45a6fb2", "type": "change", "z": "39762897d44d522d", "g": "a23c018868c7a4ef", "name": "モノの名前を保存", "rules": [ { "t": "set", "p": "thing_name", "pt": "global", "to": "payload", "tot": "msg", "dc": true } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1350, "y": 360, "wires": [ [ "ed58d50564a867fd" ] ] }, { "id": "d8fd9bd391a310d2", "type": "switch", "z": "39762897d44d522d", "g": "a23c018868c7a4ef", "name": "シリアル番号を確認", "property": "payload", "propertyType": "msg", "rules": [ { "t": "regex", "v": "^[a-zA-Z0-9]+$", "vt": "str", "case": false } ], "checkall": "true", "repair": false, "outputs": 1, "x": 940, "y": 360, "wires": [ [ "ad2f0a52fbf07f02", "670ba7d17c8e8e94" ] ] }, { "id": "6606f55dd4422350", "type": "comment", "z": "39762897d44d522d", "g": "a23c018868c7a4ef", "name": "AWSに登録するモノの名前にシリアル番号を追加して、グローバル変数として保存する", "info": "", "x": 840, "y": 300, "wires": [] }, { "id": "118a283fc244ca5d", "type": "comment", "z": "39762897d44d522d", "g": "b8cbb4abc2f82ea5", "name": "AWS IoTエンドポイントを取得し保存する", "info": "", "x": 300, "y": 560, "wires": [] }, { "id": "786cc27a400d8638", "type": "link out", "z": "39762897d44d522d", "name": "TAIL 1", "mode": "link", "links": [ "fc54921de7e29417", "83ab5965328be993" ], "x": 1305, "y": 620, "wires": [] }, { "id": "ed58d50564a867fd", "type": "function", "z": "39762897d44d522d", "g": "b8cbb4abc2f82ea5", "name": "AWS のアクセスを設定", "func": "msg.payload = env.get(\"AWS_ACCESS_KEY_ID\")\n + \":\" + env.get(\"AWS_SECRET_ACCESS_KEY\");\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 250, "y": 620, "wires": [ [ "367bacdaf920538b" ] ] }, { "id": "367bacdaf920538b", "type": "exec queue", "z": "39762897d44d522d", "g": "b8cbb4abc2f82ea5", "name": "AWS IoT エンドポイントを取得", "currentLine": { "row": 10, "column": 4 }, "command": "bash $file", "debugMode": true, "outputs": 1, "useSpawn": "false", "field": "payload", "fieldType": "msg", "format": "sh", "template": "set -x\n\nAWS_ACCESS=\"$1\"\nAWS_REGION=ap-northeast-1\nENDPOINT=iot.ap-northeast-1.amazonaws.com\nURI=/endpoint?endpointType=iot%3AData-ATS\n\ncurl \\\n --http1.1 \\\n --cacert /root/pem_files/AmazonRootCA1.pem \\\n --user \"${AWS_ACCESS}\" \\\n --aws-sigv4 \"aws:amz:${AWS_REGION}:execute-api\" \\\n --request GET -v \\\n \"https://${ENDPOINT}${URI}\"\n", "output": "str", "outputEmpty": false, "vimMode": false, "queue": 1, "addpayCB": true, "splitLine": false, "cleanQueue": true, "x": 530, "y": 620, "wires": [ [ "a679607a2eaeb9c4" ] ] }, { "id": "a679607a2eaeb9c4", "type": "function", "z": "39762897d44d522d", "g": "b8cbb4abc2f82ea5", "name": "json を抽出", "func": "var shadow = msg.payload.match(/\\{.*\\}/);\nmsg.payload = shadow[0];\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 750, "y": 620, "wires": [ [ "15885712fdf918fe" ] ] }, { "id": "15885712fdf918fe", "type": "json", "z": "39762897d44d522d", "g": "b8cbb4abc2f82ea5", "name": "", "property": "payload", "action": "obj", "pretty": false, "x": 890, "y": 620, "wires": [ [ "9f641d746dd80a37" ] ] }, { "id": "9f641d746dd80a37", "type": "change", "z": "39762897d44d522d", "g": "b8cbb4abc2f82ea5", "name": "AWS IoT エンドポイントを保存", "rules": [ { "t": "set", "p": "iot_endpoint", "pt": "global", "to": "payload.endpointAddress", "tot": "msg", "dc": true } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1090, "y": 620, "wires": [ [ "786cc27a400d8638" ] ] }, { "id": "26bd97b9d01fdabf", "type": "file in", "z": "39762897d44d522d", "g": "85d90fcb63c14e3b", "name": "初期設定の確認", "filename": "/root/node-red-setup.txtあ", "filenameType": "str", "format": "utf8", "chunk": false, "sendError": false, "encoding": "none", "allProps": false, "x": 300, "y": 160, "wires": [ [ "01aa9aa58cc8f03e" ] ] }, { "id": "01aa9aa58cc8f03e", "type": "json", "z": "39762897d44d522d", "g": "85d90fcb63c14e3b", "name": "", "property": "payload", "action": "obj", "pretty": false, "x": 450, "y": 160, "wires": [ [ "556186ca2af2bb49" ] ] }, { "id": "556186ca2af2bb49", "type": "change", "z": "39762897d44d522d", "g": "85d90fcb63c14e3b", "name": "モノの名前とエンドポイントを保存", "rules": [ { "t": "set", "p": "thing_name", "pt": "global", "to": "payload.thing_name", "tot": "msg", "dc": true }, { "t": "set", "p": "iot_endpoint", "pt": "global", "to": "payload.iot_endpoint", "tot": "msg", "dc": true } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 670, "y": 160, "wires": [ [] ] }, { "id": "44e8248a7b02dc36", "type": "comment", "z": "39762897d44d522d", "g": "85d90fcb63c14e3b", "name": "初期設定を行ってたかを確認する。セットアップ済みの場合、デバイス証明書の登録をスキップ", "info": "", "x": 550, "y": 100, "wires": [] }, { "id": "670ba7d17c8e8e94", "type": "change", "z": "39762897d44d522d", "g": "a23c018868c7a4ef", "name": "シリアル番号を保存", "rules": [ { "t": "set", "p": "serial_number", "pt": "global", "to": "payload", "tot": "msg", "dc": true } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1160, "y": 400, "wires": [ [] ] }, { "id": "80affed8266d005f", "type": "exec queue", "z": "39762897d44d522d", "g": "63c7c3f192e476f9", "name": "デバイス証明書を取得", "currentLine": { "row": 10, "column": 0 }, "command": "bash $file", "debugMode": true, "outputs": 1, "useSpawn": "false", "field": "payload", "fieldType": "msg", "format": "sh", "template": "set -x\n\nmkdir -p /root/pem_files\n\n# EdgeLock SE050 から証明書とリファレンスキーを取得する\nse05x_getkey 0xF0000111 /root/pem_files/device_cert.pem /dev/i2c-1:0x48\nse05x_getkey 0xF0000110 /root/pem_files/refkey.pem /dev/i2c-1:0x48\n\n# AWS の Root CA 証明書を準備する\ncurl https://www.amazontrust.com/repository/AmazonRootCA1.pem > /root/pem_files/AmazonRootCA1.pem\n", "output": "str", "outputEmpty": false, "vimMode": false, "queue": 1, "addpayCB": false, "splitLine": false, "cleanQueue": true, "x": 320, "y": 360, "wires": [ [ "0520ecd2ea2b30ae" ] ] }, { "id": "b7ba4753a7dd5462", "type": "comment", "z": "39762897d44d522d", "g": "63c7c3f192e476f9", "name": "AWS Root CA 証明書の準備", "info": "", "x": 340, "y": 300, "wires": [] }, { "id": "c6fdece31b96b032", "type": "catch", "z": "39762897d44d522d", "name": "", "scope": [ "26bd97b9d01fdabf" ], "uncaught": false, "x": 90, "y": 360, "wires": [ [ "80affed8266d005f" ] ] }, { "id": "45cb316a1fa35508", "type": "exec queue", "z": "b1538c3ab3866983", "name": "新しいポリシーを作成", "currentLine": { "row": 11, "column": 9 }, "command": "bash $file", "debugMode": true, "outputs": 1, "useSpawn": "false", "field": "payload", "fieldType": "msg", "format": "sh", "template": "set -x\n\nAWS_ACCESS=\"$1\"\nAWS_REGION=ap-northeast-1\nENDPOINT=iot.ap-northeast-1.amazonaws.com\nPOLICY_NAME=node-red-demo-policy\nURI=/policies/${POLICY_NAME}\n\ncurl \\\n -H \"Content-type: application/json\" \\\n --cacert /root/pem_files/AmazonRootCA1.pem \\\n --user \"${AWS_ACCESS}\" \\\n --aws-sigv4 \"aws:amz:${AWS_REGION}:execute-api\" \\\n -d '{\"policyDocument\": \"{\\\"Version\\\": \\\"2012-10-17\\\",\\\"Statement\\\": [{\\\"Effect\\\": \\\"Allow\\\",\\\"Action\\\": \\\"iot:*\\\",\\\"Resource\\\": \\\"*\\\"}]}\"}' \\\n --request POST -v \\\n \"https://${ENDPOINT}${URI}\"\n", "output": "str", "outputEmpty": false, "vimMode": false, "queue": 1, "addpayCB": true, "splitLine": false, "cleanQueue": true, "x": 940, "y": 380, "wires": [ [ "6938f33988cdbbfb" ] ] }, { "id": "edb586a4f2286f22", "type": "exec queue", "z": "b1538c3ab3866983", "name": "デバイス証明書を登録", "currentLine": { "row": 16, "column": 0 }, "command": "bash $file", "debugMode": true, "outputs": 1, "useSpawn": "false", "field": "payload", "fieldType": "msg", "format": "sh", "template": "set -x\n\nAWS_ACCESS=\"$1\"\nAWS_REGION=ap-northeast-1\nENDPOINT=iot.ap-northeast-1.amazonaws.com\nURI=/certificate/register-no-ca\nCERT=$(cat /root/pem_files/device_cert.pem | sed -z 's/\\n/\\\\n/g')\n\ncurl \\\n -H \"Content-type: application/json\" \\\n --cacert /root/pem_files/AmazonRootCA1.pem \\\n --user \"${AWS_ACCESS}\" \\\n --aws-sigv4 \"aws:amz:${AWS_REGION}:execute-api\" \\\n -d \"{\\\"certificatePem\\\":\\\"${CERT}\\\",\\\"status\\\":\\\"ACTIVE\\\"}\" \\\n --request POST -v \\\n \"https://${ENDPOINT}${URI}\"\n", "output": "str", "outputEmpty": false, "vimMode": false, "queue": 1, "addpayCB": true, "splitLine": false, "cleanQueue": true, "x": 500, "y": 460, "wires": [ [ "3df87e22740e4b97" ] ] }, { "id": "3df87e22740e4b97", "type": "function", "z": "b1538c3ab3866983", "name": "json を抽出", "func": "var shadow = msg.payload.match(/\\{.*\\}/);\nmsg.payload = shadow[0];\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 690, "y": 460, "wires": [ [ "9afcd8fca247b20c" ] ] }, { "id": "9afcd8fca247b20c", "type": "json", "z": "b1538c3ab3866983", "name": "", "property": "payload", "action": "obj", "pretty": false, "x": 850, "y": 460, "wires": [ [ "e02cc2bd1e8c7a80", "c139b20365579809", "fee4765e17d78259" ] ] }, { "id": "801775eeca198678", "type": "change", "z": "b1538c3ab3866983", "name": "証明書の ARN を保存", "rules": [ { "t": "set", "p": "certArn", "pt": "flow", "to": "payload.certificateArn", "tot": "msg", "dc": true } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1260, "y": 480, "wires": [ [ "99ef43eb52ee5b4d" ] ] }, { "id": "32453bafd1c0c15e", "type": "exec queue", "z": "b1538c3ab3866983", "name": "ポリシーをアタッチ", "currentLine": { "row": 13, "column": 10 }, "command": "bash $file", "debugMode": true, "outputs": 1, "useSpawn": "false", "field": "payload", "fieldType": "msg", "format": "sh", "template": "set -x\n\nAWS_ACCESS=\"$1\"\nCERT_ARN=\"$3\"\nAWS_REGION=ap-northeast-1\nENDPOINT=iot.ap-northeast-1.amazonaws.com\nPOLICY_NAME=node-red-demo-policy\nURI=/target-policies/${POLICY_NAME}\n\ncurl \\\n -H \"Content-type: application/json\" \\\n --cacert /root/pem_files/AmazonRootCA1.pem \\\n --user \"${AWS_ACCESS}\" \\\n --aws-sigv4 \"aws:amz:${AWS_REGION}:execute-api\" \\\n -d \"{\\\"target\\\":\\\"${CERT_ARN}\\\"}\" \\\n --request PUT -v \\\n \"https://${ENDPOINT}${URI}\"\n", "output": "str", "outputEmpty": false, "vimMode": false, "queue": 1, "addpayCB": true, "splitLine": false, "cleanQueue": true, "x": 640, "y": 740, "wires": [ [ "cb8cc46c7e3ae025" ] ] }, { "id": "e63609104082164a", "type": "exec queue", "z": "b1538c3ab3866983", "name": "モノのプリンシパルをアタッチ", "currentLine": { "row": 11, "column": 8 }, "command": "bash $file", "debugMode": true, "outputs": 1, "useSpawn": "false", "field": "payload", "fieldType": "msg", "format": "sh", "template": "set -x\n\nAWS_ACCESS=\"$1\"\nTHING_NAME=\"$2\"\nCERT_ARN=\"$3\"\nAWS_REGION=ap-northeast-1\nENDPOINT=iot.ap-northeast-1.amazonaws.com\nURI=/things/${THING_NAME}/principals\n\ncurl \\\n -H \"x-amzn-principal:${CERT_ARN}\" \\\n --cacert /root/pem_files/AmazonRootCA1.pem \\\n --user \"${AWS_ACCESS}\" \\\n --aws-sigv4 \"aws:amz:${AWS_REGION}:execute-api\" \\\n --request PUT -v \\\n \"https://${ENDPOINT}${URI}\"\n", "output": "str", "outputEmpty": false, "vimMode": false, "queue": 1, "addpayCB": true, "splitLine": false, "cleanQueue": true, "x": 670, "y": 820, "wires": [ [ "193fa1f19111e3a7" ] ] }, { "id": "cf0af15ea785100a", "type": "link in", "z": "b1538c3ab3866983", "name": "flow 3 in", "links": [ "99ef43eb52ee5b4d" ], "x": 145, "y": 600, "wires": [ [ "04a831ac38803168" ] ] }, { "id": "99ef43eb52ee5b4d", "type": "link out", "z": "b1538c3ab3866983", "name": "flow 2 out", "mode": "link", "links": [ "cf0af15ea785100a" ], "x": 1405, "y": 460, "wires": [] }, { "id": "e02cc2bd1e8c7a80", "type": "switch", "z": "b1538c3ab3866983", "name": "resourceArn を検知", "property": "payload.resourceArn", "propertyType": "msg", "rules": [ { "t": "nempty" } ], "checkall": "false", "repair": true, "outputs": 1, "x": 1030, "y": 440, "wires": [ [ "d6d8f641f57cddb8" ] ] }, { "id": "d6d8f641f57cddb8", "type": "change", "z": "b1538c3ab3866983", "name": "証明書の ARN を保存", "rules": [ { "t": "set", "p": "certArn", "pt": "flow", "to": "payload.resourceArn", "tot": "msg", "dc": true } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1260, "y": 440, "wires": [ [ "99ef43eb52ee5b4d" ] ] }, { "id": "c139b20365579809", "type": "switch", "z": "b1538c3ab3866983", "name": "certificateArn を検知", "property": "payload.certificateArn", "propertyType": "msg", "rules": [ { "t": "nempty" } ], "checkall": "false", "repair": true, "outputs": 1, "x": 1040, "y": 480, "wires": [ [ "801775eeca198678" ] ] }, { "id": "533522f03a8d325d", "type": "change", "z": "b1538c3ab3866983", "name": "アクセスキーを保存", "rules": [ { "t": "set", "p": "aws_access", "pt": "flow", "to": "payload", "tot": "msg", "dc": true } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 540, "y": 260, "wires": [ [ "03b0c00359ace85e" ] ] }, { "id": "9d467a55887c6632", "type": "change", "z": "b1538c3ab3866983", "name": "アクセスキーを出す", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "aws_access", "tot": "flow" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 720, "y": 380, "wires": [ [ "45cb316a1fa35508" ] ] }, { "id": "6938f33988cdbbfb", "type": "change", "z": "b1538c3ab3866983", "name": "アクセスキーを出す", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "aws_access", "tot": "flow" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 280, "y": 460, "wires": [ [ "edb586a4f2286f22" ] ] }, { "id": "03b0c00359ace85e", "type": "link out", "z": "b1538c3ab3866983", "name": "flow 1 out", "mode": "link", "links": [ "5cf19f28a23f7975" ], "x": 695, "y": 260, "wires": [] }, { "id": "5cf19f28a23f7975", "type": "link in", "z": "b1538c3ab3866983", "name": "flow 2 in", "links": [ "03b0c00359ace85e" ], "x": 145, "y": 380, "wires": [ [ "6d82988d138e5f0e" ] ] }, { "id": "04a831ac38803168", "type": "change", "z": "b1538c3ab3866983", "name": "アクセスキーを出す", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "aws_access", "tot": "flow" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 300, "y": 600, "wires": [ [ "3cd5efff223495a8" ] ] }, { "id": "7931f85565d48782", "type": "change", "z": "b1538c3ab3866983", "name": "アクセスキーと証明書の ARN を出す", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "cert_and_access", "tot": "flow" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 350, "y": 740, "wires": [ [ "32453bafd1c0c15e" ] ] }, { "id": "aad1da404a1daa9d", "type": "link out", "z": "b1538c3ab3866983", "name": "flow 3 out", "mode": "link", "links": [ "6c7ef1776284d2f5" ], "x": 1135, "y": 600, "wires": [] }, { "id": "6c7ef1776284d2f5", "type": "link in", "z": "b1538c3ab3866983", "name": "flow 4 in", "links": [ "aad1da404a1daa9d" ], "x": 145, "y": 740, "wires": [ [ "7931f85565d48782" ] ] }, { "id": "cb8cc46c7e3ae025", "type": "change", "z": "b1538c3ab3866983", "name": "アクセスキーと証明書の ARN を出す", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "cert_and_access", "tot": "flow" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 350, "y": 820, "wires": [ [ "e63609104082164a" ] ] }, { "id": "d48a77377864c7ff", "type": "function", "z": "b1538c3ab3866983", "name": "アクセスキーを設定", "func": "msg.payload = env.get(\"AWS_ACCESS_KEY_ID\") \n + \":\" + env.get(\"AWS_SECRET_ACCESS_KEY\") \n + \" \" + global.get(\"thing_name\");\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 300, "y": 260, "wires": [ [ "533522f03a8d325d", "0e5605c80fc08ad0" ] ] }, { "id": "3cd5efff223495a8", "type": "function", "z": "b1538c3ab3866983", "name": "アクセスキーと証明書の ARN を設定", "func": "msg.payload = msg.payload + \" \" + flow.get(\"certArn\");\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 590, "y": 600, "wires": [ [ "7f31ca3375e1e223" ] ] }, { "id": "7f31ca3375e1e223", "type": "change", "z": "b1538c3ab3866983", "name": "アクセスキーと証明書の ARN を保存", "rules": [ { "t": "set", "p": "cert_and_access", "pt": "flow", "to": "payload", "tot": "msg", "dc": true } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 930, "y": 600, "wires": [ [ "aad1da404a1daa9d" ] ] }, { "id": "83ab5965328be993", "type": "link in", "z": "b1538c3ab3866983", "name": "HEAD", "links": [ "786cc27a400d8638" ], "x": 145, "y": 260, "wires": [ [ "d48a77377864c7ff" ] ] }, { "id": "6d82988d138e5f0e", "type": "change", "z": "b1538c3ab3866983", "name": "アクセスキーを出す", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "aws_access", "tot": "flow" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 300, "y": 380, "wires": [ [ "d384ecd04bd90b87" ] ] }, { "id": "d384ecd04bd90b87", "type": "exec queue", "z": "b1538c3ab3866983", "name": "新しいモノを作成", "currentLine": { "row": 8, "column": 0 }, "command": "bash $file", "debugMode": true, "outputs": 1, "useSpawn": "false", "field": "payload", "fieldType": "msg", "format": "sh", "template": "set -x\n\nAWS_ACCESS=\"$1\"\nTHING_NAME=\"$2\"\nAWS_REGION=ap-northeast-1\nENDPOINT=iot.ap-northeast-1.amazonaws.com\nURI=/things/${THING_NAME}\n\ncurl \\\n --cacert /root/pem_files/AmazonRootCA1.pem \\\n --user \"${AWS_ACCESS}\" \\\n --aws-sigv4 \"aws:amz:${AWS_REGION}:execute-api\" \\\n --request POST -v \\\n -d \"{}\" \\\n \"https://${ENDPOINT}${URI}\"", "output": "str", "outputEmpty": false, "vimMode": false, "queue": 1, "addpayCB": true, "splitLine": false, "cleanQueue": true, "x": 510, "y": 380, "wires": [ [ "9d467a55887c6632" ] ] }, { "id": "bc040969e0dbf850", "type": "comment", "z": "b1538c3ab3866983", "name": "このフローは IAM のアクセスIDとアクセスキーをそのまま使う場合に実行する", "info": "", "x": 420, "y": 60, "wires": [] }, { "id": "f9f48065bcd27047", "type": "comment", "z": "b1538c3ab3866983", "name": "セキュリティ向上のために、一時的な認証を利用するのをお勧めする。", "info": "", "x": 390, "y": 180, "wires": [] }, { "id": "b24bb5011876ca01", "type": "comment", "z": "b1538c3ab3866983", "name": "アクセスIDとアクセスキーは Armadillo に残しているので、設定終わった後にIDとキーの権限を消すのを忘れないように", "info": "", "x": 550, "y": 100, "wires": [] }, { "id": "94bad60f66f82924", "type": "comment", "z": "b1538c3ab3866983", "name": "(AWS の IAM ダッシュボードで IDとキーの権限を管理できて、キーを消したり新しいキーを発行したりすることができる)", "info": "", "x": 560, "y": 140, "wires": [] }, { "id": "a5c4dd02877af220", "type": "file", "z": "b1538c3ab3866983", "name": "セットアップファイルに保存", "filename": "/root/node-red-setup.txt", "filenameType": "str", "appendNewline": false, "createDir": true, "overwriteFile": "true", "encoding": "none", "x": 960, "y": 920, "wires": [ [] ] }, { "id": "193fa1f19111e3a7", "type": "change", "z": "b1538c3ab3866983", "name": "モノの名前とエンドポイントを設定", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "{}", "tot": "json" }, { "t": "set", "p": "payload.thing_name", "pt": "msg", "to": "thing_name", "tot": "global" }, { "t": "set", "p": "payload.iot_endpoint", "pt": "msg", "to": "iot_endpoint", "tot": "global" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 670, "y": 920, "wires": [ [ "a5c4dd02877af220" ] ] }, { "id": "75a249822380d4a0", "type": "comment", "z": "b1538c3ab3866983", "name": "↑ 初期設定が問題なく終わったら、ファイルに保存する", "info": "", "x": 880, "y": 980, "wires": [] }, { "id": "0e5605c80fc08ad0", "type": "debug", "z": "b1538c3ab3866983", "name": "debug 4", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 460, "y": 300, "wires": [] }, { "id": "fee4765e17d78259", "type": "debug", "z": "b1538c3ab3866983", "name": "debug 6", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1020, "y": 540, "wires": [] }, { "id": "1cd74fc54e285893", "type": "mqtt out", "z": "64a255ac39e07aba", "name": "", "topic": "myTopic/mqtt", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "e894cd50b6f2fa81", "x": 690, "y": 200, "wires": [] }, { "id": "189c373fa1ddd18b", "type": "function", "z": "64a255ac39e07aba", "name": "引用符と変数を設定", "func": "msg.payload = {\"color\":\"red\",\"temperature\":100}\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 380, "y": 200, "wires": [ [ "1cd74fc54e285893", "9b7714fa4b29c514" ] ] }, { "id": "1d6ffa6fcf972fab", "type": "inject", "z": "64a255ac39e07aba", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 140, "y": 200, "wires": [ [ "189c373fa1ddd18b" ] ] }, { "id": "9b7714fa4b29c514", "type": "mqtt out", "z": "64a255ac39e07aba", "name": "", "topic": "myTopic/mqtt", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "04e6f0e8f889f6c5", "x": 694.9332885742188, "y": 258.9333190917969, "wires": [] } ]