Advertisement
MaxVonEvil

Interim JavaScript Traffic Node

Jul 19th, 2022
937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 3.77 KB | None | 0 0
  1. [
  2.     {
  3.         "id": "cdc39aa85d9e2b26",
  4.         "type": "function",
  5.         "z": "bf14112.91a86f",
  6.         "name": "Traffic",
  7.         "func": "// Replacement Traffic node as original was nuked in NR13\n\nconst allow = \"ALLOW\"\nconst block = \"BLOCK\"\n\n// create unique storage for each instance using the function node's own ID\nvar uid = \"traffic_\" + node.id + \"_state\"\n\n// retrieve traffic light state from storage\nvar sto = flow.get(uid)\n\n// green: pass message through\nif (sto == allow) {\n    node.status({fill:\"green\",shape:\"dot\",text:allow});\n    return msg\n}\n\n// red: do no such thing\nif (sto == block) {\n    node.status({fill:\"red\",shape:\"dot\",text:block});\n}\n\n// parse control messages\nif (msg.hasOwnProperty(\"control\")) {\n    if (msg.control.toUpperCase() == allow) {\n        node.status({fill:\"green\",shape:\"dot\",text:allow});     \n        flow.set(uid,allow);\n    }\n    if (msg.control.toUpperCase() == block) {\n        node.status({fill:\"red\",shape:\"dot\",text:block});     \n        flow.set(uid,block);\n    }\n}\n",
  8.         "outputs": 1,
  9.         "noerr": 0,
  10.         "initialize": "// Code added here will be run once\n// whenever the node is started.\n\nconst init_state = \"BLOCK\"\nvar uid = \"traffic_\" + node.id + \"_state\"\nflow.set(uid,init_state)\nnode.status({fill:\"red\",shape:\"dot\",text:init_state});\n",
  11.         "finalize": "",
  12.         "libs": [],
  13.         "x": 330,
  14.         "y": 3580,
  15.         "wires": [
  16.             [
  17.                 "e229ced0d3aaa895"
  18.             ]
  19.         ]
  20.     },
  21.     {
  22.         "id": "3ca8bd52927e845f",
  23.         "type": "inject",
  24.         "z": "bf14112.91a86f",
  25.         "name": "Payload",
  26.         "props": [
  27.             {
  28.                 "p": "payload"
  29.             }
  30.         ],
  31.         "repeat": "",
  32.         "crontab": "",
  33.         "once": false,
  34.         "onceDelay": 0.1,
  35.         "topic": "",
  36.         "payloadType": "date",
  37.         "x": 160,
  38.         "y": 3580,
  39.         "wires": [
  40.             [
  41.                 "cdc39aa85d9e2b26"
  42.             ]
  43.         ]
  44.     },
  45.     {
  46.         "id": "fc2a233ae81b0a7a",
  47.         "type": "inject",
  48.         "z": "bf14112.91a86f",
  49.         "name": "Allow",
  50.         "props": [
  51.             {
  52.                 "p": "control",
  53.                 "v": "Allow",
  54.                 "vt": "str"
  55.             }
  56.         ],
  57.         "repeat": "",
  58.         "crontab": "",
  59.         "once": false,
  60.         "onceDelay": 0.1,
  61.         "topic": "",
  62.         "x": 150,
  63.         "y": 3680,
  64.         "wires": [
  65.             [
  66.                 "cdc39aa85d9e2b26"
  67.             ]
  68.         ]
  69.     },
  70.     {
  71.         "id": "f21ba4c1fb2f9247",
  72.         "type": "inject",
  73.         "z": "bf14112.91a86f",
  74.         "name": "Block",
  75.         "props": [
  76.             {
  77.                 "p": "control",
  78.                 "v": "block",
  79.                 "vt": "str"
  80.             }
  81.         ],
  82.         "repeat": "",
  83.         "crontab": "",
  84.         "once": false,
  85.         "onceDelay": 0.1,
  86.         "topic": "",
  87.         "x": 150,
  88.         "y": 3640,
  89.         "wires": [
  90.             [
  91.                 "cdc39aa85d9e2b26"
  92.             ]
  93.         ]
  94.     },
  95.     {
  96.         "id": "e229ced0d3aaa895",
  97.         "type": "debug",
  98.         "z": "bf14112.91a86f",
  99.         "name": "OUT",
  100.         "active": true,
  101.         "tosidebar": true,
  102.         "console": false,
  103.         "tostatus": false,
  104.         "complete": "payload",
  105.         "targetType": "msg",
  106.         "statusVal": "",
  107.         "statusType": "auto",
  108.         "x": 470,
  109.         "y": 3580,
  110.         "wires": []
  111.     },
  112.     {
  113.         "id": "5a888fa72fcdbf18",
  114.         "type": "comment",
  115.         "z": "bf14112.91a86f",
  116.         "name": "Replacement for Traffic node",
  117.         "info": "",
  118.         "x": 120,
  119.         "y": 3540,
  120.         "wires": []
  121.     }
  122. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement