Skip to content

Instantly share code, notes, and snippets.

@alexrjs
Last active July 26, 2022 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexrjs/5846e5c65562c198d625741199cd9082 to your computer and use it in GitHub Desktop.
Save alexrjs/5846e5c65562c198d625741199cd9082 to your computer and use it in GitHub Desktop.
[
{
"id": "6dd9c5de00783d54",
"type": "tab",
"label": "Rest API Sample",
"disabled": false,
"info": "",
"env": []
},
{
"id": "2664bd1b39f7b74b",
"type": "inject",
"z": "6dd9c5de00783d54",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 160,
"y": 100,
"wires": [
[
"89f3c6e23c20f231",
"11896b2e927af7db"
]
]
},
{
"id": "89f3c6e23c20f231",
"type": "debug",
"z": "6dd9c5de00783d54",
"name": "debug 1",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 360,
"y": 40,
"wires": []
},
{
"id": "11896b2e927af7db",
"type": "http request",
"z": "6dd9c5de00783d54",
"name": "get status v2",
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "http://192.168.0.7:1880/v2/status",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"senderr": false,
"headers": [],
"x": 370,
"y": 100,
"wires": [
[
"1cbcbeea3ad7ef61"
]
]
},
{
"id": "998184eccf42c592",
"type": "http response",
"z": "6dd9c5de00783d54",
"name": "",
"statusCode": "",
"headers": {},
"x": 770,
"y": 160,
"wires": []
},
{
"id": "f67c9ce29d26f8fb",
"type": "http in",
"z": "6dd9c5de00783d54",
"name": "status v1",
"url": "/v1/status",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 160,
"y": 160,
"wires": [
[
"a34bcca63165d20c",
"fce27334063f2b66"
]
]
},
{
"id": "8ad3dba12fbac00b",
"type": "delay",
"z": "6dd9c5de00783d54",
"name": "",
"pauseType": "random",
"timeout": "10",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 560,
"y": 160,
"wires": [
[
"998184eccf42c592",
"d7a3e1373f326b6c"
]
]
},
{
"id": "fce27334063f2b66",
"type": "debug",
"z": "6dd9c5de00783d54",
"name": "debug 2",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 360,
"y": 220,
"wires": []
},
{
"id": "fbaebe376fa797cd",
"type": "debug",
"z": "6dd9c5de00783d54",
"name": "debug 3",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 560,
"y": 220,
"wires": []
},
{
"id": "d7a3e1373f326b6c",
"type": "debug",
"z": "6dd9c5de00783d54",
"name": "debug 4",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 780,
"y": 220,
"wires": []
},
{
"id": "a34bcca63165d20c",
"type": "function",
"z": "6dd9c5de00783d54",
"name": "function 1",
"func": "msg.payload = {\"msg\":\"Hallo\"};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 160,
"wires": [
[
"8ad3dba12fbac00b",
"fbaebe376fa797cd"
]
]
},
{
"id": "1cbcbeea3ad7ef61",
"type": "debug",
"z": "6dd9c5de00783d54",
"name": "debug 5",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 560,
"y": 100,
"wires": []
},
{
"id": "f1ee942fbf1eaa1c",
"type": "http response",
"z": "6dd9c5de00783d54",
"name": "",
"statusCode": "",
"headers": {},
"x": 550,
"y": 300,
"wires": []
},
{
"id": "b958a2b7496a7149",
"type": "http in",
"z": "6dd9c5de00783d54",
"name": "status v2",
"url": "/v2/status",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 160,
"y": 300,
"wires": [
[
"8740fbbcdbddd7ea",
"f601031a8e8f0978"
]
]
},
{
"id": "f601031a8e8f0978",
"type": "debug",
"z": "6dd9c5de00783d54",
"name": "debug 8",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 360,
"y": 340,
"wires": []
},
{
"id": "6bdb3dc04a4ef78e",
"type": "debug",
"z": "6dd9c5de00783d54",
"name": "debug 9",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 560,
"y": 340,
"wires": []
},
{
"id": "5db4b31076295d65",
"type": "debug",
"z": "6dd9c5de00783d54",
"name": "debug 10",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 560,
"y": 400,
"wires": []
},
{
"id": "8740fbbcdbddd7ea",
"type": "function",
"z": "6dd9c5de00783d54",
"name": "function 2",
"func": "flow.set('lock', true)\nlet queue = flow.get('queue') || {};\nlet ts = new Date().toUTCString()\n//node.warn(ts)\n\nqueue[ts] = {\"timestamp\": ts}\nflow.set('queue', queue)\n\nflow.set('lock', false)\nmsg.payload = {\"msg\":\"Ok\"};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 300,
"wires": [
[
"6bdb3dc04a4ef78e",
"f1ee942fbf1eaa1c"
]
]
},
{
"id": "92ccdbb038bf986c",
"type": "inject",
"z": "6dd9c5de00783d54",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "12",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 150,
"y": 400,
"wires": [
[
"5f03483d33f42146"
]
]
},
{
"id": "5f03483d33f42146",
"type": "function",
"z": "6dd9c5de00783d54",
"name": "function 3",
"func": "let lock = flow.get('lock')\n//node.warn(lock)\nif (lock) return null\n\nlet queue = flow.get('queue') || {}\n//node.warn(queue)\nlet keys = Object.keys(queue)\n//node.warn(keys.length)\nif (keys.length == 0) return null\n\nlet key = keys[0]\n//node.warn(key)\nnode.warn(`${key}: ${queue[key]}`)\ndelete queue[key]\n\nreturn null",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 400,
"wires": [
[
"5db4b31076295d65"
]
]
}
]
[
{
"id": "7d92ad2f593b0dc7",
"type": "tab",
"label": "Web Page Test",
"disabled": false,
"info": "",
"env": []
},
{
"id": "3f3ca19e8fc7a3d9",
"type": "http in",
"z": "7d92ad2f593b0dc7",
"name": "",
"url": "/test",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 100,
"y": 100,
"wires": [
[
"fa0d9cfea577a585"
]
]
},
{
"id": "ecf3d0d8723ddda4",
"type": "template",
"z": "7d92ad2f593b0dc7",
"name": "CSS",
"field": "payload.style",
"fieldType": "msg",
"format": "html",
"syntax": "mustache",
"template": "* {\n margin: 0;\n padding: 0;\n}\n#chart-container {\n position: relative;\n height: 100vh;\n overflow: hidden;\n}\n",
"x": 450,
"y": 360,
"wires": [
[
"c871ec55c9b5d7d5"
]
]
},
{
"id": "f13890b5bd2373af",
"type": "template",
"z": "7d92ad2f593b0dc7",
"name": "JavaScript",
"field": "payload.script",
"fieldType": "msg",
"format": "javascript",
"syntax": "mustache",
"template": "var dom = document.getElementById('chart-container');\nvar myChart = echarts.init(dom, 'dark', {\n renderer: 'canvas',\n useDirtyRect: false\n});\nvar app = {};\n\nvar option = {{{options}}};\n\nif (option && typeof option === 'object') {\n myChart.setOption(option);\n}\n\nwindow.addEventListener('resize', myChart.resize);",
"output": "str",
"x": 470,
"y": 280,
"wires": [
[
"ecf3d0d8723ddda4"
]
]
},
{
"id": "e74bf2fa5542e59d",
"type": "http response",
"z": "7d92ad2f593b0dc7",
"name": "",
"x": 850,
"y": 620,
"wires": []
},
{
"id": "c871ec55c9b5d7d5",
"type": "template",
"z": "7d92ad2f593b0dc7",
"name": "HTML",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <title>{{{title}}}</title>\n <style>{{{payload.style}}}</style>\n</head>\n<body>\n <div id=\"chart-container\"></div>\n <script src=\"https://fastly.jsdelivr.net/npm/echarts@5.3.3/dist/echarts.min.js\"></script>\n <script>{{{payload.script}}}</script>\n</body>\n</html>",
"x": 450,
"y": 440,
"wires": [
[
"e74bf2fa5542e59d"
]
]
},
{
"id": "fa0d9cfea577a585",
"type": "function",
"z": "7d92ad2f593b0dc7",
"name": "set variables",
"func": "msg.title = 'Temperature Test'\nmsg.graph = {}\nmsg.graph.title = msg.title\nmsg.graph.xData = [\n '\"Mon\"',\n '\"Tue\"',\n '\"Wed\"',\n '\"Thu\"',\n '\"Fri\"',\n '\"Sat\"',\n '\"Sun\"',\n '\"Mon\"',\n '\"Tue\"',\n '\"Wed\"',\n '\"Thu\"',\n '\"Fri\"',\n '\"Sat\"',\n '\"Sun\"'\n ]\nmsg.graph.yData = {}\nmsg.graph.yData.maxdata = [\n 10,\n 11,\n 13,\n 11,\n 12,\n 12,\n 9,\n 8,\n 8,\n 6,\n 5,\n 6,\n 7,\n 9\n ]\nmsg.graph.yData.mindata = [\n 1,\n -2,\n 2,\n 5,\n 3,\n 2,\n 0,\n 0,\n -0.5,\n 1,\n 1,\n 3,\n 2,\n 0\n ]\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 290,
"y": 140,
"wires": [
[
"74f34da5aabb0e6b"
]
]
},
{
"id": "74f34da5aabb0e6b",
"type": "template",
"z": "7d92ad2f593b0dc7",
"name": "set options",
"field": "options",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{\n \"title\": {\n \"text\": \"{{{graph.title}}}\"\n },\n \"tooltip\": {\n \"trigger\": \"axis\"\n },\n \"legend\": {},\n \"toolbox\": {\n \"show\": \"true\",\n \"feature\": {\n \"dataZoom\": {\n \"yAxisIndex\": \"none\"\n },\n \"dataView\": {\n \"readOnly\": false\n },\n \"magicType\": {\n \"type\": [\"line\", \"bar\"]\n },\n \"restore\": {},\n \"saveAsImage\": {}\n }\n },\n \"xAxis\": {\n \"type\": \"category\",\n \"boundaryGap\": \"false\",\n \"data\": [{{{graph.xData}}}]\n },\n \"yAxis\": {\n \"type\": \"value\",\n \"axisLabel\": {\n \"formatter\": \"{value} °C\"\n }\n },\n \"series\": [\n {\n \"name\": \"Highest\",\n \"type\": \"line\",\n \"data\": [{{{graph.yData.maxdata}}}],\n \"markPoint\": {\n \"data\": [\n {\n \"type\": \"max\",\n \"name\": \"Max\"\n }, {\n \"type\": \"min\",\n \"name\": \"Min\"\n }\n ]\n },\n \"markLine\": {\n \"data\": [\n {\n \"type\": \"average\",\n \"name\": \"Avg\"\n },\n [\n {\n \"symbol\": \"none\",\n \"x\": \"90%\",\n \"yAxis\": \"max\"\n\n }, {\n \"symbol\": \"circle\",\n \"label\": {\n \"position\": \"start\",\n \"formatter\": \"Max\"\n },\n \"type\": \"max\",\n \"name\": \"Max\"\n }\n ]\n ]\n }\n }, {\n \"name\": \"Lowest\",\n \"type\": \"line\",\n \"data\": [{{{graph.yData.mindata}}}],\n \"markPoint\": {\n \"data\": [\n {\n \"name\": \"TempLo\",\n \"value\": -2,\n \"xAxis\": 1,\n \"yAxis\": -1.5\n },\n {\n \"name\": \"TempHi\",\n \"value\": 5,\n \"xAxis\": 3,\n \"yAxis\": 5.5\n }\n ]\n },\n \"markLine\": {\n \"data\": [\n {\n \"type\": \"average\",\n \"name\": \"Avg\"\n },\n [\n {\n \"symbol\": \"none\",\n \"x\": \"90%\",\n \"yAxis\": \"max\"\n\n }, {\n \"symbol\": \"circle\",\n \"label\": {\n \"position\": \"start\",\n \"formatter\": \"Max\"\n },\n \"type\": \"max\",\n \"name\": \"Max\"\n }\n ]\n ]\n }\n }\n ]\n}\n",
"output": "str",
"x": 470,
"y": 200,
"wires": [
[
"f13890b5bd2373af",
"342a659a31267cad"
]
]
},
{
"id": "342a659a31267cad",
"type": "debug",
"z": "7d92ad2f593b0dc7",
"name": "debug 7",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 820,
"y": 340,
"wires": []
}
]
[
{
"id": "95f12f69e9cb18d3",
"type": "tab",
"label": "API Temp",
"disabled": false,
"info": "",
"env": []
},
{
"id": "49a85ead0c78db3a",
"type": "http in",
"z": "95f12f69e9cb18d3",
"name": "",
"url": "/api/v1/temperature/:cw",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 220,
"y": 100,
"wires": [
[
"76b4f1a06efa2d26",
"7865c6ec9ae2c34b"
]
]
},
{
"id": "bb9c030916ac8d84",
"type": "http response",
"z": "95f12f69e9cb18d3",
"name": "",
"statusCode": "",
"headers": {},
"x": 650,
"y": 100,
"wires": []
},
{
"id": "76b4f1a06efa2d26",
"type": "template",
"z": "95f12f69e9cb18d3",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{\n \"title\": {\n \"text\": \"Temperature Change in the Coming Week {{{req.params.cw}}}\"\n },\n \"tooltip\": {\n \"trigger\": \"axis\"\n },\n \"legend\": {},\n \"toolbox\": {\n \"show\": \"true\",\n \"feature\": {\n \"dataZoom\": {\n \"yAxisIndex\": \"none\"\n },\n \"dataView\": {\n \"readOnly\": false\n },\n \"magicType\": {\n \"type\": [\"line\", \"bar\"]\n },\n \"restore\": {},\n \"saveAsImage\": {}\n }\n },\n \"xAxis\": {\n \"type\": \"category\",\n \"boundaryGap\": \"false\",\n \"data\": [\n \"Mon\",\n \"Tue\",\n \"Wed\",\n \"Thu\",\n \"Fri\",\n \"Sat\",\n \"Sun\"\n ]\n },\n \"yAxis\": {\n \"type\": \"value\",\n \"axisLabel\": {\n \"formatter\": \"{value} °C\"\n }\n },\n \"series\": [\n {\n \"name\": \"Highest\",\n \"type\": \"line\",\n \"data\": [\n 10,\n 11,\n 13,\n 11,\n 12,\n 12,\n 9\n ],\n \"markPoint\": {\n \"data\": [\n {\n \"type\": \"max\",\n \"name\": \"Max\"\n }, {\n \"type\": \"min\",\n \"name\": \"Min\"\n }\n ]\n },\n \"markLine\": {\n \"data\": [\n {\n \"type\": \"average\",\n \"name\": \"Avg\"\n }\n ]\n }\n }, {\n \"name\": \"Lowest\",\n \"type\": \"line\",\n \"data\": [\n 1,\n -2,\n 2,\n 5,\n 3,\n 2,\n 0\n ],\n \"markPoint\": {\n \"data\": [\n {\n \"name\": \"Temp\",\n \"value\": -2,\n \"xAxis\": 1,\n \"yAxis\": -1.5\n }\n ]\n },\n \"markLine\": {\n \"data\": [\n {\n \"type\": \"average\",\n \"name\": \"Avg\"\n },\n [\n {\n \"symbol\": \"none\",\n \"x\": \"90%\",\n \"yAxis\": \"max\"\n\n }, {\n \"symbol\": \"circle\",\n \"label\": {\n \"position\": \"start\",\n \"formatter\": \"Max\"\n },\n \"type\": \"max\",\n \"name\": \"Temp\"\n }\n ]\n ]\n }\n }\n ]\n}\n",
"output": "json",
"x": 460,
"y": 100,
"wires": [
[
"bb9c030916ac8d84"
]
]
},
{
"id": "7865c6ec9ae2c34b",
"type": "debug",
"z": "95f12f69e9cb18d3",
"name": "debug 6",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "req.params.cw",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 460,
"y": 140,
"wires": []
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment