Compare commits

...
Sign in to create a new pull request.

15 commits

Author SHA1 Message Date
Jakub Klena
f7350c117d Merged in senica-rvo-fix-line-control (pull request #4)
Senica rvo fix line control
2024-09-09 11:47:59 +00:00
Jakub Klena
e3c68f3d86 Merged master into senica-rvo-fix-line-control 2024-09-09 11:47:05 +00:00
Jakub Klena
7e20c7d3f0 Removing duplicate 2024-09-09 13:44:39 +02:00
8929cc3a53 actual working Senica Rvo code 09/2024 2024-09-09 12:32:34 +02:00
Jakub Klena
464e74fe26 Merged in feat/Create-slack-connector (pull request #2)
Feat/Create slack connector

Approved-by: Rastislav Kovac
2024-09-06 13:00:04 +00:00
rasta5man
f4ffef94b9 kovalov part delete 2024-06-20 17:56:49 +02:00
Jakub Klena
1b7aae4590 removing some debug msgs 2024-05-24 08:44:15 +02:00
Jakub Klena
6d468acd6f proper last version 2024-05-24 08:42:21 +02:00
Jakub Klena
9e2ab3ccea api key fix 2024-05-24 01:24:08 +02:00
Jakub Klena
2f659a164b Slack connector component 2024-05-24 01:19:34 +02:00
rasta5man
54038a06f8 major updated line switching version 2024-05-10 2024-05-21 15:49:42 +02:00
rasta5man
d289a99d07 new switching line functionality - in progress 2024-05-14 16:29:11 +02:00
rasta5man
31fe341ef1 refactoring - no change 2024-05-14 16:17:58 +02:00
rasta5man
86c7b3a942 add buildTasks function to dido_controller and handle 7 lines with state_of_braker 2024-05-07 16:28:43 +02:00
rasta5man
ac2ccc1c61 senica add rebuild tasks at 11 on tuesday and saturday 2024-05-07 14:11:40 +02:00
10 changed files with 6656 additions and 6519 deletions

View file

@ -1,4 +1,5 @@
const timeoutInterval = 300000;
const timeoutInterval = 150000;
const deviceConfig = [
{
device: "em340",
@ -110,4 +111,4 @@ const deviceConfig = [
}
];
module.exports = { timeoutInterval, deviceConfig };
module.exports = { timeoutInterval, deviceConfig };

View file

@ -31,4 +31,7 @@ key:string|weight:string|sk:string|en:string
+|voltage_on_phase_restored|NOTICE|Napätie na fáze č. ${phase} bolo obnovené|Voltage on phase no. ${phase} has been restored|...............
+|flow_start|NOTICE|FLOW bol spustený|FLOW has been started |...............
+|twilight_sensor_nok|ERROR|Sensor súmraku neodpovedá|Twilight sensor is not responding|...............
+|twilight_sensor_ok|NOTICE|Sensor súmraku znovu odpovedá|Twilight sensor is responding again|...............
+|twilight_sensor_ok|NOTICE|Sensor súmraku znovu odpovedá|Twilight sensor is responding again|...............
+|lamps_have_turned_on|NOTICE|Lampy sa zapli|Lamps have turned on|...............
+|lamps_have_turned_off|NOTICE|Lampy sa vypli|Lamps have turned off|...............
+|flow_restart|NOTICE|Restart flowu|Flow has been restarted|...............

File diff suppressed because it is too large Load diff

View file

@ -20,37 +20,13 @@
}
],
"components": [
{
"id": "1611938192035",
"component": "debug",
"tab": "1611921777196",
"name": "modbus_ddebug",
"x": 400.5,
"y": 121.5,
"connections": {},
"disabledio": {
"input": [],
"output": []
},
"state": {
"text": "Enabled",
"color": "gray"
},
"options": {
"type": "data",
"repository": false,
"enabled": true
},
"color": "#967ADC",
"notes": ""
},
{
"id": "1611951142547",
"component": "debug",
"tab": "1611921777196",
"name": "ERROR",
"x": 404,
"y": 29,
"x": 401,
"y": 31,
"connections": {},
"disabledio": {
"input": [],
@ -68,35 +44,13 @@
"color": "#DA4453",
"notes": ""
},
{
"id": "1612772119611",
"component": "virtualwireout",
"tab": "1611921777196",
"name": "tb-push",
"x": 399.75,
"y": 211.5,
"connections": {},
"disabledio": {
"input": [],
"output": []
},
"state": {
"text": "tb-push",
"color": "gray"
},
"options": {
"wirename": "tb-push"
},
"color": "#303E4D",
"notes": ""
},
{
"id": "1612776786008",
"component": "wsmqttpublish",
"tab": "1612772287426",
"name": "WS MQTT publish",
"x": 311.75,
"y": 268,
"y": 248,
"connections": {
"0": [
{
@ -148,7 +102,7 @@
"tab": "1612772287426",
"name": "tb-push",
"x": 68.75,
"y": 289,
"y": 269,
"connections": {
"0": [
{
@ -181,7 +135,7 @@
"tab": "1612772287426",
"name": "to TB",
"x": 317.75,
"y": 174,
"y": 154,
"connections": {},
"disabledio": {
"input": [
@ -201,33 +155,13 @@
"color": "#967ADC",
"notes": ""
},
{
"id": "1613576617722",
"component": "comment",
"tab": "1612772287426",
"name": "In case broker is not ready, we save data to database, and when connected, we resend data",
"x": 72.88333129882812,
"y": 32,
"connections": {},
"disabledio": {
"input": [],
"output": []
},
"state": {
"text": "",
"color": "gray"
},
"options": {},
"color": "#704cff",
"notes": ""
},
{
"id": "1615551060773",
"component": "debug",
"tab": "1612772287426",
"name": "errors from MQTT Broker",
"x": 610,
"y": 131,
"y": 111,
"connections": {},
"disabledio": {
"input": [
@ -252,8 +186,8 @@
"component": "debug",
"tab": "1615551125555",
"name": "Debug",
"x": 763,
"y": 123,
"x": 755,
"y": 19,
"connections": {},
"disabledio": {
"input": [
@ -278,8 +212,8 @@
"component": "virtualwireout",
"tab": "1615551125555",
"name": "tb-push",
"x": 761,
"y": 216,
"x": 753,
"y": 112,
"connections": {},
"disabledio": {
"input": [],
@ -300,8 +234,8 @@
"component": "debug",
"tab": "1615551125555",
"name": "CMD_debug",
"x": 758,
"y": 301,
"x": 750,
"y": 197,
"connections": {},
"disabledio": {
"input": [
@ -327,7 +261,7 @@
"tab": "1611921777196",
"name": "Debug",
"x": 398.8833312988281,
"y": 477.3500061035156,
"y": 528.3500061035156,
"connections": {},
"disabledio": {
"input": [
@ -336,13 +270,13 @@
"output": []
},
"state": {
"text": "Enabled",
"text": "Disabled",
"color": "gray"
},
"options": {
"type": "data",
"repository": false,
"enabled": true
"enabled": false
},
"color": "#967ADC",
"notes": ""
@ -352,8 +286,8 @@
"component": "debug",
"tab": "1611921777196",
"name": "Debug",
"x": 406.8833312988281,
"y": 567.3500061035156,
"x": 401.8833312988281,
"y": 625.3500061035156,
"connections": {},
"disabledio": {
"input": [
@ -378,8 +312,8 @@
"component": "virtualwireout",
"tab": "1611921777196",
"name": "tb-push",
"x": 404.8833312988281,
"y": 653.25,
"x": 400.8833312988281,
"y": 328.25,
"connections": {},
"disabledio": {
"input": [],
@ -400,8 +334,8 @@
"component": "httproute",
"tab": "1615551125555",
"name": "POST /terminal",
"x": 110,
"y": 508,
"x": 72,
"y": 350,
"connections": {
"0": [
{
@ -446,8 +380,8 @@
"component": "httpresponse",
"tab": "1615551125555",
"name": "HTTP Response",
"x": 759,
"y": 377,
"x": 751,
"y": 273,
"connections": {},
"disabledio": {
"input": [],
@ -468,8 +402,8 @@
"component": "debug",
"tab": "1615551125555",
"name": "DIDO_Debug",
"x": 743,
"y": 839,
"x": 739,
"y": 635,
"connections": {},
"disabledio": {
"input": [
@ -494,8 +428,8 @@
"component": "trigger",
"tab": "1615551125555",
"name": "turnOff line",
"x": 75,
"y": 1033,
"x": 71,
"y": 829,
"connections": {
"0": [
{
@ -524,8 +458,8 @@
"component": "virtualwireout",
"tab": "1615551125555",
"name": "tb-push",
"x": 751,
"y": 940,
"x": 741,
"y": 736,
"connections": {},
"disabledio": {
"input": [],
@ -546,8 +480,8 @@
"component": "debug",
"tab": "1615551125555",
"name": "Debug",
"x": 628,
"y": 1246,
"x": 605,
"y": 1024,
"connections": {},
"disabledio": {
"input": [],
@ -570,8 +504,8 @@
"component": "trigger",
"tab": "1615551125555",
"name": "start import",
"x": 258,
"y": 1254,
"x": 235,
"y": 1032,
"connections": {
"0": [
{
@ -600,8 +534,8 @@
"component": "csv_import",
"tab": "1615551125555",
"name": "CsvImport",
"x": 437,
"y": 1235,
"x": 414,
"y": 1013,
"connections": {
"0": [
{
@ -629,8 +563,8 @@
"component": "comment",
"tab": "1615551125555",
"name": "import data from csv",
"x": 424,
"y": 1168,
"x": 401,
"y": 946,
"connections": {},
"disabledio": {
"input": [],
@ -649,8 +583,8 @@
"component": "trigger",
"tab": "1615551125555",
"name": "update profile / node",
"x": 119,
"y": 130,
"x": 80,
"y": 13,
"connections": {
"0": [
{
@ -678,9 +612,9 @@
"id": "1618235171399",
"component": "trigger",
"tab": "1615551125555",
"name": "run tasks",
"x": 122,
"y": 206,
"name": "tun tasks",
"x": 77,
"y": 84,
"connections": {
"0": [
{
@ -709,7 +643,7 @@
"tab": "1612772287426",
"name": "wsmqtt-exit1",
"x": 610.8833312988281,
"y": 219,
"y": 199,
"connections": {},
"disabledio": {
"input": [],
@ -733,7 +667,7 @@
"tab": "1612772287426",
"name": "wsmqtt-exit2",
"x": 611.8833312988281,
"y": 394,
"y": 374,
"connections": {},
"disabledio": {
"input": [
@ -758,8 +692,8 @@
"component": "virtualwireout",
"tab": "1615551125555",
"name": "to-cmd-manager",
"x": 744.8833312988281,
"y": 1032,
"x": 740.8833312988281,
"y": 828,
"connections": {},
"disabledio": {
"input": [],
@ -780,8 +714,8 @@
"component": "virtualwirein",
"tab": "1615551125555",
"name": "platform-rpc-call",
"x": 115.88333129882812,
"y": 316,
"x": 77.88333129882812,
"y": 173,
"connections": {
"0": [
{
@ -809,8 +743,8 @@
"component": "virtualwirein",
"tab": "1615551125555",
"name": "cmd_to_dido",
"x": 78.88333129882812,
"y": 864,
"x": 76.88333129882812,
"y": 678,
"connections": {
"0": [
{
@ -842,8 +776,8 @@
"component": "virtualwireout",
"tab": "1615551125555",
"name": "cmd_to_dido",
"x": 756.8833312988281,
"y": 477,
"x": 748.8833312988281,
"y": 373,
"connections": {},
"disabledio": {
"input": [],
@ -865,7 +799,7 @@
"tab": "1612772287426",
"name": "platform-rpc-call",
"x": 611.8833312988281,
"y": 307,
"y": 287,
"connections": {},
"disabledio": {
"input": [],
@ -886,8 +820,8 @@
"component": "trigger",
"tab": "1615551125555",
"name": "turnOn line",
"x": 76,
"y": 947,
"x": 72,
"y": 756,
"connections": {
"0": [
{
@ -916,8 +850,8 @@
"component": "cmd_manager",
"tab": "1615551125555",
"name": "CMD Manager",
"x": 442,
"y": 290,
"x": 420,
"y": 156,
"connections": {
"0": [
{
@ -971,8 +905,8 @@
"component": "httproute",
"tab": "1615551125555",
"name": "GET db",
"x": 104,
"y": 619,
"x": 73,
"y": 455,
"connections": {
"0": [
{
@ -1016,8 +950,8 @@
"component": "trigger",
"tab": "1615551125555",
"name": "turnOnAlarm",
"x": 72,
"y": 1106,
"x": 68,
"y": 902,
"connections": {
"0": [
{
@ -1046,8 +980,8 @@
"component": "trigger",
"tab": "1615551125555",
"name": "turnOffAlarm",
"x": 71,
"y": 1179,
"x": 67,
"y": 975,
"connections": {
"0": [
{
@ -1076,8 +1010,8 @@
"component": "virtualwireout",
"tab": "1611921777196",
"name": "modbus_to_dido",
"x": 396,
"y": 390,
"x": 399,
"y": 433,
"connections": {},
"disabledio": {
"input": [],
@ -1188,7 +1122,7 @@
"tab": "1612772287426",
"name": "RAM",
"x": 71.88333129882812,
"y": 629.5,
"y": 609.5,
"connections": {
"0": [
{
@ -1202,7 +1136,7 @@
"output": []
},
"state": {
"text": "826.22 MB / 985.68 MB",
"text": "834.19 MB / 985.68 MB",
"color": "gray"
},
"options": {
@ -1218,7 +1152,7 @@
"tab": "1612772287426",
"name": "disk",
"x": 72.88333129882812,
"y": 726.5,
"y": 706.5,
"connections": {
"0": [
{
@ -1232,7 +1166,7 @@
"output": []
},
"state": {
"text": "5.85 GB / 7.26 GB",
"text": "5.84 GB / 7.26 GB",
"color": "gray"
},
"options": {
@ -1249,7 +1183,7 @@
"tab": "1612772287426",
"name": "send-to-services",
"x": 5.883331298828125,
"y": 1089.5,
"y": 1069.5,
"connections": {
"0": [
{
@ -1282,7 +1216,7 @@
"tab": "1612772287426",
"name": "send-to-services",
"x": 428.8833312988281,
"y": 622.5,
"y": 602.5,
"connections": {},
"disabledio": {
"input": [],
@ -1304,7 +1238,7 @@
"tab": "1612772287426",
"name": "send-to-services",
"x": 612.8833312988281,
"y": 482.5,
"y": 462.5,
"connections": {},
"disabledio": {
"input": [],
@ -1327,7 +1261,7 @@
"name": "http://192.168.252.2:8004/sentmessage",
"reference": "",
"x": 439.8833312988281,
"y": 1096.7333374023438,
"y": 1076.7333374023438,
"connections": {
"0": [
{
@ -1358,7 +1292,7 @@
"tab": "1612772287426",
"name": "Debug",
"x": 234.75,
"y": 1044,
"y": 1024,
"connections": {},
"disabledio": {
"input": [
@ -1384,7 +1318,7 @@
"tab": "1612772287426",
"name": "Code",
"x": 255,
"y": 532,
"y": 512,
"connections": {
"0": [
{
@ -1419,7 +1353,7 @@
"tab": "1612772287426",
"name": "Debug",
"x": 430,
"y": 528,
"y": 508,
"connections": {},
"disabledio": {
"input": [
@ -1445,7 +1379,7 @@
"tab": "1612772287426",
"name": "Code",
"x": 244,
"y": 628,
"y": 608,
"connections": {
"0": [
{
@ -1480,7 +1414,7 @@
"tab": "1612772287426",
"name": "Debug",
"x": 431,
"y": 720,
"y": 700,
"connections": {},
"disabledio": {
"input": [
@ -1506,7 +1440,7 @@
"tab": "1612772287426",
"name": "Code",
"x": 247,
"y": 722,
"y": 702,
"connections": {
"0": [
{
@ -1541,7 +1475,7 @@
"tab": "1612772287426",
"name": "Debug",
"x": 434,
"y": 812,
"y": 792,
"connections": {},
"disabledio": {
"input": [
@ -1567,7 +1501,7 @@
"tab": "1612772287426",
"name": "Send info",
"x": 438,
"y": 1205,
"y": 1185,
"connections": {},
"disabledio": {
"input": [
@ -1593,7 +1527,7 @@
"tab": "1612772287426",
"name": "Info sender",
"x": 233,
"y": 1142,
"y": 1122,
"connections": {
"0": [
{
@ -1626,7 +1560,7 @@
"tab": "1612772287426",
"name": "Debug",
"x": 811.8833312988281,
"y": 1090.5,
"y": 1070.5,
"connections": {},
"disabledio": {
"input": [
@ -1651,8 +1585,8 @@
"component": "virtualwireout",
"tab": "1615551125555",
"name": "send-to-services",
"x": 756,
"y": 568,
"x": 748,
"y": 464,
"connections": {},
"disabledio": {
"input": [],
@ -1674,7 +1608,7 @@
"tab": "1612772287426",
"name": "CPU",
"x": 71,
"y": 535,
"y": 515,
"connections": {
"0": [
{
@ -1688,7 +1622,7 @@
"output": []
},
"state": {
"text": "0.9% / 86.46 MB",
"text": "1.9% / 86.94 MB",
"color": "gray"
},
"options": {
@ -1707,8 +1641,8 @@
"component": "debug",
"tab": "1615551125555",
"name": "CMDtoDIDO",
"x": 417,
"y": 858,
"x": 413,
"y": 654,
"connections": {},
"disabledio": {
"input": [
@ -1733,8 +1667,8 @@
"component": "virtualwirein",
"tab": "1615551125555",
"name": "from-dido-controller",
"x": 113,
"y": 423,
"x": 71,
"y": 260,
"connections": {
"0": [
{
@ -1766,8 +1700,8 @@
"component": "debug",
"tab": "1615551125555",
"name": "from dido to cmd",
"x": 441,
"y": 461,
"x": 423,
"y": 331,
"connections": {},
"disabledio": {
"input": [
@ -1792,8 +1726,8 @@
"component": "debug",
"tab": "1615551125555",
"name": "HTTP routes",
"x": 441,
"y": 564,
"x": 423,
"y": 422,
"connections": {},
"disabledio": {
"input": [
@ -1818,8 +1752,8 @@
"component": "debug",
"tab": "1611921777196",
"name": "MDBToDido",
"x": 402,
"y": 300,
"x": 401,
"y": 118,
"connections": {},
"disabledio": {
"input": [],
@ -1842,8 +1776,8 @@
"component": "dido_controller",
"tab": "1615551125555",
"name": "DIDO_Controller",
"x": 406,
"y": 940,
"x": 402,
"y": 736,
"connections": {
"0": [
{
@ -1887,8 +1821,8 @@
"component": "virtualwirein",
"tab": "1615551125555",
"name": "modbus_to_dido",
"x": 83,
"y": 775,
"x": 79,
"y": 595,
"connections": {
"0": [
{
@ -1920,8 +1854,8 @@
"component": "debug",
"tab": "1615551125555",
"name": "modbusToDido",
"x": 415,
"y": 765,
"x": 411,
"y": 561,
"connections": {},
"disabledio": {
"input": [
@ -1963,16 +1897,20 @@
{
"index": "0",
"id": "1684179110403"
},
{
"index": "0",
"id": "1717441414646"
}
],
"2": [
{
"index": "0",
"id": "1621340721628"
"id": "1615809595184"
},
{
"index": "0",
"id": "1684179110403"
"id": "1714752862828"
}
]
},
@ -1993,8 +1931,8 @@
"component": "thermometer",
"tab": "1611921777196",
"name": "Thermometer",
"x": 94.75,
"y": 414,
"x": 107.75,
"y": 449,
"connections": {
"0": [
{
@ -2030,6 +1968,264 @@
"options": {},
"color": "#5CB36D",
"notes": ""
},
{
"id": "1714752862828",
"component": "debug",
"tab": "1611921777196",
"name": "MDBToTb",
"x": 402,
"y": 228,
"connections": {},
"disabledio": {
"input": [],
"output": []
},
"state": {
"text": "Enabled",
"color": "gray"
},
"options": {
"type": "data",
"repository": false,
"enabled": true
},
"color": "#967ADC",
"notes": ""
},
{
"id": "1717441414646",
"component": "code",
"tab": "1611921777196",
"name": "device-status",
"x": 588.0833282470703,
"y": 177,
"connections": {
"0": [
{
"index": "0",
"id": "1717442627834"
},
{
"index": "0",
"id": "1717442631338"
}
]
},
"disabledio": {
"input": [],
"output": []
},
"state": {
"text": "",
"color": "gray"
},
"options": {
"keepmessage": true,
"code": "if(value.hasOwnProperty(\"status\"))\n{\n\tif(value.status.includes(\"-em\"))\n\t{\n\t\tsend(0, {\"em_status\": \"NOK\"});\n\t}\n\telse if(value.status.includes(\"twilight\"))\n\t{\n\t\tsend(0, {\"lux_sensor\": \"NOK\"});\n\t}\n}\n\nif(value.hasOwnProperty(\"values\"))\n{\n\tif(value.values.hasOwnProperty(\"twilight_sensor\"))\n\t{\n\t\tsend(0, {\"lux_sensor\": \"OK\"});\n\t}\n\telse if(value.values.hasOwnProperty(\"Phase_1_power\") ||\n\t\t\tvalue.values.hasOwnProperty(\"Phase_1_voltage\") ||\n\t\t\tvalue.values.hasOwnProperty(\"Total_power\") ||\n\t\t\tvalue.values.hasOwnProperty(\"Phase_1_current\"))\n\t{\n\t\tsend(0, {\"em_status\": \"OK\"});\n\t}\n}",
"outputs": 1
},
"color": "#656D78",
"notes": ""
},
{
"id": "1717442627834",
"component": "debug",
"tab": "1611921777196",
"name": "modbus service",
"x": 802.0833282470703,
"y": 139,
"connections": {},
"disabledio": {
"input": [
0
],
"output": []
},
"state": {
"text": "Enabled",
"color": "gray"
},
"options": {
"type": "data",
"repository": false,
"enabled": true
},
"color": "#967ADC",
"notes": ""
},
{
"id": "1717442631338",
"component": "virtualwireout",
"tab": "1611921777196",
"name": "send-to-services",
"x": 801.0833282470703,
"y": 236,
"connections": {},
"disabledio": {
"input": [],
"output": []
},
"state": {
"text": "send-to-services",
"color": "gray"
},
"options": {
"wirename": "send-to-services"
},
"color": "#303E4D",
"notes": ""
},
{
"id": "1718016045116",
"component": "virtualwirein",
"tab": "1612772287426",
"name": "tb-push",
"x": 84.75,
"y": 1300,
"connections": {
"0": [
{
"index": "0",
"id": "1718016052341"
}
]
},
"disabledio": {
"input": [],
"output": []
},
"state": {
"text": "tb-push",
"color": "gray"
},
"options": {
"wirename": "tb-push"
},
"color": "#303E4D",
"notes": ""
},
{
"id": "1718016052341",
"component": "slack_filter",
"tab": "1612772287426",
"name": "Slack Filter",
"x": 278,
"y": 1297,
"connections": {
"0": [
{
"index": "0",
"id": "1718016086212"
},
{
"index": "0",
"id": "1718016073501"
}
]
},
"disabledio": {
"input": [],
"output": []
},
"state": {
"text": "Running",
"color": "gray"
},
"options": {
"slack_channel": "C071KN2Q8SK",
"tag_on_include": "[{\"user_id\":\"U072JE5JUQG\", \"includes\":[\"Electrometer\", \"Twilight sensor\"]}]",
"message_includes": "[\"is responding again\", \"Lamps have turned\", \"Flow has been restarted\"]",
"types": "[\"emergency\", \"critical\", \"error\", \"alert\"]",
"name": "RVO16 Senica - 10.0.0.131"
},
"color": "#30E193",
"notes": ""
},
{
"id": "1718016073501",
"component": "httprequest",
"tab": "1612772287426",
"name": "http://192.168.252.2:8004/slack",
"x": 471,
"y": 1354,
"connections": {
"0": [
{
"index": "0",
"id": "1718016086212"
}
]
},
"disabledio": {
"input": [],
"output": []
},
"state": {
"text": "",
"color": "gray"
},
"options": {
"stringify": "json",
"method": "POST",
"url": "http://192.168.252.2:8004/slack"
},
"color": "#5D9CEC",
"notes": ""
},
{
"id": "1718016086212",
"component": "debug",
"tab": "1612772287426",
"name": "Debug",
"x": 808,
"y": 1302,
"connections": {},
"disabledio": {
"input": [],
"output": []
},
"state": {
"text": "Enabled",
"color": "gray"
},
"options": {
"type": "data",
"repository": false,
"enabled": true
},
"color": "#967ADC",
"notes": ""
},
{
"id": "1718016094070",
"component": "trigger",
"tab": "1612772287426",
"name": "Trigger",
"x": 73,
"y": 1388,
"connections": {
"0": [
{
"index": "0",
"id": "1718016052341"
}
]
},
"disabledio": {
"input": [],
"output": []
},
"state": {
"text": "",
"color": "gray"
},
"options": {
"datatype": "object",
"data": "{ \"g9OxBZ5KRwNznlY6pAppqEAWXvjdEL4eGQobMDy2\": [ { \"ts\": 1716289039281, \"values\": { \"_event\": { \"type\": \"alert\", \"status\": \"new\", \"source\": { \"func\": \"CMD Manager: process cmd\", \"component\": \"1619515097737\", \"component_name\": \"CMD Manager\", \"edge\": \"g9OxBZ5KRwNznlY6pAppqEAWXvjdEL4eGQobMDy2\" }, \"message\": \"NOW CONNECTED TO SLACK !\", \"message_data\": \"\" } } } ] }"
},
"color": "#F6BB42",
"notes": ""
}
],
"version": 615

File diff suppressed because it is too large Load diff

View file

@ -1,218 +0,0 @@
exports.id = 'thermometer';
exports.title = 'Thermometer';
exports.group = 'Worksys';
exports.color = '#5CB36D';
exports.version = '1.0.3';
exports.output = ["red", "white", "blue"];
exports.author = 'Rastislav Kovac';
exports.icon = 'thermometer-three-quarters';
exports.readme = `# Getting temperature values for RVO. In case of LM, you need device address. In case of unipi, evok sends values, in case thermometer is installed`;
const instanceSendTo = {
debug: 0,
tb: 1,
dido_controller: 2
}
//read temperature - frequency
let timeoutMin = 5;//minutes
var path = require('path');
var log4js = require("log4js");
log4js.configure({
appenders: {
errLogs: { type: 'file', filename: path.join(__dirname + "/../", 'err.txt') },
monitorLogs: { type: 'file', compress:true, daysToKeep: 2, maxLogSize: 1048576, backups: 1, keepFileExt: true, filename: path.join(__dirname + "/../", 'monitor.txt') },
console: { type: 'console' }
},
categories: {
errLogs: { appenders: ['console', 'errLogs'], level: 'error' },
monitorLogs: { appenders: ['console', 'monitorLogs'], level: 'trace' },
//another: { appenders: ['console'], level: 'trace' },
default: { appenders: ['console'], level: 'trace' }
}
});
const errLogger = log4js.getLogger("errLogs");
const logger = log4js.getLogger();
const monitor = log4js.getLogger("monitorLogs");
//logger.debug("text")
//monitor.info('info');
//errLogger.error("some error");
const { promisifyBuilder } = require('./helper/db_helper');
const dbSettings = TABLE("settings");
let temperatureAddress = "";
async function loadSettings()
{
//todo global FLOW.OMS_edgeName is making problem, so we load it here as well, it should not be
let responseSettings = await promisifyBuilder(dbSettings.find());
temperatureAddress = responseSettings[0]["temperature_adress"];
}
loadSettings();
exports.install = function(instance) {
const { exec } = require('child_process');
const { sendNotification, ERRWEIGHT } = require('./helper/notification_reporter');
let startRead;
let dataToTb;
let counter = 0;
let edgeName = "";
logger.debug(exports.title, "installed");
instance.on("close", function(){
clearInterval(startRead);
})
const start = function() {
try {
if(FLOW.OMS_controller_type === "unipi")
{
clearInterval(startRead);
return;
}
if(temperatureAddress === "") throw "gettemperature: temperatureAddress is not defined";
logger.debug("FLOW.OMS_temperature_adress", FLOW.OMS_temperature_adress);
exec(`owread -C ${temperatureAddress}/temperature`, (error, stdout, stderr) => {
edgeName = FLOW.OMS_edgeName;
if(edgeName !== "")
{
if(error)
{
if(FLOW.OMS_brokerready == undefined)
{
logger.debug("gettemparature - FLOW.OMS_brokerready is undefined");
setTimeout(function(){
start();
}, 3000);
return;
}
if(FLOW.OMS_brokerready)
{
//sendNotification("start", edgeName, ERRWEIGHT.WARNING, "Thermometer is not responding", {"Error": error}, instanceSendTo.tb, instance, "thermometer");
sendNotification("start", edgeName, "thermometer_is_not_responding", {}, {"Error": error}, instanceSendTo.tb, instance, "thermometer");
}
let status = "NOK";
dataToTb = {
[edgeName]: [
{
"ts": Date.now(),
"values": {
"status": status
}
}
]
}
monitor.info("Thermometer is not responding", error, FLOW.OMS_brokerready);
// instance.send(instanceSendTo.tb, dataToTb); // poslat stav nok do tb, ak to handluje dido_controller ??
instance.send(instanceSendTo.dido_controller, {status: "NOK-thermometer"});
}
else parseData(stdout);
}
else
{
monitor.info("gettemperature: edgeName is not defined", FLOW.OMS_edgeName);
setTimeout(function(){
start();
}, 3000);
return;
}
//instance.send({"Temp":stdout,"stderr":stderr,"err":error});
});
}
catch(err) {
errLogger.error(exports.title, err);
}
}
const parseData = function(data) {
data = parseFloat(data);
logger.debug("gettemperature", data);
if(!isNaN(data)) {
if(counter > 290)
{
instance.send(instanceSendTo.debug, "[Get temperature component] - temperature data are comming again from RVO after more than 1 day break");
//sendNotification("parseData", edgeName, ERRWEIGHT.NOTICE, "Thermometer is working again", "", instanceSendTo.tb, instance, "thermometer");
if(FLOW.OMS_brokerready) sendNotification("parseData", edgeName, "thermometer_is_responding_again", {}, "", instanceSendTo.tb, instance, "thermometer");
}
logger.debug("gettemperature", data);
const values = {
"temperature": Number(data.toFixed(2)),
"status": "OK"
}
dataToTb = {
[edgeName]: [
{
"ts": Date.now(),
"values":values
}
]
}
instance.send(instanceSendTo.tb, dataToTb);
instance.send(instanceSendTo.dido_controller, values);
counter = 0;
} else {
counter++;
monitor.info("gettemperature err", counter, data);
//ked je problem 1 den
let day = 24 * 60 / timeoutMin;
if ( counter > day && counter < day + 2 ) {
//sendNotification("parseData", edgeName, ERRWEIGHT.WARNING, "Thermometer receives invalid data", "", instanceSendTo.tb, instance, "thermometer");
sendNotification("parseData", edgeName, "thermometer_sends_invalid_data", {}, "", instanceSendTo.tb, instance, "thermometer");
instance.send(instanceSendTo.debug, "[Get temperature component] - no temperature data from RVO for more than 1 day");
instance.send(instanceSendTo.dido_controller, {status: "NOK-thermometer"});
}
}
}
setTimeout(function(){
start();
}, 3000);
startRead = setInterval(start, timeoutMin * 1000 * 60);
};

View file

@ -1,163 +1,163 @@
class DataToTbHandler
{
constructor(index) {
this.index = index;
this.previousValues = {};
this.debug = false;
this.messageCounter = 0;
this.sender = "";
}
dump()
{
console.log("----------------------------");
console.log("previousValues", this.previousValues);
console.log("----------------------------");
}
setSender(sender)
{
this.sender = sender;
}
isEmptyObject( obj ) {
for ( var name in obj ) {
return false;
}
return true;
}
sendToTb(dataToTb, instance)
{
if(!FLOW.OMS_brokerready)
{
return dataToTb;
}
let keys = Object.keys(dataToTb);
if(keys.length == 0)
{
if(this.debug) console.log("sendToTb received epty object", dataToTb);
return;
}
let tbname = keys[0];
let ts;
let arrayOfValues = dataToTb[tbname];
let arrayOfValuesToSend = [];
for(let i = 0; i < arrayOfValues.length; i++)
{
ts = arrayOfValues[i].ts;
//console.log("sendToTb------------>before", arrayOfValues[i].values, tbname);
let values = this.prepareValuesForTb(tbname, ts, arrayOfValues[i].values);
//console.log("sendToTb------------>after", values);
if(!this.isEmptyObject(values))
{
arrayOfValuesToSend.push({ts: ts, values: values});
}
}
if(arrayOfValuesToSend.length == 0)
{
//if(this.debug) console.log("data not sent - empty array");
return;
}
/*
let dataToTb = {
[tbname]: [
{
"ts": Date.now(),
"values": values
}
]
}
*/
this.messageCounter++;
let dataToTbModified = {
[tbname]: arrayOfValuesToSend
}
//console.log(this.sender + " DATA SEND TO TB ", tbname, this.messageCounter, new Date(ts), dataToTbModified[tbname][0].values, this.instance);
if(this.debug) console.log(this.sender + " DATA SEND TO TB ", this.index, tbname, arrayOfValuesToSend);
instance.send(this.index, dataToTbModified);
}
getDiffTimestamp(key)
{
let seconds = 60*60;//1h
//seconds = 1;//for testing
//TODO set different value for given key!!!
//if(key == "status") seconds = 2*60*60;//2h
let timestampDiffToRemoveKey = seconds*1000;
return timestampDiffToRemoveKey;
}
prepareValuesForTb(tbname, timestamp, values)
{
let keys = Object.keys(values);
if(!this.previousValues.hasOwnProperty(tbname))
{
this.previousValues[tbname] = {};
}
//if(this.debug) console.log("prepareValuesForTb", tbname, timestamp, values);
for(let i = 0; i < keys.length; i++)
{
let key = keys[i];
let value = values[key];
if(!this.previousValues[tbname].hasOwnProperty(key))
{
this.previousValues[tbname][key] = {ts: timestamp, value: value};
continue;
}
if(this.previousValues[tbname][key].value === value)
{
let diff = timestamp - this.previousValues[tbname][key].ts;
let timestampDiffToRemoveKey = this.getDiffTimestamp(key);
if(diff > timestampDiffToRemoveKey)
{
this.previousValues[tbname][key].ts = Date.now();
//if(this.debug) console.log(this.sender + ": update ts for key", key, "diff is", diff, "messageCounter", this.messageCounter);
}
else
{
delete values[key];
//if(this.debug) console.log(this.sender + ": delete key", key, "diff is", diff, "messageCounter", this.messageCounter, timestampDiffToRemoveKey);
}
}
else
{
this.previousValues[tbname][key].value = value;
this.previousValues[tbname][key].ts = timestamp;
}
}
return values;
}
}
class DataToTbHandler
{
constructor(index) {
this.index = index;
this.previousValues = {};
this.debug = false;
this.messageCounter = 0;
this.sender = "";
}
dump()
{
console.log("----------------------------");
console.log("previousValues", this.previousValues);
console.log("----------------------------");
}
setSender(sender)
{
this.sender = sender;
}
isEmptyObject( obj ) {
for ( var name in obj ) {
return false;
}
return true;
}
sendToTb(dataToTb, instance)
{
if(!FLOW.OMS_brokerready)
{
return dataToTb;
}
let keys = Object.keys(dataToTb);
if(keys.length == 0)
{
if(this.debug) console.log("sendToTb received epty object", dataToTb);
return;
}
let tbname = keys[0];
let ts;
let arrayOfValues = dataToTb[tbname];
let arrayOfValuesToSend = [];
for(let i = 0; i < arrayOfValues.length; i++)
{
ts = arrayOfValues[i].ts;
//console.log("sendToTb------------>before", arrayOfValues[i].values, tbname);
let values = this.prepareValuesForTb(tbname, ts, arrayOfValues[i].values);
//console.log("sendToTb------------>after", values);
if(!this.isEmptyObject(values))
{
arrayOfValuesToSend.push({ts: ts, values: values});
}
}
if(arrayOfValuesToSend.length == 0)
{
//if(this.debug) console.log("data not sent - empty array");
return;
}
/*
let dataToTb = {
[tbname]: [
{
"ts": Date.now(),
"values": values
}
]
}
*/
this.messageCounter++;
let dataToTbModified = {
[tbname]: arrayOfValuesToSend
}
//console.log(this.sender + " DATA SEND TO TB ", tbname, this.messageCounter, new Date(ts), dataToTbModified[tbname][0].values, this.instance);
if(this.debug) console.log(this.sender + " DATA SEND TO TB ", this.index, tbname, arrayOfValuesToSend);
instance.send(this.index, dataToTbModified);
}
getDiffTimestamp(key)
{
let seconds = 60*60;//1h
//seconds = 1;//for testing
//TODO set different value for given key!!!
//if(key == "status") seconds = 2*60*60;//2h
let timestampDiffToRemoveKey = seconds*1000;
return timestampDiffToRemoveKey;
}
prepareValuesForTb(tbname, timestamp, values)
{
let keys = Object.keys(values);
if(!this.previousValues.hasOwnProperty(tbname))
{
this.previousValues[tbname] = {};
}
//if(this.debug) console.log("prepareValuesForTb", tbname, timestamp, values);
for(let i = 0; i < keys.length; i++)
{
let key = keys[i];
let value = values[key];
if(!this.previousValues[tbname].hasOwnProperty(key))
{
this.previousValues[tbname][key] = {ts: timestamp, value: value};
continue;
}
if(this.previousValues[tbname][key].value === value)
{
let diff = timestamp - this.previousValues[tbname][key].ts;
let timestampDiffToRemoveKey = this.getDiffTimestamp(key);
if(diff > timestampDiffToRemoveKey)
{
this.previousValues[tbname][key].ts = Date.now();
//if(this.debug) console.log(this.sender + ": update ts for key", key, "diff is", diff, "messageCounter", this.messageCounter);
}
else
{
delete values[key];
//if(this.debug) console.log(this.sender + ": delete key", key, "diff is", diff, "messageCounter", this.messageCounter, timestampDiffToRemoveKey);
}
}
else
{
this.previousValues[tbname][key].value = value;
this.previousValues[tbname][key].ts = timestamp;
}
}
return values;
}
}
module.exports = DataToTbHandler;

View file

@ -3,7 +3,7 @@ exports.title = 'Modbus reader';
exports.version = '2.0.0';
exports.group = 'Worksys';
exports.color = '#2134B0';
exports.output = ["red", "white"];
exports.output = ["red", "white", "yellow"];
exports.click = false;
exports.author = 'Rastislav Kovac';
exports.icon = 'bolt';
@ -14,24 +14,23 @@ exports.readme = `
This device needs to be configured in dido_controller!!! Double check if it is. In dido_controller we calculate final status and all values with status are pushed to tb.
`;
const modbus = require('jsmodbus')
const SerialPort = require('serialport')
const modbus = require('jsmodbus');
const SerialPort = require('serialport');
const { timeoutInterval, deviceConfig } = require("../databases/modbus_config");
const ErrorToServiceHandler = require('./helper/ErrorToServiceHandler');
const errorHandler = new ErrorToServiceHandler();
const { sendNotification } = require('./helper/notification_reporter');
const instanceSendTo = {
const DELAY_BETWEEN_DEVICES = 10000;
const SEND_TO = {
debug: 0,
dido_controller: 1,
tb: 2
};
//to handle NOK and OK sendNotifications s
const numberOfNotResponding = {};
let tbName = null;
let mainSocket;
exports.install = function(instance) {
@ -47,12 +46,16 @@ exports.install = function(instance) {
this.index = 0;
this.timeoutInterval = 5000;
// kedze potrebujeme ist stale dookola pre jednotlive zariadenia, potrebujeme ci uz index ako aj adresu zariadenia, a aj pocet registrov na vycitanie
this.deviceAddress = null; // adresa zariadenia (1 ma EM340 a 2 ma twilight_sensor)
this.indexInDeviceConfig = 0; // prvy item v deviceConfig
// we need to go always around for all devices. So we need index value, device address, as well as number of registers for single device
this.deviceAddress = null; // device address (1 - EM340 and 2 for twilight_sensor)
this.indexInDeviceConfig = 0; // first item in deviceConfig
this.lengthOfActualDeviceStream = null;
this.device = null;
// lampSwitchNotification helper variables
this.onNotificationSent = false;
this.offNotificationSent = false;
this.startSocket();
}
@ -67,7 +70,7 @@ exports.install = function(instance) {
// we create a client for every deviceAddress ( = address) in list and push them into dictionary
for( let i = 0; i < deviceConfig.length; i++)
{
this.clients[deviceConfig[i].deviceAddress] = new modbus.client.RTU(this.socket, deviceConfig[i].deviceAddress);
this.clients[deviceConfig[i].deviceAddress] = new modbus.client.RTU(this.socket, deviceConfig[i].deviceAddress, 2000); // 2000 is timeout in register request, default is 5000, which is too long
}
this.socket.on('error', function(e) {
@ -86,7 +89,7 @@ exports.install = function(instance) {
this.socket.on('open', function () {
console.log("socket connected");
obj.getActualStreamAndDevice();
obj.timeoutInterval = timeoutInterval;
obj.timeoutInterval = timeoutInterval - DELAY_BETWEEN_DEVICES; // to make sure readout always runs in timeoutinterval we substract DELAY_BETWEEN_DEVICES
})
};
@ -101,7 +104,7 @@ exports.install = function(instance) {
this.device = dev.device; //em340, twilight_sensor
if(this.indexInDeviceConfig == 0) setTimeout(this.readRegisters, this.timeoutInterval);
else setTimeout(this.readRegisters, 2000);
else setTimeout(this.readRegisters, DELAY_BETWEEN_DEVICES);
}
readRegisters = () => {
@ -131,26 +134,24 @@ exports.install = function(instance) {
{
message = "twilight_sensor_ok";
}
message && sendNotification("modbus_reader: readRegisters", tbName, message, {}, "", instanceSendTo.tb, instance);
message && sendNotification("modbus_reader: readRegisters", tbName, message, {}, "", SEND_TO.tb, instance);
delete numberOfNotResponding[obj.device];
}
obj.transformResponse(resp, register, obj.deviceAddress);
obj.transformResponse(resp, register);
obj.error = 0;
//obj.errors = 0;
obj.index++;
if(obj.index < obj.lengthOfActualDeviceStream) setTimeout(obj.readRegisters, 0);
else obj.setNewStream();
obj.readAnotherRegister();
}).catch (function () {
console.log("error pri citani modbus registra", register, obj.indexInDeviceConfig, tbName, tbAttribute);
console.log("errors pri citani modbus registra", register, obj.indexInDeviceConfig, tbName, tbAttribute);
obj.error++;
if(obj.error == obj.lengthOfActualDeviceStream)
obj.errors++;
if(obj.errors == obj.lengthOfActualDeviceStream)
{
instance.send(instanceSendTo.dido_controller, {status: "NOK-" + obj.device}); // NOK-em340, NOK-em111, NOK-twilight_sensor, NOK-thermometer
instance.send(SEND_TO.dido_controller, {status: "NOK-" + obj.device}); // NOK-em340, NOK-em111, NOK-twilight_sensor, NOK-thermometer
//todo - neposlalo notification, ked sme vypojili twilight a neposle to do tb, ale do dido ??
if(!numberOfNotResponding.hasOwnProperty(obj.device))
@ -164,11 +165,11 @@ exports.install = function(instance) {
{
message = "electrometer_nok";
}
message && sendNotification("modbus_reader: readingTimeouted", tbName, message, {}, "", instanceSendTo.tb, instance);
message && sendNotification("modbus_reader: readingTimeouted", tbName, message, {}, "", SEND_TO.tb, instance);
numberOfNotResponding[obj.device] = 1;
}
obj.error = 0;
obj.errors = 0;
numberOfNotResponding[obj.device] += 1;
}
@ -176,14 +177,24 @@ exports.install = function(instance) {
depth: null
}))
// if reading out of device's last register returns error, we send accumulated allValues to dido_controller (if allValues are not an empty object)
if(obj.index + 1 >= obj.lengthOfActualDeviceStream)
{
if(!isObjectEmpty(obj.allValues)) instance.send(SEND_TO.dido_controller, {values: obj.allValues});
obj.allValues = {};
}
obj.index++;
if(obj.index < obj.lengthOfActualDeviceStream) setTimeout(obj.readRegisters, 0);
else obj.setNewStream();
obj.readAnotherRegister();
})
};
transformResponse = (response, register, deviceAddress) => {
readAnotherRegister = () => {
if(this.index < this.lengthOfActualDeviceStream) setTimeout(this.readRegisters, 0);
else this.setNewStream();
}
transformResponse = (response, register) => {
for (let i = 0; i < this.lengthOfActualDeviceStream; i++) {
@ -194,11 +205,11 @@ exports.install = function(instance) {
let multiplier = a.multiplier;
let value = this.calculateValue(response, multiplier);
// console.log(deviceAddress, register, tbName, tbAttribute, response, a.multiplier, value);
// console.log(register, tbName, tbAttribute, response, a.multiplier, value);
// if(tbName == undefined) return;
if(this.index + 1 + this.errors < this.lengthOfActualDeviceStream)
if(this.index + 1 < this.lengthOfActualDeviceStream)
{
this.allValues[tbAttribute] = value;
return;
@ -210,8 +221,9 @@ exports.install = function(instance) {
};
this.checkNullVoltage(values);
this.lampSwitchNotification(values);
instance.send(instanceSendTo.dido_controller, {values: values});
instance.send(SEND_TO.dido_controller, {values: values});
this.allValues = {};
break;
@ -223,8 +235,6 @@ exports.install = function(instance) {
setNewStream = () =>
{
// console.log('------------',this.lengthOfActualDeviceStream, this.index);
// console.log('------------',this.indexInDeviceConfig, deviceConfig.length);
if(this.lengthOfActualDeviceStream == this.index)
{
if(this.indexInDeviceConfig + 1 == deviceConfig.length)
@ -240,32 +250,6 @@ exports.install = function(instance) {
}
}
// sendFinalObjects = (values) =>
// {
// const date = Date.now();
// // values["status"] = "OK";
// const dataToTB = {
// [tbName]: [
// {
// "ts": date,
// "values": values
// }
// ]
// };
// instance.send(instanceSendTo.tb, dataToTB);
// const dataToDiDo = {
// values: values
// }
// instance.send(instanceSendTo.dido_controller, dataToDiDo);
// }
calculateValue = (response, multiplier) =>
{
let value = 0;
@ -293,7 +277,6 @@ exports.install = function(instance) {
return Math.round(value * multiplier * 10) / 10;
}
checkNullVoltage = (values) => {
if(!(values.hasOwnProperty("Phase_1_voltage") || values.hasOwnProperty("Phase_2_voltage") || values.hasOwnProperty("Phase_3_voltage"))) return;
@ -310,27 +293,56 @@ exports.install = function(instance) {
if(values[singleValue] == 0)
{
FLOW.OMS_no_voltage.add(phase);
sendNotification("modbus_citys: checkNullVoltage", tbName, "no_voltage_on_phase", {phase: phase}, "", instanceSendTo.tb, instance, "voltage" + phase );
sendNotification("modbus_reader: checkNullVoltage", tbName, "no_voltage_on_phase", {phase: phase}, "", SEND_TO.tb, instance, "voltage" + phase );
// console.log('no voltage')
}
else
{
FLOW.OMS_no_voltage.delete(phase);
// console.log('voltage detected')
sendNotification("modbus_citys: checkNullVoltage", tbName, "voltage_on_phase_restored", {phase: phase}, "", instanceSendTo.tb, instance, "voltage" + phase);
sendNotification("modbus_reader: checkNullVoltage", tbName, "voltage_on_phase_restored", {phase: phase}, "", SEND_TO.tb, instance, "voltage" + phase);
}
}
})
}
// we use dataToTbHandler. Therefore we need to check, if objects we send to dido_controller are not empty
isObjectEmpty = (objectName) => {
return Object.keys(objectName).length === 0 && objectName.constructor === Object;
/**
* function sends notification to slack and to tb, if EM total_power value changes more than 500. This should show, that RVO lamps has been switched on or off
*/
lampSwitchNotification = (values) => {
if(!values.hasOwnProperty("total_power")) return;
const actualTotalPower = values.total_power;
if(actualTotalPower > 600 && this.onNotificationSent == false)
{
sendNotification("modbus_reader: lampSwitchNotification", tbName, "lamps_have_turned_on", {}, "", SEND_TO.tb, instance);
this.onNotificationSent = true;
this.offNotificationSent = false;
}
else if(actualTotalPower <= 600 && this.offNotificationSent == false)
{
sendNotification("modbus_reader: lampSwitchNotification", tbName, "lamps_have_turned_off", {}, "", SEND_TO.tb, instance);
this.onNotificationSent = false;
this.offNotificationSent = true;
}
}
}
const isObjectEmpty = (objectName) => {
return Object.keys(objectName).length === 0 && objectName.constructor === Object;
}
setTimeout(() => {
const newSocket = new SocketWithClients();
mainSocket = new SocketWithClients();
tbName = FLOW.OMS_rvo_tbname;
// this notification is to show, that flow (unipi) has been restarted
sendNotification("modbus_reader", tbName, "flow_restart", {}, "", SEND_TO.slack, instance);
}, 25000);
}

124
flow/slack_connector.js Normal file
View file

@ -0,0 +1,124 @@
exports.id = 'slack_connector';
exports.title = 'Slack_Connector';
exports.version = '1.0.0';
exports.group = 'Worksys';
exports.color = '#888600';
exports.input = 1;
exports.output = 1;
exports.click = false;
exports.author = 'Jakub Klena';
exports.icon = 'sign-out';
exports.options = { slack_channel: "C071KN2Q8SK", api_key: "", bot_name: "Flow DEMO", bot_icon: ":totaljs:" };
// Slack channel - where to post the messages, can be name like "backend-alerts"
// Bot Name - Name of the "user" that will post these messages, it should be based on which server it is running on.
// Bot Icon - We can use any slack icon (even custom ones uploaded by us) as the "user" profile picture
exports.html = `<div class="padding">
<div class="row">
<div class="col-md-6">
<div data-jc="textbox" data-jc-path="slack_channel" data-jc-config="placeholder:name or id;required:true" class="m">Slack Channel</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div data-jc="textbox" data-jc-path="api_key" data-jc-config="placeholder:api key;required:true" class="m">API Key:</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div data-jc="textbox" data-jc-path="bot_name" data-jc-config="placeholder:Flow DEMO;required:false" class="m">Bot Name</div>
</div>
<div class="col-md-6">
<div data-jc="textbox" data-jc-path="bot_icon" data-jc-config="placeholder:\:totaljs\:;required:true" class="m">Bot Icon</div>
</div>
</div>
</div>`;
exports.readme = `Sends any string received on input to Slack Channel.`;
var log4js = require("log4js");
var path = require('path');
log4js.configure({
appenders: {
errLogs: { type: 'file', compress:true, daysToKeep: 2, maxLogSize: 1048576, backups: 1, keepFileExt: true, filename: path.join(__dirname + "/../", 'err.txt') },
monitorLogs: { type: 'file', compress:true, daysToKeep: 2, maxLogSize: 1048576, backups: 1, keepFileExt: true, filename: path.join(__dirname + "/../", 'monitor.txt') },
console: { type: 'console' }
},
categories: {
errLogs: { appenders: ['console', 'errLogs'], level: 'error' },
monitorLogs: { appenders: ['console', 'monitorLogs'], level: 'trace' },
//another: { appenders: ['console'], level: 'trace' },
default: { appenders: ['console'], level: 'trace' }
}
});
const errLogger = log4js.getLogger("errLogs");
const logger = log4js.getLogger();
const monitor = log4js.getLogger("monitorLogs");
exports.install = function(instance) {
var can = false;
process.on('uncaughtException', function (err) {
errLogger.error('uncaughtException:', err.message);
errLogger.error(err.stack);
instance.error(err);
});
instance.on('data', function(data) {
if (!can) return;
let str = String(data.data); // Ensuring data get converted to string
let message = {
'channel': instance.options.slack_channel,
'username': instance.options.bot_name,
'icon_emoji': instance.options.bot_icon,
'text': str
};
let headers = {
'Content-type': `application/json`,
'Authorization': `Bearer ${instance.options.api_key}`
};
if (F.is4) {
let opt = {
'method': 'post',
'url': 'https://slack.com/api/chat.postMessage',
'headers': headers,
'body': JSON.stringify(message),
'type': 'json',
'callback': function(err, response) {
if (response && !err) {
var msg = { data: response.body, status: response.status, headers: response.headers, host: response.host, cookies: response.cookies };
instance.send2(msg);
} else if (err) {
errLogger.error('Slack post failed - err:', err, '\n - response was:', response);
instance.error(err, response);
}
}
};
REQUEST(opt);
} else {
U.request('https://slack.com/api/chat.postMessage', ['json', 'post'], JSON.stringify(message), function(err, data, status, headers, host) {
if (response && !err) {
response.data = { data: data, status: status, headers: headers, host: host };
instance.send2(response);
} else if (err) {
errLogger.error('Slack post failed - err:', err, '\n - response was:', response);
instance.error(err, response);
}
}, null, headers);
}
});
instance.reconfigure = function() {
var options = instance.options;
can = options.slack_channel && options.bot_name && options.bot_icon && options.api_key ? true : false;
instance.status(can ? '' : 'Not configured', can ? undefined : 'red');
};
instance.on('options', instance.reconfigure);
instance.reconfigure();
}

187
flow/slack_filter.js Normal file
View file

@ -0,0 +1,187 @@
exports.id = 'slack_filter';
exports.title = 'Slack Filter';
exports.group = 'Citysys';
exports.color = '#30E193';
exports.input = 1;
exports.output = 1;
exports.author = 'Jakub Klena';
exports.icon = 'plug';
exports.version = '1.0.8';
exports.options = { 'name':'', 'types': '["emergency", "critical", "error", "alert"]', 'message_includes':'["is responding again"]', 'tag_on_include':'[{"user_id":"U072JE5JUQG", "includes":["Electrometer", "Twilight sensor"]}]', 'slack_channel':'' };
exports.html = `<div class="padding">
<div class="row">
<div class="col-md-12">
<div data-jc="textbox" data-jc-path="name" data-jc-config="required:true">@(Name of this server)</div>
</div>
<div class="col-md-12">
<div data-jc="textbox" data-jc-path="slack_channel" data-jc-config="required:false">@(Slack channel to receive the alerts)</div>
</div>
<div class="col-md-12">
<div data-jc="textbox" data-jc-path="types" data-jc-config="required:false">@(Watch these types, comma separated names)</div>
</div>
<div class="col-md-12">
<div data-jc="textbox" data-jc-path="message_includes" data-jc-config="required:false">@(Watch messages that include any of the following strings)</div>
</div>
<div class="col-md-12">
<div data-jc="textbox" data-jc-path="tag_on_include" data-jc-config="required:false">@(Tag people if message includes something)</div>
</div>
</div>
</div>`;
exports.readme = `# Slack Filter`;
exports.install = function(instance) {
var running = false;
instance["savedSlackMessages"] = [];
var timer = null;
instance.on('data', function(response) {
if (!running) return;
let value = response.data;
if (typeof value !== 'object') return;
let can = false
var k = Object.keys(value);
var interested = JSON.parse(instance.options.types);
var msg_incl = JSON.parse(instance.options.message_includes);
var tags = JSON.parse(instance.options.tag_on_include);
if (k.length <= 0) return;
if (value[k[0]].length <= 0) return;
if (!Object.prototype.hasOwnProperty.call(value[k[0]][0], 'values')) return;
if (!Object.prototype.hasOwnProperty.call(value[k[0]][0]['values'], '_event')) return;
if (!Object.prototype.hasOwnProperty.call(value[k[0]][0]['values']['_event'], 'type')) return;
if (!Object.prototype.hasOwnProperty.call(value[k[0]][0]['values']['_event'], 'source')) return;
if (!Object.prototype.hasOwnProperty.call(value[k[0]][0]['values']['_event']['source'], 'func')) return;
if (!Object.prototype.hasOwnProperty.call(value[k[0]][0]['values']['_event'], 'message')) return;
if (!Object.prototype.hasOwnProperty.call(value[k[0]][0]['values']['_event'], 'message_data')) return;
let icon = ':totaljs:';
let type = value[k[0]][0]['values']['_event']['type'];
let source = value[k[0]][0]['values']['_event']['source']['func'];
let message = value[k[0]][0]['values']['_event']['message'];
let message_data = value[k[0]][0]['values']['_event']['message_data'];
let tag = '';
switch(type){
case 'debug':
icon = ':beetle:';
break;
case 'info':
icon = ':speech_balloon:';
break;
case 'notice':
icon = ':speech_balloon:';
break;
case 'warning':
icon = ':exclamation:';
break;
case 'alert':
icon = ':warning:';
break;
case 'error':
icon = ':no_entry:';
break;
case 'emergency':
icon = ':fire:';
break;
case 'critical':
icon = ':fire:';
break;
}
// Check if this message includes one of the strings we are watching for
for (const msg of msg_incl){
if (message.includes(msg)){
if (msg == 'is responding again') icon = ':large_green_circle:';
can = true;
break;
}
}
// Check if message is one of the types we are watching for
if (interested.includes(type)){
can = true;
}
if (!can) return;
// Check for each person tags based on what the message includes
for (const person of tags){
for (const msg of person.includes){
if (message.includes(msg)){
tag += '<@'+person.user_id+'> ';
break; // Break out from this person checks as they are already tagged now
}
}
}
// Now that all people are tagged add new line symbol
if (tag != '') tag += '\n';
let send_data = tag+instance.options.name+' '+type.toUpperCase()+'\n*Source*: '+source+'\n*Message*: '+message;
if (message_data) {
send_data += '\nData: '+message_data;
}
let ignore_msg = false
if (message.includes('Configuration of dimming profile to node no')){
for (let i = 0; i < FLOW["savedSlackMessages"].length; i++){
if (FLOW["savedSlackMessages"][i].message == message){
ignore_msg = true;
break;
}
}
if (!ignore_msg){
FLOW["savedSlackMessages"].push({message, 'dateandtime': Date.now()});
if (timer === null){
timer = setTimeout(checkSavedMessages, 60*60000);
}
}
}
if (!ignore_msg){
instance.send2({'msg':send_data,'bot_name':instance.options.name+' '+type.toUpperCase(),'bot_icon':icon,'channel':instance.options.slack_channel});
}
});
function checkSavedMessages(){
var d = Date.now();
d = d - 86400000; // older then 24hr
var a = [];
//Remove msgs older then 24hr
for (let i = 0; i < FLOW["savedSlackMessages"].length; i++){
if (FLOW["savedSlackMessages"][i].dateandtime > d){
a.push(FLOW["savedSlackMessages"][i]);
}
}
FLOW["savedSlackMessages"] = a;
if (FLOW["savedSlackMessages"].length > 0) {
timer = setTimeout(checkSavedMessages, 60*60000);
} else {
timer = null;
}
}
instance.reconfigure = function() {
try {
if (!FLOW["savedSlackMessages"]){
FLOW["savedSlackMessages"] = [];
}
if (instance.options.name) {
instance.status('Running');
running = true;
} else {
instance.status('Please enter name', 'red');
running = false;
}
} catch (e) {
instance.error('Citysys connector: ' + e.message);
}
};
instance.on('options', instance.reconfigure);
instance.reconfigure();
};