Commit 3a3ebcd3 authored by Spencer Williams's avatar Spencer Williams
Browse files

split ratelimiting between AWS and Dash

parent cfa20eaa
......@@ -197,7 +197,8 @@
"y": 800,
"wires": [
[
"aadbf527.6c3dd8"
"aadbf527.6c3dd8",
"649e5655.cf7178"
],
[
"a031a60c.d4e5c8"
......@@ -342,7 +343,7 @@
"order": 2,
"width": 0,
"height": 0,
"format": "<h2>Device List</h2>\n<table width=\"100%\" style=\"margin: 0px;\">\n <thead>\n <tr>\n <th>Device UUID</th>\n <th>Last Seen</th>\n </tr>\n </thead>\n <tbody>\n <tr ng-repeat=\"(key, value) in msg.payload\">\n <td>{{key}}</td>\n <td>{{value}}</td>\n </tr>\n </tbody>\n</table>\n",
"format": "<h2>Device List</h2>\n<table width=\"100%\" style=\"margin: 0px;\">\n <thead>\n <tr>\n <th>Device UUID</th>\n <th>Last Sent to AWS</th>\n <th>Last Sent to Dashboard</th>\n </tr>\n </thead>\n <tbody>\n <tr ng-repeat=\"(key, value) in msg.payload\">\n <td>{{key}}</td>\n <td>{{value.sentToAWS}}</td>\n <td>{{value.sentToDash}}</td>\n </tr>\n </tbody>\n</table>\n",
"storeOutMessages": false,
"fwdInMessages": false,
"templateScope": "local",
......@@ -548,7 +549,7 @@
"type": "comment",
"z": "155b7069.fcdeb",
"name": "1. Concatenate sensor data and gateway information",
"info": "When sensor data comes in, it does not include gateway information. The delay\nnode acts as a trigger for an exec node running the command\n`unit_serial_number`.\n\nNote: This command is a binary that exists on Rigado Gateways, and may not exist\non other systems.\n\nThe unit serial number is saved to the flow context.",
"info": "When sensor data comes in, it does not include Gateway information. This part of\nthe flow stores the Gateway serial number in the flow context.\n\nNote: This command is a binary that exists on Rigado Gateways, and may not exist\non other systems.",
"x": 1100,
"y": 180,
"wires": []
......@@ -628,18 +629,6 @@
]
]
},
{
"id": "40db5f48.6a536",
"type": "debug",
"z": "155b7069.fcdeb",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 730,
"y": 520,
"wires": []
},
{
"id": "193b3996.8bc026",
"type": "comment",
......@@ -663,7 +652,7 @@
"storeOutMessages": true,
"fwdInMessages": true,
"templateScope": "local",
"x": 1526,
"x": 1540,
"y": 380,
"wires": [
[]
......@@ -708,19 +697,42 @@
"id": "c78ef0c0.1413c",
"type": "function",
"z": "155b7069.fcdeb",
"name": "1 msg/device/sec",
"func": "if (!flow.get(\"deviceList\")) {\n flow.set(\"deviceList\", {});\n}\n\nlet deviceList = flow.get(\"deviceList\");\nlet uuid = msg.payload.peripheralUuid;\nlet forward = null;\n\nif (deviceList.hasOwnProperty(uuid)) {\n let ms = msg.payload.time - deviceList[uuid];\n let rate = 1000; // ms per message\n if (ms > rate) {\n deviceList[uuid]=msg.payload.time;\n forward = msg;\n }\n} else {\n deviceList[uuid] = msg.payload.time;\n node.log(\"adding new uuid \"+uuid);\n forward = msg;\n}\n\nflow.set(\"deviceList\", deviceList);\nreturn forward;",
"outputs": 1,
"name": "ratelimit",
"func": "if (!flow.get(\"deviceList\")) {\n flow.set(\"deviceList\", {});\n}\n\nlet deviceList = flow.get(\"deviceList\");\nlet uuid = msg.payload.peripheralUuid;\nlet forwardAWS = null;\nlet forwardDash = null;\n\nif (deviceList.hasOwnProperty(uuid)) {\n let msAWS = msg.payload.time - deviceList[uuid].sentToAWS;\n if (msAWS > 1000) {\n deviceList[uuid].sentToAWS=msg.payload.time;\n forwardAWS = msg;\n }\n let msDash = msg.payload.time - deviceList[uuid].sentToDash;\n if (msDash > 5000) {\n deviceList[uuid].sentToDash=msg.payload.time;\n forwardDash = msg;\n }\n} else {\n deviceList[uuid] = {\n \"sentToAWS\": msg.payload.time,\n \"sentToDash\": msg.payload.time\n };\n node.log(\"adding new uuid \"+uuid);\n forwardAWS = msg;\n forwardDash = msg;\n}\n\nflow.set(\"deviceList\", deviceList);\nreturn [forwardAWS, forwardDash];",
"outputs": "2",
"noerr": 0,
"x": 550,
"x": 520,
"y": 520,
"wires": [
[
"6f5b2160.1b6f7",
"240447c9.909a48",
"40db5f48.6a536",
"240447c9.909a48"
],
[
"15459cab.c4ab73"
]
]
},
{
"id": "649e5655.cf7178",
"type": "debug",
"z": "155b7069.fcdeb",
"name": "",
"active": false,
"console": "false",
"complete": "true",
"x": 1010,
"y": 880,
"wires": []
},
{
"id": "5a5b2fc6.c6c88",
"type": "comment",
"z": "155b7069.fcdeb",
"name": "About ratelimiting",
"info": "This function node limits the rate of data to each of the other parts of the\nflow. It will send 1 message per device per second to Amazon Lambda, and 1\nmessage per device per 5 seconds to the Node-RED Dashboard.",
"x": 520,
"y": 480,
"wires": []
}
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment