From a3761538f8074bf53e3565848317ad0d0b438150 Mon Sep 17 00:00:00 2001
From: andreas <a.strasser@student.tugraz.at>
Date: Wed, 10 May 2023 08:31:10 +0200
Subject: [PATCH] added flow for mqtt to http request mapping

---
 flows/mqtt-http-mapping.json | 459 +++++++++++++++++++++++++++++++++++
 1 file changed, 459 insertions(+)
 create mode 100644 flows/mqtt-http-mapping.json

diff --git a/flows/mqtt-http-mapping.json b/flows/mqtt-http-mapping.json
new file mode 100644
index 0000000..88acac2
--- /dev/null
+++ b/flows/mqtt-http-mapping.json
@@ -0,0 +1,459 @@
+[
+    {
+        "id": "fa218eeab601b6b9",
+        "type": "tab",
+        "label": "mqtt-http mapping",
+        "disabled": false,
+        "info": "",
+        "env": []
+    },
+    {
+        "id": "0f04124050f5e56f",
+        "type": "mqtt in",
+        "z": "fa218eeab601b6b9",
+        "name": "configurator/devices/+/request",
+        "topic": "configurator/devices/+/request",
+        "qos": "0",
+        "datatype": "auto-detect",
+        "broker": "cdd2ed1d59e64cb9",
+        "nl": false,
+        "rap": true,
+        "rh": 0,
+        "inputs": 0,
+        "x": 180,
+        "y": 280,
+        "wires": [
+            [
+                "9374948461cc5f2e"
+            ]
+        ]
+    },
+    {
+        "id": "efaa7556a7f6610c",
+        "type": "switch",
+        "z": "fa218eeab601b6b9",
+        "name": "select action",
+        "property": "payload.action",
+        "propertyType": "msg",
+        "rules": [
+            {
+                "t": "eq",
+                "v": "REGISTER_CLUSTER",
+                "vt": "str"
+            },
+            {
+                "t": "eq",
+                "v": "REGISTER_DEVICE",
+                "vt": "str"
+            },
+            {
+                "t": "eq",
+                "v": "UPDATE_DEVICE_PEERS",
+                "vt": "str"
+            },
+            {
+                "t": "eq",
+                "v": "POLL_CONFIGURATIONS",
+                "vt": "str"
+            },
+            {
+                "t": "eq",
+                "v": "UPDATE_CONFIGURATION_STATUS",
+                "vt": "str"
+            },
+            {
+                "t": "else"
+            }
+        ],
+        "checkall": "true",
+        "repair": false,
+        "outputs": 6,
+        "x": 570,
+        "y": 280,
+        "wires": [
+            [
+                "6421f3d7bf5c6427"
+            ],
+            [
+                "9ca24c3d5bfb018d"
+            ],
+            [
+                "98303ccf9b2c9818"
+            ],
+            [
+                "219f9268f060097a"
+            ],
+            [
+                "4c9c97376cb3c318"
+            ],
+            [
+                "d7a6669c814bb305"
+            ]
+        ]
+    },
+    {
+        "id": "62352dd0f430475a",
+        "type": "mqtt out",
+        "z": "fa218eeab601b6b9",
+        "name": "configurator/devices/+/response",
+        "topic": "",
+        "qos": "0",
+        "retain": "false",
+        "respTopic": "",
+        "contentType": "",
+        "userProps": "",
+        "correl": "",
+        "expiry": "",
+        "broker": "cdd2ed1d59e64cb9",
+        "x": 1870,
+        "y": 280,
+        "wires": []
+    },
+    {
+        "id": "ac7c5712394954d2",
+        "type": "change",
+        "z": "fa218eeab601b6b9",
+        "name": "modify topic",
+        "rules": [
+            {
+                "t": "change",
+                "p": "topic",
+                "pt": "msg",
+                "from": "request",
+                "fromt": "str",
+                "to": "response",
+                "tot": "str"
+            }
+        ],
+        "action": "",
+        "property": "",
+        "from": "",
+        "to": "",
+        "reg": false,
+        "x": 1650,
+        "y": 280,
+        "wires": [
+            [
+                "62352dd0f430475a"
+            ]
+        ]
+    },
+    {
+        "id": "6421f3d7bf5c6427",
+        "type": "function",
+        "z": "fa218eeab601b6b9",
+        "name": "prepare request",
+        "func": "msg.url = \"localhost:1880/clusters/new\";\nmsg.method = \"POST\";\nreturn msg;",
+        "outputs": 1,
+        "noerr": 0,
+        "initialize": "",
+        "finalize": "",
+        "libs": [],
+        "x": 820,
+        "y": 60,
+        "wires": [
+            [
+                "f80d64014fd0400f"
+            ]
+        ]
+    },
+    {
+        "id": "9ca24c3d5bfb018d",
+        "type": "function",
+        "z": "fa218eeab601b6b9",
+        "name": "prepare request",
+        "func": "msg.url = \"localhost:1880/clusters/\" + msg.payload.cluster_uuid + \"/devices/new\";\nmsg.payload = msg.payload.content;\nmsg.method = \"POST\";\nreturn msg;",
+        "outputs": 1,
+        "noerr": 0,
+        "initialize": "",
+        "finalize": "",
+        "libs": [],
+        "x": 820,
+        "y": 120,
+        "wires": [
+            [
+                "265f58ca4afbbc72"
+            ]
+        ]
+    },
+    {
+        "id": "af137342458aad20",
+        "type": "function",
+        "z": "fa218eeab601b6b9",
+        "name": "prepare contentless response",
+        "func": "const response = {\n    status: msg.statusCode,\n    action: msg.api_action\n}\n\nmsg.payload = response;\nreturn msg;",
+        "outputs": 1,
+        "noerr": 0,
+        "initialize": "",
+        "finalize": "",
+        "libs": [],
+        "x": 1390,
+        "y": 320,
+        "wires": [
+            [
+                "ac7c5712394954d2"
+            ]
+        ]
+    },
+    {
+        "id": "5238ec19e65f570e",
+        "type": "function",
+        "z": "fa218eeab601b6b9",
+        "name": "prepare response",
+        "func": "const response = {\n    status: msg.statusCode,\n    action: msg.apiAction,\n    content: JSON.parse(msg.payload)\n}\n\nmsg.payload = response;\nreturn msg;",
+        "outputs": 1,
+        "noerr": 0,
+        "initialize": "",
+        "finalize": "",
+        "libs": [],
+        "x": 1350,
+        "y": 240,
+        "wires": [
+            [
+                "ac7c5712394954d2"
+            ]
+        ]
+    },
+    {
+        "id": "f80d64014fd0400f",
+        "type": "http request",
+        "z": "fa218eeab601b6b9",
+        "name": "register cluster",
+        "method": "use",
+        "ret": "txt",
+        "paytoqs": "ignore",
+        "url": "",
+        "tls": "",
+        "persist": false,
+        "proxy": "",
+        "insecureHTTPParser": false,
+        "authType": "",
+        "senderr": false,
+        "headers": [],
+        "x": 1000,
+        "y": 60,
+        "wires": [
+            [
+                "5238ec19e65f570e"
+            ]
+        ]
+    },
+    {
+        "id": "98303ccf9b2c9818",
+        "type": "function",
+        "z": "fa218eeab601b6b9",
+        "name": "prepare request",
+        "func": "const mac = msg.payload.mac.replace(/:/g, '').toLowerCase();\nmsg.url = \"localhost:1880/clusters/\" + msg.payload.cluster_uuid + \"/devices/\" + mac;\nmsg.payload = msg.payload.content;\nmsg.method = \"PATCH\";\nreturn msg;",
+        "outputs": 1,
+        "noerr": 0,
+        "initialize": "",
+        "finalize": "",
+        "libs": [],
+        "x": 820,
+        "y": 180,
+        "wires": [
+            [
+                "35c1a2c52c6a3703"
+            ]
+        ]
+    },
+    {
+        "id": "265f58ca4afbbc72",
+        "type": "http request",
+        "z": "fa218eeab601b6b9",
+        "name": "register device",
+        "method": "use",
+        "ret": "txt",
+        "paytoqs": "ignore",
+        "url": "",
+        "tls": "",
+        "persist": false,
+        "proxy": "",
+        "insecureHTTPParser": false,
+        "authType": "",
+        "senderr": false,
+        "headers": [],
+        "x": 1000,
+        "y": 120,
+        "wires": [
+            [
+                "5238ec19e65f570e"
+            ]
+        ]
+    },
+    {
+        "id": "35c1a2c52c6a3703",
+        "type": "http request",
+        "z": "fa218eeab601b6b9",
+        "name": "update device peers",
+        "method": "use",
+        "ret": "txt",
+        "paytoqs": "ignore",
+        "url": "",
+        "tls": "",
+        "persist": false,
+        "proxy": "",
+        "insecureHTTPParser": false,
+        "authType": "",
+        "senderr": false,
+        "headers": [],
+        "x": 1020,
+        "y": 180,
+        "wires": [
+            [
+                "af137342458aad20"
+            ]
+        ]
+    },
+    {
+        "id": "219f9268f060097a",
+        "type": "function",
+        "z": "fa218eeab601b6b9",
+        "name": "prepare request",
+        "func": "const mac = msg.payload.mac.replace(/:/g, '').toLowerCase();\nmsg.url = \"localhost:1880/clusters/\" + msg.payload.cluster_uuid + \"/configurations/?compact&gatekeeper_mac=\" + mac;\nmsg.method = \"GET\";\nreturn msg;",
+        "outputs": 1,
+        "noerr": 0,
+        "initialize": "",
+        "finalize": "",
+        "libs": [],
+        "x": 820,
+        "y": 240,
+        "wires": [
+            [
+                "fdd6a4f4014cb983"
+            ]
+        ]
+    },
+    {
+        "id": "fdd6a4f4014cb983",
+        "type": "http request",
+        "z": "fa218eeab601b6b9",
+        "name": "poll configurations",
+        "method": "use",
+        "ret": "txt",
+        "paytoqs": "ignore",
+        "url": "",
+        "tls": "",
+        "persist": false,
+        "proxy": "",
+        "insecureHTTPParser": false,
+        "authType": "",
+        "senderr": false,
+        "headers": [],
+        "x": 1010,
+        "y": 240,
+        "wires": [
+            [
+                "5238ec19e65f570e"
+            ]
+        ]
+    },
+    {
+        "id": "4c9c97376cb3c318",
+        "type": "function",
+        "z": "fa218eeab601b6b9",
+        "name": "prepare request",
+        "func": "msg.url = \"localhost:1880/clusters/\" + msg.payload.cluster_uuid + \"/configurations/\" + msg.payload.configuration_uuid;\nmsg.payload = msg.payload.content;\nmsg.method = \"PATCH\";\nreturn msg;",
+        "outputs": 1,
+        "noerr": 0,
+        "initialize": "",
+        "finalize": "",
+        "libs": [],
+        "x": 820,
+        "y": 300,
+        "wires": [
+            [
+                "fd0510cb66633fd7"
+            ]
+        ]
+    },
+    {
+        "id": "fd0510cb66633fd7",
+        "type": "http request",
+        "z": "fa218eeab601b6b9",
+        "name": "update configuration status",
+        "method": "use",
+        "ret": "txt",
+        "paytoqs": "ignore",
+        "url": "",
+        "tls": "",
+        "persist": false,
+        "proxy": "",
+        "insecureHTTPParser": false,
+        "authType": "",
+        "senderr": false,
+        "headers": [],
+        "x": 1040,
+        "y": 300,
+        "wires": [
+            [
+                "af137342458aad20"
+            ]
+        ]
+    },
+    {
+        "id": "d7a6669c814bb305",
+        "type": "function",
+        "z": "fa218eeab601b6b9",
+        "name": "error",
+        "func": "msg.statusCode = 400;\nreturn msg;",
+        "outputs": 1,
+        "noerr": 0,
+        "initialize": "",
+        "finalize": "",
+        "libs": [],
+        "x": 790,
+        "y": 360,
+        "wires": [
+            [
+                "af137342458aad20"
+            ]
+        ]
+    },
+    {
+        "id": "9374948461cc5f2e",
+        "type": "function",
+        "z": "fa218eeab601b6b9",
+        "name": "preserve action",
+        "func": "msg.apiAction = msg.payload.action;\nreturn msg;",
+        "outputs": 1,
+        "noerr": 0,
+        "initialize": "",
+        "finalize": "",
+        "libs": [],
+        "x": 400,
+        "y": 280,
+        "wires": [
+            [
+                "efaa7556a7f6610c"
+            ]
+        ]
+    },
+    {
+        "id": "cdd2ed1d59e64cb9",
+        "type": "mqtt-broker",
+        "name": "mqtt-broker",
+        "broker": "localhost",
+        "port": "1883",
+        "clientid": "",
+        "autoConnect": true,
+        "usetls": false,
+        "protocolVersion": "4",
+        "keepalive": "60",
+        "cleansession": true,
+        "birthTopic": "",
+        "birthQos": "0",
+        "birthPayload": "",
+        "birthMsg": {},
+        "closeTopic": "",
+        "closeQos": "0",
+        "closePayload": "",
+        "closeMsg": {},
+        "willTopic": "",
+        "willQos": "0",
+        "willPayload": "",
+        "willMsg": {},
+        "userProps": "",
+        "sessionExpiry": ""
+    }
+]
\ No newline at end of file
-- 
GitLab