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 = [ const deviceConfig = [
{ {
device: "em340", device: "em340",

View file

@ -32,3 +32,6 @@ key:string|weight:string|sk:string|en:string
+|flow_start|NOTICE|FLOW bol spustený|FLOW has been started |............... +|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_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": [ "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", "id": "1611951142547",
"component": "debug", "component": "debug",
"tab": "1611921777196", "tab": "1611921777196",
"name": "ERROR", "name": "ERROR",
"x": 404, "x": 401,
"y": 29, "y": 31,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -68,35 +44,13 @@
"color": "#DA4453", "color": "#DA4453",
"notes": "" "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", "id": "1612776786008",
"component": "wsmqttpublish", "component": "wsmqttpublish",
"tab": "1612772287426", "tab": "1612772287426",
"name": "WS MQTT publish", "name": "WS MQTT publish",
"x": 311.75, "x": 311.75,
"y": 268, "y": 248,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -148,7 +102,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "tb-push", "name": "tb-push",
"x": 68.75, "x": 68.75,
"y": 289, "y": 269,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -181,7 +135,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "to TB", "name": "to TB",
"x": 317.75, "x": 317.75,
"y": 174, "y": 154,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -201,33 +155,13 @@
"color": "#967ADC", "color": "#967ADC",
"notes": "" "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", "id": "1615551060773",
"component": "debug", "component": "debug",
"tab": "1612772287426", "tab": "1612772287426",
"name": "errors from MQTT Broker", "name": "errors from MQTT Broker",
"x": 610, "x": 610,
"y": 131, "y": 111,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -252,8 +186,8 @@
"component": "debug", "component": "debug",
"tab": "1615551125555", "tab": "1615551125555",
"name": "Debug", "name": "Debug",
"x": 763, "x": 755,
"y": 123, "y": 19,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -278,8 +212,8 @@
"component": "virtualwireout", "component": "virtualwireout",
"tab": "1615551125555", "tab": "1615551125555",
"name": "tb-push", "name": "tb-push",
"x": 761, "x": 753,
"y": 216, "y": 112,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -300,8 +234,8 @@
"component": "debug", "component": "debug",
"tab": "1615551125555", "tab": "1615551125555",
"name": "CMD_debug", "name": "CMD_debug",
"x": 758, "x": 750,
"y": 301, "y": 197,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -327,7 +261,7 @@
"tab": "1611921777196", "tab": "1611921777196",
"name": "Debug", "name": "Debug",
"x": 398.8833312988281, "x": 398.8833312988281,
"y": 477.3500061035156, "y": 528.3500061035156,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -336,13 +270,13 @@
"output": [] "output": []
}, },
"state": { "state": {
"text": "Enabled", "text": "Disabled",
"color": "gray" "color": "gray"
}, },
"options": { "options": {
"type": "data", "type": "data",
"repository": false, "repository": false,
"enabled": true "enabled": false
}, },
"color": "#967ADC", "color": "#967ADC",
"notes": "" "notes": ""
@ -352,8 +286,8 @@
"component": "debug", "component": "debug",
"tab": "1611921777196", "tab": "1611921777196",
"name": "Debug", "name": "Debug",
"x": 406.8833312988281, "x": 401.8833312988281,
"y": 567.3500061035156, "y": 625.3500061035156,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -378,8 +312,8 @@
"component": "virtualwireout", "component": "virtualwireout",
"tab": "1611921777196", "tab": "1611921777196",
"name": "tb-push", "name": "tb-push",
"x": 404.8833312988281, "x": 400.8833312988281,
"y": 653.25, "y": 328.25,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -400,8 +334,8 @@
"component": "httproute", "component": "httproute",
"tab": "1615551125555", "tab": "1615551125555",
"name": "POST /terminal", "name": "POST /terminal",
"x": 110, "x": 72,
"y": 508, "y": 350,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -446,8 +380,8 @@
"component": "httpresponse", "component": "httpresponse",
"tab": "1615551125555", "tab": "1615551125555",
"name": "HTTP Response", "name": "HTTP Response",
"x": 759, "x": 751,
"y": 377, "y": 273,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -468,8 +402,8 @@
"component": "debug", "component": "debug",
"tab": "1615551125555", "tab": "1615551125555",
"name": "DIDO_Debug", "name": "DIDO_Debug",
"x": 743, "x": 739,
"y": 839, "y": 635,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -494,8 +428,8 @@
"component": "trigger", "component": "trigger",
"tab": "1615551125555", "tab": "1615551125555",
"name": "turnOff line", "name": "turnOff line",
"x": 75, "x": 71,
"y": 1033, "y": 829,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -524,8 +458,8 @@
"component": "virtualwireout", "component": "virtualwireout",
"tab": "1615551125555", "tab": "1615551125555",
"name": "tb-push", "name": "tb-push",
"x": 751, "x": 741,
"y": 940, "y": 736,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -546,8 +480,8 @@
"component": "debug", "component": "debug",
"tab": "1615551125555", "tab": "1615551125555",
"name": "Debug", "name": "Debug",
"x": 628, "x": 605,
"y": 1246, "y": 1024,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -570,8 +504,8 @@
"component": "trigger", "component": "trigger",
"tab": "1615551125555", "tab": "1615551125555",
"name": "start import", "name": "start import",
"x": 258, "x": 235,
"y": 1254, "y": 1032,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -600,8 +534,8 @@
"component": "csv_import", "component": "csv_import",
"tab": "1615551125555", "tab": "1615551125555",
"name": "CsvImport", "name": "CsvImport",
"x": 437, "x": 414,
"y": 1235, "y": 1013,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -629,8 +563,8 @@
"component": "comment", "component": "comment",
"tab": "1615551125555", "tab": "1615551125555",
"name": "import data from csv", "name": "import data from csv",
"x": 424, "x": 401,
"y": 1168, "y": 946,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -649,8 +583,8 @@
"component": "trigger", "component": "trigger",
"tab": "1615551125555", "tab": "1615551125555",
"name": "update profile / node", "name": "update profile / node",
"x": 119, "x": 80,
"y": 130, "y": 13,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -678,9 +612,9 @@
"id": "1618235171399", "id": "1618235171399",
"component": "trigger", "component": "trigger",
"tab": "1615551125555", "tab": "1615551125555",
"name": "run tasks", "name": "tun tasks",
"x": 122, "x": 77,
"y": 206, "y": 84,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -709,7 +643,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "wsmqtt-exit1", "name": "wsmqtt-exit1",
"x": 610.8833312988281, "x": 610.8833312988281,
"y": 219, "y": 199,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -733,7 +667,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "wsmqtt-exit2", "name": "wsmqtt-exit2",
"x": 611.8833312988281, "x": 611.8833312988281,
"y": 394, "y": 374,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -758,8 +692,8 @@
"component": "virtualwireout", "component": "virtualwireout",
"tab": "1615551125555", "tab": "1615551125555",
"name": "to-cmd-manager", "name": "to-cmd-manager",
"x": 744.8833312988281, "x": 740.8833312988281,
"y": 1032, "y": 828,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -780,8 +714,8 @@
"component": "virtualwirein", "component": "virtualwirein",
"tab": "1615551125555", "tab": "1615551125555",
"name": "platform-rpc-call", "name": "platform-rpc-call",
"x": 115.88333129882812, "x": 77.88333129882812,
"y": 316, "y": 173,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -809,8 +743,8 @@
"component": "virtualwirein", "component": "virtualwirein",
"tab": "1615551125555", "tab": "1615551125555",
"name": "cmd_to_dido", "name": "cmd_to_dido",
"x": 78.88333129882812, "x": 76.88333129882812,
"y": 864, "y": 678,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -842,8 +776,8 @@
"component": "virtualwireout", "component": "virtualwireout",
"tab": "1615551125555", "tab": "1615551125555",
"name": "cmd_to_dido", "name": "cmd_to_dido",
"x": 756.8833312988281, "x": 748.8833312988281,
"y": 477, "y": 373,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -865,7 +799,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "platform-rpc-call", "name": "platform-rpc-call",
"x": 611.8833312988281, "x": 611.8833312988281,
"y": 307, "y": 287,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -886,8 +820,8 @@
"component": "trigger", "component": "trigger",
"tab": "1615551125555", "tab": "1615551125555",
"name": "turnOn line", "name": "turnOn line",
"x": 76, "x": 72,
"y": 947, "y": 756,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -916,8 +850,8 @@
"component": "cmd_manager", "component": "cmd_manager",
"tab": "1615551125555", "tab": "1615551125555",
"name": "CMD Manager", "name": "CMD Manager",
"x": 442, "x": 420,
"y": 290, "y": 156,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -971,8 +905,8 @@
"component": "httproute", "component": "httproute",
"tab": "1615551125555", "tab": "1615551125555",
"name": "GET db", "name": "GET db",
"x": 104, "x": 73,
"y": 619, "y": 455,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1016,8 +950,8 @@
"component": "trigger", "component": "trigger",
"tab": "1615551125555", "tab": "1615551125555",
"name": "turnOnAlarm", "name": "turnOnAlarm",
"x": 72, "x": 68,
"y": 1106, "y": 902,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1046,8 +980,8 @@
"component": "trigger", "component": "trigger",
"tab": "1615551125555", "tab": "1615551125555",
"name": "turnOffAlarm", "name": "turnOffAlarm",
"x": 71, "x": 67,
"y": 1179, "y": 975,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1076,8 +1010,8 @@
"component": "virtualwireout", "component": "virtualwireout",
"tab": "1611921777196", "tab": "1611921777196",
"name": "modbus_to_dido", "name": "modbus_to_dido",
"x": 396, "x": 399,
"y": 390, "y": 433,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -1188,7 +1122,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "RAM", "name": "RAM",
"x": 71.88333129882812, "x": 71.88333129882812,
"y": 629.5, "y": 609.5,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1202,7 +1136,7 @@
"output": [] "output": []
}, },
"state": { "state": {
"text": "826.22 MB / 985.68 MB", "text": "834.19 MB / 985.68 MB",
"color": "gray" "color": "gray"
}, },
"options": { "options": {
@ -1218,7 +1152,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "disk", "name": "disk",
"x": 72.88333129882812, "x": 72.88333129882812,
"y": 726.5, "y": 706.5,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1232,7 +1166,7 @@
"output": [] "output": []
}, },
"state": { "state": {
"text": "5.85 GB / 7.26 GB", "text": "5.84 GB / 7.26 GB",
"color": "gray" "color": "gray"
}, },
"options": { "options": {
@ -1249,7 +1183,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "send-to-services", "name": "send-to-services",
"x": 5.883331298828125, "x": 5.883331298828125,
"y": 1089.5, "y": 1069.5,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1282,7 +1216,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "send-to-services", "name": "send-to-services",
"x": 428.8833312988281, "x": 428.8833312988281,
"y": 622.5, "y": 602.5,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -1304,7 +1238,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "send-to-services", "name": "send-to-services",
"x": 612.8833312988281, "x": 612.8833312988281,
"y": 482.5, "y": 462.5,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -1327,7 +1261,7 @@
"name": "http://192.168.252.2:8004/sentmessage", "name": "http://192.168.252.2:8004/sentmessage",
"reference": "", "reference": "",
"x": 439.8833312988281, "x": 439.8833312988281,
"y": 1096.7333374023438, "y": 1076.7333374023438,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1358,7 +1292,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "Debug", "name": "Debug",
"x": 234.75, "x": 234.75,
"y": 1044, "y": 1024,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -1384,7 +1318,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "Code", "name": "Code",
"x": 255, "x": 255,
"y": 532, "y": 512,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1419,7 +1353,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "Debug", "name": "Debug",
"x": 430, "x": 430,
"y": 528, "y": 508,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -1445,7 +1379,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "Code", "name": "Code",
"x": 244, "x": 244,
"y": 628, "y": 608,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1480,7 +1414,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "Debug", "name": "Debug",
"x": 431, "x": 431,
"y": 720, "y": 700,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -1506,7 +1440,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "Code", "name": "Code",
"x": 247, "x": 247,
"y": 722, "y": 702,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1541,7 +1475,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "Debug", "name": "Debug",
"x": 434, "x": 434,
"y": 812, "y": 792,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -1567,7 +1501,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "Send info", "name": "Send info",
"x": 438, "x": 438,
"y": 1205, "y": 1185,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -1593,7 +1527,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "Info sender", "name": "Info sender",
"x": 233, "x": 233,
"y": 1142, "y": 1122,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1626,7 +1560,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "Debug", "name": "Debug",
"x": 811.8833312988281, "x": 811.8833312988281,
"y": 1090.5, "y": 1070.5,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -1651,8 +1585,8 @@
"component": "virtualwireout", "component": "virtualwireout",
"tab": "1615551125555", "tab": "1615551125555",
"name": "send-to-services", "name": "send-to-services",
"x": 756, "x": 748,
"y": 568, "y": 464,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -1674,7 +1608,7 @@
"tab": "1612772287426", "tab": "1612772287426",
"name": "CPU", "name": "CPU",
"x": 71, "x": 71,
"y": 535, "y": 515,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1688,7 +1622,7 @@
"output": [] "output": []
}, },
"state": { "state": {
"text": "0.9% / 86.46 MB", "text": "1.9% / 86.94 MB",
"color": "gray" "color": "gray"
}, },
"options": { "options": {
@ -1707,8 +1641,8 @@
"component": "debug", "component": "debug",
"tab": "1615551125555", "tab": "1615551125555",
"name": "CMDtoDIDO", "name": "CMDtoDIDO",
"x": 417, "x": 413,
"y": 858, "y": 654,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -1733,8 +1667,8 @@
"component": "virtualwirein", "component": "virtualwirein",
"tab": "1615551125555", "tab": "1615551125555",
"name": "from-dido-controller", "name": "from-dido-controller",
"x": 113, "x": 71,
"y": 423, "y": 260,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1766,8 +1700,8 @@
"component": "debug", "component": "debug",
"tab": "1615551125555", "tab": "1615551125555",
"name": "from dido to cmd", "name": "from dido to cmd",
"x": 441, "x": 423,
"y": 461, "y": 331,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -1792,8 +1726,8 @@
"component": "debug", "component": "debug",
"tab": "1615551125555", "tab": "1615551125555",
"name": "HTTP routes", "name": "HTTP routes",
"x": 441, "x": 423,
"y": 564, "y": 422,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -1818,8 +1752,8 @@
"component": "debug", "component": "debug",
"tab": "1611921777196", "tab": "1611921777196",
"name": "MDBToDido", "name": "MDBToDido",
"x": 402, "x": 401,
"y": 300, "y": 118,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [], "input": [],
@ -1842,8 +1776,8 @@
"component": "dido_controller", "component": "dido_controller",
"tab": "1615551125555", "tab": "1615551125555",
"name": "DIDO_Controller", "name": "DIDO_Controller",
"x": 406, "x": 402,
"y": 940, "y": 736,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1887,8 +1821,8 @@
"component": "virtualwirein", "component": "virtualwirein",
"tab": "1615551125555", "tab": "1615551125555",
"name": "modbus_to_dido", "name": "modbus_to_dido",
"x": 83, "x": 79,
"y": 775, "y": 595,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -1920,8 +1854,8 @@
"component": "debug", "component": "debug",
"tab": "1615551125555", "tab": "1615551125555",
"name": "modbusToDido", "name": "modbusToDido",
"x": 415, "x": 411,
"y": 765, "y": 561,
"connections": {}, "connections": {},
"disabledio": { "disabledio": {
"input": [ "input": [
@ -1963,16 +1897,20 @@
{ {
"index": "0", "index": "0",
"id": "1684179110403" "id": "1684179110403"
},
{
"index": "0",
"id": "1717441414646"
} }
], ],
"2": [ "2": [
{ {
"index": "0", "index": "0",
"id": "1621340721628" "id": "1615809595184"
}, },
{ {
"index": "0", "index": "0",
"id": "1684179110403" "id": "1714752862828"
} }
] ]
}, },
@ -1993,8 +1931,8 @@
"component": "thermometer", "component": "thermometer",
"tab": "1611921777196", "tab": "1611921777196",
"name": "Thermometer", "name": "Thermometer",
"x": 94.75, "x": 107.75,
"y": 414, "y": 449,
"connections": { "connections": {
"0": [ "0": [
{ {
@ -2030,6 +1968,264 @@
"options": {}, "options": {},
"color": "#5CB36D", "color": "#5CB36D",
"notes": "" "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 "version": 615

View file

@ -60,7 +60,7 @@ state_of_contactor - podľa indexu stykača sa reportuje jeho stav, teda
//globals //globals
//FIRMWARE version //FIRMWARE version
FLOW.OMS_edge_fw_version = "2023-10-18";//rok-mesiac-den FLOW.OMS_edge_fw_version = "2024-07-08";//rok-mesiac-den
FLOW.OMS_edgeName = ""; FLOW.OMS_edgeName = "";
FLOW.OMS_maintenance_mode = false; FLOW.OMS_maintenance_mode = false;
@ -78,7 +78,7 @@ FLOW.OMS_temperature_adress = "";//cmd_manager
let alarmStatus = "OFF"; let alarmStatus = "OFF";
const instanceSendTo = { const SEND_TO = {
debug: 0, debug: 0,
tb: 1, tb: 1,
cmd_manager: 2 cmd_manager: 2
@ -192,7 +192,7 @@ exports.install = function(instance) {
/* /*
dbRelays.on('change', function(doc, old) { dbRelays.on('change', function(doc, old) {
console.log("'DI_DO_Controller - dbRelays.on('change'"); console.log("'DI_DO_Controller - dbRelays.on('change'");
instance.send(instanceSendTo.cmd_manager, "reload_relays"); instance.send(SEND_TO.cmd_manager, "reload_relays");
}); });
*/ */
@ -264,14 +264,13 @@ exports.install = function(instance) {
{ {
errLogger.error("CRITICAL!!! undefined relay", relaysData[line], line); errLogger.error("CRITICAL!!! undefined relay", relaysData[line], line);
//sendNotification("set port ", edgeName, ERRWEIGHT.CRITICAL, "local database is corrupted", "", instanceSendTo.tb, instance, null ); //sendNotification("set port ", edgeName, ERRWEIGHT.CRITICAL, "local database is corrupted", "", SEND_TO.tb, instance, null );
sendNotification("set port ", edgeName, "local_database_is_corrupted", {}, "", instanceSendTo.tb, instance ); sendNotification("set port ", edgeName, "local_database_is_corrupted", {}, "", SEND_TO.tb, instance );
} }
} }
if(pinsData[key].type == "state_of_contactor") if(pinsData[key].type == "state_of_contactor")
{ {
let pin = key - 1; let pin = key - 1;
if(controller_type === "unipi") pin = key; if(controller_type === "unipi") pin = key;
@ -299,33 +298,19 @@ exports.install = function(instance) {
] ]
} }
instance.send(instanceSendTo.tb, dataToTb); instance.send(SEND_TO.tb, dataToTb);
let time = 3*1000; let time = 3*1000;
setTimeout(function(){ setTimeout(function(){
instance.send(instanceSendTo.cmd_manager, {sender: "dido_controller", cmd: "buildTasks"}); instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "buildTasks"});
sendNotification("rsPort.open()", edgeName, "flow_start", {}, "", instanceSendTo.tb, instance ); sendNotification("rsPort.open()", edgeName, "flow_start", {}, "", SEND_TO.tb, instance );
monitor.info("-->FLOW bol spustený", edgeName, FLOW.OMS_edge_fw_version); monitor.info("-->FLOW bol spustený", edgeName, FLOW.OMS_edge_fw_version);
}, time); }, time);
} }
// we ensure, all tasks will be rebuild every day at 11. To set correct switch off and on times
let sendRebuildTasksAt11 = null;
const checkIf11Oclock = () =>
{
const d = new Date();
const h = d.getHours();
if(h === 11)
{
instance.send(instanceSendTo.cmd_manager, {sender:"dido_controller", cmd:"buildTasks"});
}
}
sendRebuildTasksAt11 = setInterval(checkIf11Oclock, 3600000);
function handleRsPort() function handleRsPort()
{ {
//TODO build according to pins!!! //TODO build according to pins!!!
@ -335,7 +320,7 @@ exports.install = function(instance) {
rsPort.on('error', function(err) { rsPort.on('error', function(err) {
logger.debug("rsPort opened error - failed", err.message); logger.debug("rsPort opened error - failed", err.message);
instance.send(instanceSendTo.debug, err.message); instance.send(SEND_TO.debug, err.message);
errorHandler.sendMessageToService( exports.title + " rsPort opened error - failed: " + err.message); errorHandler.sendMessageToService( exports.title + " rsPort opened error - failed: " + err.message);
}) })
@ -357,7 +342,7 @@ exports.install = function(instance) {
}) })
}).catch(function (reason) { }).catch(function (reason) {
//instance.send(instanceSendTo.debug, exports.title + " runSyncExec - promise rejected:" + reason); //instance.send(SEND_TO.debug, exports.title + " runSyncExec - promise rejected:" + reason);
errLogger.error( exports.title + " runSyncExec - promise rejected:" + reason); errLogger.error( exports.title + " runSyncExec - promise rejected:" + reason);
errorHandler.sendMessageToService( exports.title + " runSyncExec - promise rejected:" + reason); errorHandler.sendMessageToService( exports.title + " runSyncExec - promise rejected:" + reason);
@ -486,7 +471,7 @@ exports.install = function(instance) {
deviceStatuses["temperature"] = "OK"; deviceStatuses["temperature"] = "OK";
previousValues["temperature"] = value; previousValues["temperature"] = value;
instance.send(instanceSendTo.tb, dataToTb); instance.send(SEND_TO.tb, dataToTb);
} }
return; return;
} }
@ -503,15 +488,18 @@ exports.install = function(instance) {
ws.on('error', (err) => { ws.on('error', (err) => {
instance.send(instanceSendTo.debug, err.message); monitor.info('websocket error, reconnect')
instance.send(SEND_TO.debug, err.message);
clearInterval(startRequests); clearInterval(startRequests);
startRequests = null; ws = null;
setTimeout(handleWebSocket, 1000);
}) })
ws.onclose = function(){ ws.onclose = function(){
// connection closed, discard old websocket and create a new one in 5s // connection closed, discard old websocket and create a new one in 5s
// stopRequests(); // stopRequests();
monitor.info('websocket onclose, reconnect')
clearInterval(startRequests); clearInterval(startRequests);
ws = null; ws = null;
console.log("ws is null now, reconnecting..."); console.log("ws is null now, reconnecting...");
@ -650,14 +638,14 @@ exports.install = function(instance) {
//console.log(values); //console.log(values);
instance.send(instanceSendTo.tb, dataToTb); instance.send(SEND_TO.tb, dataToTb);
} }
function turnOnLine(line, pin, force, info) function turnOnLine(line, pin, force, info)
{ {
instance.send(instanceSendTo.debug, "turn on line " + line ); instance.send(SEND_TO.debug, "turn on line " + line );
if(force == undefined) force = false; if(force == undefined) force = false;
if(line == 0) if(line == 0)
@ -691,7 +679,7 @@ exports.install = function(instance) {
{ {
if(relaysData[line].contactor == 1) if(relaysData[line].contactor == 1)
{ {
instance.send(instanceSendTo.debug, "line is already on " + line ); instance.send(SEND_TO.debug, "line is already on " + line );
logger.debug("turnOnLine: line is already on: ", line); logger.debug("turnOnLine: line is already on: ", line);
return; return;
@ -701,7 +689,7 @@ exports.install = function(instance) {
// if(!rsPort.isOpen && !ws) // if(!rsPort.isOpen && !ws)
if(!rsPort && !ws) if(!rsPort && !ws)
{ {
errLogger.error("di do controller - port or websocket is not opened"); errLogger.error("dido controller - port or websocket is not opened");
return; return;
} }
@ -768,7 +756,7 @@ exports.install = function(instance) {
{ {
if(relaysData[line].contactor == 0) if(relaysData[line].contactor == 0)
{ {
instance.send(instanceSendTo.debug, "line is already off " + line ); instance.send(SEND_TO.debug, "line is already off " + line );
logger.debug("turnOffLine: line already off:", line); logger.debug("turnOffLine: line already off:", line);
return; return;
@ -821,7 +809,7 @@ exports.install = function(instance) {
if(!flowdata.data instanceof Object) return; if(!flowdata.data instanceof Object) return;
// console.log('***********************', flowdata.data) // console.log('***********************', flowdata.data)
instance.send(instanceSendTo.debug, flowdata.data); instance.send(SEND_TO.debug, flowdata.data);
// we handle nok status from modbus_reader component and thermometer // we handle nok status from modbus_reader component and thermometer
if(flowdata.data?.status) if(flowdata.data?.status)
@ -839,13 +827,13 @@ exports.install = function(instance) {
{ {
deviceStatuses["temperature"] = "NOK"; deviceStatuses["temperature"] = "NOK";
} }
return;
} }
else if(flowdata.data?.values)
{
const values = flowdata.data.values; const values = flowdata.data.values;
if(values.hasOwnProperty("twilight_sensor")) if(values.hasOwnProperty("twilight_sensor"))
{ {
instance.send(instanceSendTo.cmd_manager, {sender: "dido_controller", cmd: "lux_sensor", value: values["twilight_sensor"]}); instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "lux_sensor", value: values["twilight_sensor"]});
deviceStatuses["twilight_sensor"] = "OK" deviceStatuses["twilight_sensor"] = "OK"
} }
else if(values.hasOwnProperty("temperature")) else if(values.hasOwnProperty("temperature"))
@ -857,11 +845,16 @@ exports.install = function(instance) {
{ {
deviceStatuses["em"] = "OK"; deviceStatuses["em"] = "OK";
} }
else
{
return;
}
const updateStatus = checkFinalRVOStatus(); const updateStatus = checkFinalRVOStatus();
if(updateStatus) values.status = "OK"; if(updateStatus) values.status = "OK";
sendTelemetry(values, FLOW.OMS_rvo_tbname); sendTelemetry(values, FLOW.OMS_rvo_tbname);
}
}) })
@ -891,7 +884,7 @@ exports.install = function(instance) {
rsPort.write(Buffer.from(obj), function(err) { rsPort.write(Buffer.from(obj), function(err) {
switchLogic(obj); switchLogic(obj);
instance.send(instanceSendTo.debug, {"WRITE":obj} ); instance.send(SEND_TO.debug, {"WRITE":obj} );
}); });
} }
}) })
@ -1184,14 +1177,14 @@ exports.install = function(instance) {
{ {
if (newPinValue === 0 && newPinValue !== previousValues[pinIndex]) if (newPinValue === 0 && newPinValue !== previousValues[pinIndex])
{ {
sendNotification("switchLogic", edgeName, "main_switch_has_been_turned_off", {}, "", instanceSendTo.tb, instance , "state_of_main_switch"); sendNotification("switchLogic", edgeName, "main_switch_has_been_turned_off", {}, "", SEND_TO.tb, instance , "state_of_main_switch");
values["status"] = "NOK"; values["status"] = "NOK";
deviceStatuses["state_of_main_switch"] = "Off"; deviceStatuses["state_of_main_switch"] = "Off";
} }
else if (newPinValue === 1 && newPinValue !== previousValues[pinIndex]) else if (newPinValue === 1 && newPinValue !== previousValues[pinIndex])
{ {
sendNotification("switchLogic", edgeName, "main_switch_has_been_turned_on", {}, "", instanceSendTo.tb, instance , "state_of_main_switch"); sendNotification("switchLogic", edgeName, "main_switch_has_been_turned_on", {}, "", SEND_TO.tb, instance , "state_of_main_switch");
deviceStatuses["state_of_main_switch"] = "On"; deviceStatuses["state_of_main_switch"] = "On";
} }
@ -1236,7 +1229,7 @@ exports.install = function(instance) {
//ak je spracovany, a automatic - tak ho zapnem //ak je spracovany, a automatic - tak ho zapnem
//ak nie je spracovany, iba profil zapisem //ak nie je spracovany, iba profil zapisem
instance.send(instanceSendTo.cmd_manager, {sender: "dido_controller", cmd: "rotary_switch_state", value: value}); instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "rotary_switch_state", value: value});
//console.log("rotary_switch_state pin", pin2, pin3, value); //console.log("rotary_switch_state pin", pin2, pin3, value);
} }
@ -1245,16 +1238,16 @@ exports.install = function(instance) {
{ {
if (newPinValue === 0 && newPinValue !== previousValues[pinIndex]) if (newPinValue === 0 && newPinValue !== previousValues[pinIndex])
{ {
//sendNotification("switchLogic", edgeName, ERRWEIGHT.ALERT, "Power supply is not OK", "", instanceSendTo.tb, instance); //sendNotification("switchLogic", edgeName, ERRWEIGHT.ALERT, "Power supply is not OK", "", SEND_TO.tb, instance);
sendNotification("switchLogic", edgeName, "power_supply_has_disconnected_input", {}, "", instanceSendTo.tb, instance, "power_supply"); sendNotification("switchLogic", edgeName, "power_supply_has_disconnected_input", {}, "", SEND_TO.tb, instance, "power_supply");
values["status"] = "NOK"; values["status"] = "NOK";
deviceStatuses["power_supply"] = "NOK"; deviceStatuses["power_supply"] = "NOK";
} }
else if (newPinValue === 1 && newPinValue !== previousValues[pinIndex]) else if (newPinValue === 1 && newPinValue !== previousValues[pinIndex])
{ {
//sendNotification("switchLogic", edgeName, ERRWEIGHT.NOTICE, "Power supply is is OK", "", instanceSendTo.tb, instance); //sendNotification("switchLogic", edgeName, ERRWEIGHT.NOTICE, "Power supply is is OK", "", SEND_TO.tb, instance);
sendNotification("switchLogic", edgeName, "power_supply_works_correctly", {}, "", instanceSendTo.tb, instance, "power_supply"); sendNotification("switchLogic", edgeName, "power_supply_works_correctly", {}, "", SEND_TO.tb, instance, "power_supply");
deviceStatuses["power_supply"] = "OK"; deviceStatuses["power_supply"] = "OK";
} }
@ -1264,16 +1257,16 @@ exports.install = function(instance) {
{ {
if (newPinValue === 1 && newPinValue !== previousValues[pinIndex]) if (newPinValue === 1 && newPinValue !== previousValues[pinIndex])
{ {
//sendNotification("switchLogic", edgeName, ERRWEIGHT.ERROR, "Battery is not OK", "", instanceSendTo.tb, instance); //sendNotification("switchLogic", edgeName, ERRWEIGHT.ERROR, "Battery is not OK", "", SEND_TO.tb, instance);
sendNotification("switchLogic", edgeName, "battery_level_is_low", {}, "", instanceSendTo.tb, instance, "battery_level"); sendNotification("switchLogic", edgeName, "battery_level_is_low", {}, "", SEND_TO.tb, instance, "battery_level");
values["status"] = "NOK"; values["status"] = "NOK";
deviceStatuses["battery"] = "NOK"; deviceStatuses["battery"] = "NOK";
} }
else if (newPinValue === 0 && newPinValue !== previousValues[pinIndex]) else if (newPinValue === 0 && newPinValue !== previousValues[pinIndex])
{ {
//sendNotification("switchLogic", edgeName, ERRWEIGHT.NOTICE, "Battery is OK", "", instanceSendTo.tb, instance); //sendNotification("switchLogic", edgeName, ERRWEIGHT.NOTICE, "Battery is OK", "", SEND_TO.tb, instance);
sendNotification("switchLogic", edgeName, "battery_level_is_ok", {}, "", instanceSendTo.tb, instance, "battery_level"); sendNotification("switchLogic", edgeName, "battery_level_is_ok", {}, "", SEND_TO.tb, instance, "battery_level");
deviceStatuses["battery"] = "OK"; deviceStatuses["battery"] = "OK";
} }
@ -1287,19 +1280,19 @@ exports.install = function(instance) {
if (newPinValue != previousValues[pinIndex]) if (newPinValue != previousValues[pinIndex])
{ {
//sendNotification("switchLogic", edgeName, ERRWEIGHT.NOTICE, `RVO door ${value}`, "", instanceSendTo.tb, instance, "rvo_door"); //sendNotification("switchLogic", edgeName, ERRWEIGHT.NOTICE, `RVO door ${value}`, "", SEND_TO.tb, instance, "rvo_door");
//TODO ? sendNotification("switchLogic", edgeName, "door_value", {value: value}, "", instanceSendTo.tb, instance, "rvo_door"); //TODO ? sendNotification("switchLogic", edgeName, "door_value", {value: value}, "", SEND_TO.tb, instance, "rvo_door");
} }
if (value === "open" && FLOW.OMS_maintenance_mode) if (value === "open" && FLOW.OMS_maintenance_mode)
{ {
sendNotification("switchLogic", edgeName, "door_has_been_open", {}, "", instanceSendTo.tb, instance, "rvo_door"); sendNotification("switchLogic", edgeName, "door_has_been_open", {}, "", SEND_TO.tb, instance, "rvo_door");
} }
if (value === "open" && !FLOW.OMS_maintenance_mode) if (value === "open" && !FLOW.OMS_maintenance_mode)
{ {
//sendNotification("switchLogic", edgeName, ERRWEIGHT.WARNING, "RVO open door out of maintenance mode", "", instanceSendTo.tb, instance); //sendNotification("switchLogic", edgeName, ERRWEIGHT.WARNING, "RVO open door out of maintenance mode", "", SEND_TO.tb, instance);
sendNotification("switchLogic", edgeName, "door_has_been_open_without_permision_alarm_is_on", {}, "", instanceSendTo.tb, instance, "rvo_door"); sendNotification("switchLogic", edgeName, "door_has_been_open_without_permision_alarm_is_on", {}, "", SEND_TO.tb, instance, "rvo_door");
values["status"] = "NOK"; values["status"] = "NOK";
//console.log(door_has_been_open_without_permision_alarm_is_on); //console.log(door_has_been_open_without_permision_alarm_is_on);
@ -1314,7 +1307,7 @@ exports.install = function(instance) {
if(alarmStatus == "ON") turnOffAlarm(); if(alarmStatus == "ON") turnOffAlarm();
//turnOffAlarm(); //turnOffAlarm();
sendNotification("switchLogic", edgeName, "door_has_been_closed", {}, "", instanceSendTo.tb, instance, "rvo_door"); sendNotification("switchLogic", edgeName, "door_has_been_closed", {}, "", SEND_TO.tb, instance, "rvo_door");
} }
deviceStatuses["door_condition"] = value; deviceStatuses["door_condition"] = value;
@ -1353,12 +1346,12 @@ exports.install = function(instance) {
twilightError = true; twilightError = true;
values["status"] = "NOK"; values["status"] = "NOK";
let value = twilight_sensor_array.shift(); let value = twilight_sensor_array.shift();
//sendNotification("switchLogic", edgeName, ERRWEIGHT.ERROR, "Lux sensor error", {"Repeating value": value}, instanceSendTo.tb, instance ); //sendNotification("switchLogic", edgeName, ERRWEIGHT.ERROR, "Lux sensor error", {"Repeating value": value}, SEND_TO.tb, instance );
newPinValue = 0; newPinValue = 0;
} }
else if (set.size !== 1 && twilightError) else if (set.size !== 1 && twilightError)
{ {
//sendNotification("switchLogic", edgeName, ERRWEIGHT.NOTICE, "Lux sensor is working again", "", instanceSendTo.tb, instance ); //sendNotification("switchLogic", edgeName, ERRWEIGHT.NOTICE, "Lux sensor is working again", "", SEND_TO.tb, instance );
twilightError = false; twilightError = false;
twilight_sensor_array.shift(); twilight_sensor_array.shift();
newPinValue = value; newPinValue = value;
@ -1376,7 +1369,7 @@ exports.install = function(instance) {
if(diff >= twilight_sensor_interval * 60 * 1000) if(diff >= twilight_sensor_interval * 60 * 1000)
{ {
const average = twilight_sensor.reduce((acc, c) => acc + c.value, 0) / twilight_sensor.length; const average = twilight_sensor.reduce((acc, c) => acc + c.value, 0) / twilight_sensor.length;
instance.send(instanceSendTo.cmd_manager, {sender: "dido_controller", cmd: "lux_sensor", value: average}); instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "lux_sensor", value: average});
twilight_sensor = []; twilight_sensor = [];
@ -1387,11 +1380,11 @@ exports.install = function(instance) {
} }
else if(type == "state_of_contactor") else if(type == "state_of_contactor")
{ {
//sendNotification("switchLogic", edgeName, ERRWEIGHT.INFO, `State of contactor ${line} is now ${value}`, "", instanceSendTo.tb, instance ); //sendNotification("switchLogic", edgeName, ERRWEIGHT.INFO, `State of contactor ${line} is now ${value}`, "", SEND_TO.tb, instance );
if(!(deviceStatuses["state_of_contactor"][line] == value)) if(!(deviceStatuses["state_of_contactor"][line] == value))
{ {
sendNotification("switchLogic", edgeName, "state_of_contactor_for_line", {line: line, value: value}, "", instanceSendTo.tb, instance ); sendNotification("switchLogic", edgeName, "state_of_contactor_for_line", {line: line, value: value}, "", SEND_TO.tb, instance );
} }
else else
{ {
@ -1433,7 +1426,7 @@ exports.install = function(instance) {
//a budu sa odosielat commandy, tie vsak mozu zlyhat, a preto potrebujeme ich spusti trochu neskor //a budu sa odosielat commandy, tie vsak mozu zlyhat, a preto potrebujeme ich spusti trochu neskor
setTimeout(function(){ setTimeout(function(){
instance.send(instanceSendTo.cmd_manager, {sender: "dido_controller", cmd: "reload_relays", line: line, time: time, value: value, dataChanged: dataChanged}); instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "reload_relays", line: line, time: time, value: value, dataChanged: dataChanged});
}, time); }, time);
reportLineStatus(line); reportLineStatus(line);
@ -1458,24 +1451,53 @@ exports.install = function(instance) {
if(valueChanged) if(valueChanged)
{ {
instance.send(instanceSendTo.cmd_manager, {sender: "dido_controller", cmd: "state_of_breaker", value: value, line: line}); instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "state_of_breaker", value: value, line: line});
//mame 3 istice. ked je viac ako 3 linie, dalsie sa zapajaju paralelne. to znamena na istici 1 je linia 1 a 4, na istici 2 je linia 2 a 5, na istici 3 je linia 3 a 6 (key je string ("4")) //mame iba 3 istice. vyreportujeme a ohandlujeme liniu na tom istom istici ako paralelna linia (napr linia 1, paralelna s nou je linia 4, key je string "4")
//vyreportujeme a ohandlujeme liniu na tom istom istici ako paralelna linia // ak je 7 linii, na 1 istici je linia 1,4,7
if(line == 1)
{
const lineOnSameBraker = [4,7];
for (var i = 0; i < lineOnSameBraker.length; i++)
{
if(!relaysData.hasOwnProperty(lineOnSameBraker[i])) continue;
instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "state_of_breaker", value: value, line: lineOnSameBraker[i]});
deviceStatuses["state_of_breaker"][lineOnSameBraker[i]] = value;
reportLineStatus(lineOnSameBraker[i]);
values[type] = value;
const tbname = relaysData[lineOnSameBraker[i]].tbname;
sendTelemetry(values, tbname);
delete values[type];
}
}
else
{
const lineOnSameBraker = line + 3 + ""; const lineOnSameBraker = line + 3 + "";
if(relaysData.hasOwnProperty(lineOnSameBraker)) { if(relaysData.hasOwnProperty(lineOnSameBraker))
instance.send(instanceSendTo.cmd_manager, {sender: "di_do_controller", cmd: "state_of_breaker", value: value, line: line + 3}); {
instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "state_of_breaker", value: value, line: line + 3});
deviceStatuses["state_of_breaker"][line + 3] = value; deviceStatuses["state_of_breaker"][line + 3] = value;
reportLineStatus(line + 3); reportLineStatus(line + 3);
values[type] = value; values[type] = value;
tbname = relaysData[lineOnSameBraker].tbname; const tbname = relaysData[lineOnSameBraker].tbname;
sendTelemetry(values, tbname); sendTelemetry(values, tbname);
delete values[type]; delete values[type];
} }
}
} }
if(value == "Off") values["status"] = "NOK"; if(value == "Off") values["status"] = "NOK";
@ -1558,7 +1580,7 @@ exports.install = function(instance) {
] ]
} }
instance.send(instanceSendTo.tb, dataToTb); instance.send(SEND_TO.tb, dataToTb);
} }
} }

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

@ -3,7 +3,7 @@ exports.title = 'Modbus reader';
exports.version = '2.0.0'; exports.version = '2.0.0';
exports.group = 'Worksys'; exports.group = 'Worksys';
exports.color = '#2134B0'; exports.color = '#2134B0';
exports.output = ["red", "white"]; exports.output = ["red", "white", "yellow"];
exports.click = false; exports.click = false;
exports.author = 'Rastislav Kovac'; exports.author = 'Rastislav Kovac';
exports.icon = 'bolt'; 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. 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 modbus = require('jsmodbus');
const SerialPort = require('serialport') const SerialPort = require('serialport');
const { timeoutInterval, deviceConfig } = require("../databases/modbus_config"); const { timeoutInterval, deviceConfig } = require("../databases/modbus_config");
const ErrorToServiceHandler = require('./helper/ErrorToServiceHandler');
const errorHandler = new ErrorToServiceHandler();
const { sendNotification } = require('./helper/notification_reporter'); const { sendNotification } = require('./helper/notification_reporter');
const instanceSendTo = { const DELAY_BETWEEN_DEVICES = 10000;
const SEND_TO = {
debug: 0, debug: 0,
dido_controller: 1, dido_controller: 1,
tb: 2
}; };
//to handle NOK and OK sendNotifications s //to handle NOK and OK sendNotifications s
const numberOfNotResponding = {}; const numberOfNotResponding = {};
let tbName = null; let tbName = null;
let mainSocket;
exports.install = function(instance) { exports.install = function(instance) {
@ -47,12 +46,16 @@ exports.install = function(instance) {
this.index = 0; this.index = 0;
this.timeoutInterval = 5000; 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 // 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; // adresa zariadenia (1 ma EM340 a 2 ma twilight_sensor) this.deviceAddress = null; // device address (1 - EM340 and 2 for twilight_sensor)
this.indexInDeviceConfig = 0; // prvy item v deviceConfig this.indexInDeviceConfig = 0; // first item in deviceConfig
this.lengthOfActualDeviceStream = null; this.lengthOfActualDeviceStream = null;
this.device = null; this.device = null;
// lampSwitchNotification helper variables
this.onNotificationSent = false;
this.offNotificationSent = false;
this.startSocket(); 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 // we create a client for every deviceAddress ( = address) in list and push them into dictionary
for( let i = 0; i < deviceConfig.length; i++) 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) { this.socket.on('error', function(e) {
@ -86,7 +89,7 @@ exports.install = function(instance) {
this.socket.on('open', function () { this.socket.on('open', function () {
console.log("socket connected"); console.log("socket connected");
obj.getActualStreamAndDevice(); 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 this.device = dev.device; //em340, twilight_sensor
if(this.indexInDeviceConfig == 0) setTimeout(this.readRegisters, this.timeoutInterval); if(this.indexInDeviceConfig == 0) setTimeout(this.readRegisters, this.timeoutInterval);
else setTimeout(this.readRegisters, 2000); else setTimeout(this.readRegisters, DELAY_BETWEEN_DEVICES);
} }
readRegisters = () => { readRegisters = () => {
@ -131,26 +134,24 @@ exports.install = function(instance) {
{ {
message = "twilight_sensor_ok"; 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]; delete numberOfNotResponding[obj.device];
} }
obj.transformResponse(resp, register, obj.deviceAddress); obj.transformResponse(resp, register);
obj.error = 0; //obj.errors = 0;
obj.index++; obj.index++;
obj.readAnotherRegister();
if(obj.index < obj.lengthOfActualDeviceStream) setTimeout(obj.readRegisters, 0);
else obj.setNewStream();
}).catch (function () { }).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++; obj.errors++;
if(obj.error == obj.lengthOfActualDeviceStream) 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 ?? //todo - neposlalo notification, ked sme vypojili twilight a neposle to do tb, ale do dido ??
if(!numberOfNotResponding.hasOwnProperty(obj.device)) if(!numberOfNotResponding.hasOwnProperty(obj.device))
@ -164,11 +165,11 @@ exports.install = function(instance) {
{ {
message = "electrometer_nok"; 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; numberOfNotResponding[obj.device] = 1;
} }
obj.error = 0; obj.errors = 0;
numberOfNotResponding[obj.device] += 1; numberOfNotResponding[obj.device] += 1;
} }
@ -176,14 +177,24 @@ exports.install = function(instance) {
depth: null 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++; obj.index++;
if(obj.index < obj.lengthOfActualDeviceStream) setTimeout(obj.readRegisters, 0); obj.readAnotherRegister();
else obj.setNewStream();
}) })
}; };
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++) { for (let i = 0; i < this.lengthOfActualDeviceStream; i++) {
@ -194,11 +205,11 @@ exports.install = function(instance) {
let multiplier = a.multiplier; let multiplier = a.multiplier;
let value = this.calculateValue(response, 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(tbName == undefined) return;
if(this.index + 1 + this.errors < this.lengthOfActualDeviceStream) if(this.index + 1 < this.lengthOfActualDeviceStream)
{ {
this.allValues[tbAttribute] = value; this.allValues[tbAttribute] = value;
return; return;
@ -210,8 +221,9 @@ exports.install = function(instance) {
}; };
this.checkNullVoltage(values); this.checkNullVoltage(values);
this.lampSwitchNotification(values);
instance.send(instanceSendTo.dido_controller, {values: values}); instance.send(SEND_TO.dido_controller, {values: values});
this.allValues = {}; this.allValues = {};
break; break;
@ -223,8 +235,6 @@ exports.install = function(instance) {
setNewStream = () => setNewStream = () =>
{ {
// console.log('------------',this.lengthOfActualDeviceStream, this.index);
// console.log('------------',this.indexInDeviceConfig, deviceConfig.length);
if(this.lengthOfActualDeviceStream == this.index) if(this.lengthOfActualDeviceStream == this.index)
{ {
if(this.indexInDeviceConfig + 1 == deviceConfig.length) 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) => calculateValue = (response, multiplier) =>
{ {
let value = 0; let value = 0;
@ -293,7 +277,6 @@ exports.install = function(instance) {
return Math.round(value * multiplier * 10) / 10; return Math.round(value * multiplier * 10) / 10;
} }
checkNullVoltage = (values) => { checkNullVoltage = (values) => {
if(!(values.hasOwnProperty("Phase_1_voltage") || values.hasOwnProperty("Phase_2_voltage") || values.hasOwnProperty("Phase_3_voltage"))) return; 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) if(values[singleValue] == 0)
{ {
FLOW.OMS_no_voltage.add(phase); 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') // console.log('no voltage')
} }
else else
{ {
FLOW.OMS_no_voltage.delete(phase); FLOW.OMS_no_voltage.delete(phase);
// console.log('voltage detected') // 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) => { * 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
return Object.keys(objectName).length === 0 && objectName.constructor === Object; */
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(() => { setTimeout(() => {
const newSocket = new SocketWithClients();
mainSocket = new SocketWithClients();
tbName = FLOW.OMS_rvo_tbname; 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); }, 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();
};