Skip to content

Instantly share code, notes, and snippets.

@kumajaya
Last active October 3, 2020 14:35
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 kumajaya/88835061782797f632e1581a06250619 to your computer and use it in GitHub Desktop.
Save kumajaya/88835061782797f632e1581a06250619 to your computer and use it in GitHub Desktop.
Rapid SCADA - Grafana Data Provider - Node-RED
[
{
"id": "5d938c28.47ae64",
"type": "inject",
"z": "905fe045.cf464",
"name": "set request",
"props": [
{
"p": "targets",
"v": "[{\"target\":\"3201\",\"type\":\"timeserie\"},{\"target\":\"3202\",\"type\":\"timeserie\"},{\"target\":\"3203\",\"type\":\"timeserie\"},{\"target\":\"3204\",\"type\":\"timeserie\"},{\"target\":\"3205\",\"type\":\"timeserie\"},{\"target\":\"3206\",\"type\":\"timeserie\"},{\"target\":\"3207\",\"type\":\"timeserie\"},{\"target\":\"3208\",\"type\":\"timeserie\"},{\"target\":\"3209\",\"type\":\"timeserie\"},{\"target\":\"3210\",\"type\":\"timeserie\"},{\"target\":\"3211\",\"type\":\"timeserie\"},{\"target\":\"3212\",\"type\":\"timeserie\"},{\"target\":\"3213\",\"type\":\"timeserie\"},{\"target\":\"3214\",\"type\":\"timeserie\"}]",
"vt": "json"
},
{
"p": "time_from",
"v": "$moment().subtract(1, 'minutes').utc().format('YYYY-MM-DDTHH:mm:ss.SSS[Z]')",
"vt": "jsonata"
},
{
"p": "time_to",
"v": "$moment().utc().format('YYYY-MM-DDTHH:mm:ss.SSS[Z]')",
"vt": "jsonata"
},
{
"p": "payload"
},
{
"p": "url",
"v": "http://192.168.4.247/GrafanaDataProvider/api/trends/query",
"vt": "str"
},
{
"p": "header",
"v": "{}",
"vt": "json"
},
{
"p": "msg.headers['Content-Type']",
"v": "application/json",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": "5",
"topic": "",
"payload": "{\t \"panelId\": 1,\t \"range\": {\t \"from\": time_from,\t \"to\": time_to\t },\t \"interval\": \"1m\",\t \"intervalMs\": 60000,\t \"targets\": [targets],\t \"format\": \"json\",\t \"maxDataPoints\": 1\t}",
"payloadType": "jsonata",
"x": 100,
"y": 660,
"wires": [
[
"2bbd4285.69c1fe",
"cd323eaf.9e539"
]
]
},
{
"id": "cd323eaf.9e539",
"type": "http request",
"z": "905fe045.cf464",
"name": "post request",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 270,
"y": 660,
"wires": [
[
"ad128778.6c1338",
"67ef2d74.890cb4"
]
]
},
{
"id": "ad128778.6c1338",
"type": "change",
"z": "905fe045.cf464",
"name": "parse response",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload. {\t \"target\": target,\t \"datapoints\": $filter(\t datapoints,\t function($v) { $v[0] != null } \t )[-1]\t}",
"tot": "jsonata"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload#$i. {\t \"target\": target,\t \"index\": $i,\t \"value\": datapoints[0],\t \"ts\": datapoints[1]\t}",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 480,
"y": 660,
"wires": [
[
"6813b210.fe643c"
]
]
},
{
"id": "6813b210.fe643c",
"type": "function",
"z": "905fe045.cf464",
"name": "serialize output",
"func": "function pad(num, size) {\n var s = \"00\" + num;\n return s.substr(s.length-size);\n}\n\nvar out = [];\nvar tmp;\n\nfor (i = 0; i < msg.payload.length; i++) {\n if (i === 12) {\n tmp = { pin:i, topic:msg.payload[i].target, payload:parseInt(msg.payload[i].value)*85 };\n } else if (i === 13) {\n tmp = { pin:i, topic:msg.payload[i].target, payload:parseInt(msg.payload[i].value)*255 };\n } else {\n tmp = { pin:i, topic:msg.payload[i].target, payload:parseFloat(msg.payload[i].value).toFixed(2) };\n }\n\n out.push(tmp);\n}\n\ntmp = new Date(msg.payload[msg.payload.length - 1].ts);\ntmp = pad(tmp.getDate(), 2) + '/' + pad(tmp.getMonth() + 1, 2) + '/' + pad(tmp.getFullYear(), 2) + ' ' + pad(tmp.getHours(), 2) + ':' + pad(tmp.getMinutes(), 2);\ntmp = { pin:msg.payload.length, topic:'timestamp', payload:tmp };\nout.push(tmp);\n\nreturn [out];",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 680,
"y": 660,
"wires": [
[
"62f6bef9.63ef7"
]
]
},
{
"id": "62f6bef9.63ef7",
"type": "debug",
"z": "905fe045.cf464",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 870,
"y": 660,
"wires": []
},
{
"id": "67ef2d74.890cb4",
"type": "debug",
"z": "905fe045.cf464",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 470,
"y": 720,
"wires": []
},
{
"id": "2bbd4285.69c1fe",
"type": "debug",
"z": "905fe045.cf464",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 270,
"y": 600,
"wires": []
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment