diff --git a/databases/settings.table b/databases/settings.table index b649808..7d0c8cd 100644 --- a/databases/settings.table +++ b/databases/settings.table @@ -1,2 +1,2 @@ rvo_name:string|lang:string|mqtt_host:string|mqtt_clientid:string|mqtt_username:string|mqtt_port:number|maintanace_mode:boolean|projects_id:number|controller_type:string|backup_on_failure:boolean|restore_from_backup:number|restore_backup_wait:number -+|Grafia 10.0.0.74|en||10_0_0_74_grafia||1883|0|29|unipi|1|30|50|........................................... ++|Grafia 10.0.0.76|en|192.168.252.1|10_0_0_76_grafia|6TsPFTwE1j8iI8B1oIYD|1883|0|31|unipi|1|100|5|........................................... diff --git a/flow/designer.json b/flow/designer.json index ffba053..f6271ea 100644 --- a/flow/designer.json +++ b/flow/designer.json @@ -10,7 +10,7 @@ { "name": "Time setter", "linker": "time-setter", - "id": "1667235000217", + "id": "1667233810390", "index": 1 } ], @@ -19,9 +19,9 @@ "id": "1636110851291", "component": "socomec", "tab": "1636110831878", - "name": "IP - 192.168.1.11 & 12", - "x": 53, - "y": 145, + "name": "IP - 192.168.1.31 & 32", + "x": 34, + "y": 124, "connections": { "0": [ { @@ -40,17 +40,17 @@ }, { "index": "0", - "id": "1643023439891" + "id": "1643021318333" } ], "2": [ { "index": "0", - "id": "1640097360601" + "id": "1640011795746" }, { "index": "0", - "id": "1669850052514" + "id": "1645452856681" } ] }, @@ -65,8 +65,8 @@ "color": "#2134B0", "notes": "", "options": { - "host": "192.168.1.11", - "port": 502 + "port": 502, + "host": "192.168.1.11" } }, { @@ -74,8 +74,8 @@ "component": "debug", "tab": "1636110831878", "name": "Debug", - "x": 376, - "y": 32, + "x": 389, + "y": 45, "connections": {}, "disabledio": { "input": [ @@ -100,13 +100,11 @@ "component": "debug", "tab": "1636110831878", "name": "Debug", - "x": 377, - "y": 113, + "x": 553, + "y": 83, "connections": {}, "disabledio": { - "input": [ - 0 - ], + "input": [], "output": [] }, "state": { @@ -126,13 +124,13 @@ "component": "virtualwirein", "tab": "1636110831878", "name": "tb-prod01-push", - "x": 23, - "y": 586, + "x": 30, + "y": 587, "connections": { "0": [ { "index": "0", - "id": "1694077414274" + "id": "1694075854662" } ] }, @@ -155,8 +153,8 @@ "component": "virtualwireout", "tab": "1636110831878", "name": "tb-prod01-push", - "x": 383, - "y": 234, + "x": 446, + "y": 194, "connections": {}, "disabledio": { "input": [], @@ -177,13 +175,13 @@ "component": "monitormemory", "tab": "1636110831878", "name": "Memory", - "x": 37, - "y": 945, + "x": 47, + "y": 987, "connections": { "0": [ { "index": "0", - "id": "1641906774515" + "id": "1641214032469" } ] }, @@ -192,14 +190,14 @@ "output": [] }, "state": { - "text": "804.16 MB / 987.80 MB", + "text": "847.58 MB / 987.80 MB", "color": "gray" }, "color": "#F6BB42", "notes": "", "options": { "enabled": true, - "interval": 30000 + "interval": 60000 } }, { @@ -207,8 +205,8 @@ "component": "debug", "tab": "1636110831878", "name": "Debug", - "x": 395, - "y": 984, + "x": 397, + "y": 1056, "connections": {}, "disabledio": { "input": [ @@ -233,13 +231,13 @@ "component": "monitorconsumption", "tab": "1636110831878", "name": "CPU", - "x": 35, - "y": 850, + "x": 43, + "y": 890, "connections": { "0": [ { "index": "0", - "id": "1641906812467" + "id": "1641213956795" } ] }, @@ -248,7 +246,7 @@ "output": [] }, "state": { - "text": "3.1% / 57.85 MB", + "text": "0.3% / 64.51 MB", "color": "gray" }, "color": "#967ADC", @@ -259,7 +257,7 @@ "monitorsize": true, "monitorconsumption": true, "enabled": true, - "interval": 30000 + "interval": 60000 } }, { @@ -267,8 +265,8 @@ "component": "debug", "tab": "1636110831878", "name": "Debug", - "x": 396, - "y": 808, + "x": 397, + "y": 868, "connections": {}, "disabledio": { "input": [ @@ -289,17 +287,17 @@ } }, { - "id": "1640097360601", + "id": "1640011795746", "component": "httprequest", "tab": "1636110831878", - "name": "grafia-prod01.worksys.io", - "x": 380, - "y": 317, + "name": "grafia-prod01.worksys.io/total_energy", + "x": 443, + "y": 284, "connections": { "0": [ { "index": "0", - "id": "1640097392518" + "id": "1640011891453" } ] }, @@ -314,19 +312,19 @@ "color": "#5D9CEC", "notes": "", "options": { - "stringify": "json", "method": "POST", + "stringify": "json", "url": "http://192.168.252.2:8005/total_energy", "type": "json" } }, { - "id": "1640097392518", + "id": "1640011891453", "component": "debug", "tab": "1636110831878", "name": "Debug", - "x": 697, - "y": 317, + "x": 794, + "y": 279, "connections": {}, "disabledio": { "input": [ @@ -347,17 +345,17 @@ } }, { - "id": "1641906699312", - "component": "monitordisk", + "id": "1640013180066", + "component": "trigger", "tab": "1636110831878", - "name": "Disk", - "x": 35, - "y": 1036, + "name": "Trigger", + "x": 186, + "y": 292, "connections": { "0": [ { "index": "0", - "id": "1641906732272" + "id": "1640011795746" } ] }, @@ -366,122 +364,23 @@ "output": [] }, "state": { - "text": "5.67 GB / 7.26 GB", + "text": "", "color": "gray" }, "color": "#F6BB42", "notes": "", "options": { - "enabled": true, - "path": "/", - "interval": 30000 + "data": "{s:3}", + "datatype": "object" } }, { - "id": "1641906703877", - "component": "debug", - "tab": "1636110831878", - "name": "Debug", - "x": 396, - "y": 1073, - "connections": {}, - "disabledio": { - "input": [ - 0 - ], - "output": [] - }, - "state": { - "text": "Enabled", - "color": "gray" - }, - "color": "#967ADC", - "notes": "", - "options": { - "type": "data", - "repository": false, - "enabled": true - } - }, - { - "id": "1641906732272", + "id": "1641213956795", "component": "code", "tab": "1636110831878", "name": "Code", - "x": 196, - "y": 1034, - "connections": { - "0": [ - { - "index": "0", - "id": "1641906703877" - }, - { - "index": "0", - "id": "1641907044563" - } - ] - }, - "disabledio": { - "input": [], - "output": [] - }, - "state": { - "text": "", - "color": "gray" - }, - "color": "#656D78", - "notes": "", - "options": { - "keepmessage": true, - "code": "let response = {};\n\nresponse.hdd_total = value.total;\nresponse.hdd_free = value.free;\nresponse.hdd_used = value.used;\n\nsend(0, response);", - "outputs": 1, - "COMPONENT": "code", - "NAME": "Code" - } - }, - { - "id": "1641906774515", - "component": "code", - "tab": "1636110831878", - "name": "Code", - "x": 197, - "y": 941, - "connections": { - "0": [ - { - "index": "0", - "id": "1636971491099" - }, - { - "index": "0", - "id": "1641907044563" - } - ] - }, - "disabledio": { - "input": [], - "output": [] - }, - "state": { - "text": "", - "color": "gray" - }, - "color": "#656D78", - "notes": "", - "options": { - "keepmessage": true, - "code": "let response = {};\n\nresponse.memory_total = value.total;\nresponse.memory_free = value.free;\nresponse.memory_used = value.used;\n\nsend(0, response);", - "outputs": 1 - } - }, - { - "id": "1641906812467", - "component": "code", - "tab": "1636110831878", - "name": "Code", - "x": 202, - "y": 845, + "x": 214, + "y": 889, "connections": { "0": [ { @@ -490,7 +389,7 @@ }, { "index": "0", - "id": "1641907044563" + "id": "1641214092460" } ] }, @@ -511,12 +410,47 @@ } }, { - "id": "1641907044563", + "id": "1641214032469", + "component": "code", + "tab": "1636110831878", + "name": "Code", + "x": 214, + "y": 983, + "connections": { + "0": [ + { + "index": "0", + "id": "1636971491099" + }, + { + "index": "0", + "id": "1641214092460" + } + ] + }, + "disabledio": { + "input": [], + "output": [] + }, + "state": { + "text": "", + "color": "gray" + }, + "color": "#656D78", + "notes": "", + "options": { + "keepmessage": true, + "code": "let response = {};\n\nresponse.memory_total = value.total;\nresponse.memory_free = value.free;\nresponse.memory_used = value.used;\n\nsend(0, response);", + "outputs": 1 + } + }, + { + "id": "1641214092460", "component": "virtualwireout", "tab": "1636110831878", "name": "send-to-services", - "x": 398, - "y": 892, + "x": 414, + "y": 965, "connections": {}, "disabledio": { "input": [], @@ -533,17 +467,113 @@ } }, { - "id": "1641907104812", - "component": "virtualwirein", + "id": "1641214696139", + "component": "monitordisk", "tab": "1636110831878", - "name": "send-to-services", - "x": 65, - "y": 1232, + "name": "Disk", + "x": 52, + "y": 1088, "connections": { "0": [ { "index": "0", - "id": "1641907121073" + "id": "1641214703623" + } + ] + }, + "disabledio": { + "input": [], + "output": [] + }, + "state": { + "text": "5.78 GB / 7.26 GB", + "color": "gray" + }, + "color": "#F6BB42", + "notes": "", + "options": { + "enabled": true, + "path": "/", + "interval": 60000 + } + }, + { + "id": "1641214703610", + "component": "debug", + "tab": "1636110831878", + "name": "Debug", + "x": 399, + "y": 1146, + "connections": {}, + "disabledio": { + "input": [ + 0 + ], + "output": [] + }, + "state": { + "text": "Enabled", + "color": "gray" + }, + "color": "#967ADC", + "notes": "", + "options": { + "type": "data", + "repository": false, + "enabled": true + } + }, + { + "id": "1641214703623", + "component": "code", + "tab": "1636110831878", + "name": "Code", + "x": 219, + "y": 1090, + "connections": { + "0": [ + { + "index": "0", + "id": "1641214703610" + }, + { + "index": "0", + "id": "1641214092460" + } + ] + }, + "disabledio": { + "input": [], + "output": [] + }, + "state": { + "text": "", + "color": "gray" + }, + "color": "#656D78", + "notes": "", + "options": { + "keepmessage": true, + "code": "let response = {};\n\nresponse.hdd_total = value.total;\nresponse.hdd_free = value.free;\nresponse.hdd_used = value.used;\n\nsend(0, response);", + "outputs": 1 + } + }, + { + "id": "1641214819493", + "component": "virtualwirein", + "tab": "1636110831878", + "name": "send-to-services", + "x": 57, + "y": 1349, + "connections": { + "0": [ + { + "index": "0", + "id": "1641214853420" + }, + { + "index": "0", + "id": "1641214870492" } ] }, @@ -562,21 +592,47 @@ } }, { - "id": "1641907121073", + "id": "1641214853420", + "component": "debug", + "tab": "1636110831878", + "name": "Debug", + "x": 343, + "y": 1306, + "connections": {}, + "disabledio": { + "input": [ + 0 + ], + "output": [] + }, + "state": { + "text": "Enabled", + "color": "gray" + }, + "color": "#967ADC", + "notes": "", + "options": { + "type": "data", + "repository": false, + "enabled": true + } + }, + { + "id": "1641214870492", "component": "infosender", "tab": "1636110831878", "name": "Info sender", - "x": 304, - "y": 1227, + "x": 322, + "y": 1395, "connections": { "0": [ { "index": "0", - "id": "1641907134719" + "id": "1641214879162" }, { "index": "0", - "id": "1641907182409" + "id": "1641214887643" } ] }, @@ -595,17 +651,43 @@ } }, { - "id": "1641907134719", + "id": "1641214879162", + "component": "debug", + "tab": "1636110831878", + "name": "Debug", + "x": 543, + "y": 1470, + "connections": {}, + "disabledio": { + "input": [ + 0 + ], + "output": [] + }, + "state": { + "text": "Enabled", + "color": "gray" + }, + "color": "#967ADC", + "notes": "", + "options": { + "type": "data", + "repository": false, + "enabled": true + } + }, + { + "id": "1641214887643", "component": "httprequest", "tab": "1636110831878", "name": "http://192.168.252.2:8004/sentmessage", - "x": 533, - "y": 1191, + "x": 535, + "y": 1363, "connections": { "0": [ { "index": "0", - "id": "1641907188601" + "id": "1641214960946" } ] }, @@ -620,19 +702,19 @@ "color": "#5D9CEC", "notes": "", "options": { - "stringify": "json", - "method": "POST", + "type": "json", "url": "http://192.168.252.2:8004/sentmessage", - "type": "json" + "method": "POST", + "stringify": "json" } }, { - "id": "1641907182409", + "id": "1641214960946", "component": "debug", "tab": "1636110831878", "name": "Debug", - "x": 536, - "y": 1295, + "x": 911, + "y": 1359, "connections": {}, "disabledio": { "input": [ @@ -653,43 +735,17 @@ } }, { - "id": "1641907188601", - "component": "debug", - "tab": "1636110831878", - "name": "Debug", - "x": 906, - "y": 1189, - "connections": {}, - "disabledio": { - "input": [ - 0 - ], - "output": [] - }, - "state": { - "text": "Enabled", - "color": "gray" - }, - "color": "#967ADC", - "notes": "", - "options": { - "type": "data", - "repository": false, - "enabled": true - } - }, - { - "id": "1643023439891", + "id": "1643021318333", "component": "code", "tab": "1636110831878", "name": "Code", - "x": 569, - "y": 176, + "x": 705.8833312988281, + "y": 130.53334045410156, "connections": { "0": [ { "index": "0", - "id": "1643023495930" + "id": "1643021403079" } ] }, @@ -707,17 +763,17 @@ "notes": "", "options": { "keepmessage": true, - "code": "//if(value.hasOwnProperty('1JMYvnx2RzKEo4aWQ7D93vAL8yZV3m9NBePXbrdj'))\n//{\n\t//send(0, value);\n//}\n//if(value.hasOwnProperty('1559') || value.hasOwnProperty('1558'))\nif(value.hasOwnProperty('1559'))\n{\n\tif(value[\"1559\"][0].values.hasOwnProperty(\"total_energy\"))\n\t\t{\n\t\t\tsend(0, value);\n\t\t}\n\n}\n\nif(value.hasOwnProperty('1558'))\n{\n\tif(value[\"1558\"][0].values.hasOwnProperty(\"total_energy\"))\n\t\t{\n\t\t\tsend(0, value);\n\t\t}\n\n}", + "code": "//if(value.hasOwnProperty('RO8rjaBDy21qPQJzW7oKN17pK3xmNleVZg9Ed4Gw') || value.hasOwnProperty('K94XLav1glVRnyQ6r01VZ3kme3YJwBxM5oOzdP2j'))\n\tif(value.hasOwnProperty('K94XLav1glVRnyQ6r01VZ3kme3YJwBxM5oOzdP2j'))\n\t{\n\t\tsend(0, value);\n\t}", "outputs": 1 } }, { - "id": "1643023495930", + "id": "1643021403079", "component": "debug", "tab": "1636110831878", - "name": "Just 1 module", - "x": 719, - "y": 169, + "name": "just 1 module", + "x": 882.8833312988281, + "y": 127.53334045410156, "connections": {}, "disabledio": { "input": [], @@ -736,12 +792,36 @@ } }, { - "id": "1660058310860", + "id": "1645452856681", + "component": "debug", + "tab": "1636110831878", + "name": "Http req data", + "x": 449.8833312988281, + "y": 381.51666259765625, + "connections": {}, + "disabledio": { + "input": [], + "output": [] + }, + "state": { + "text": "Enabled", + "color": "gray" + }, + "color": "#967ADC", + "notes": "", + "options": { + "type": "data", + "repository": false, + "enabled": true + } + }, + { + "id": "1660045438935", "component": "virtualwireout", "tab": "1636110831878", "name": "send-to-services", - "x": 590.5, - "y": 633.4166870117188, + "x": 582.8833312988281, + "y": 652, "connections": {}, "disabledio": { "input": [], @@ -758,17 +838,17 @@ } }, { - "id": "1667235009598", + "id": "1667233820282", "component": "timesetter", - "tab": "1667235000217", + "tab": "1667233810390", "name": "Timesetter", - "x": 245.0833282470703, - "y": 166, + "x": 333.8833312988281, + "y": 136, "connections": { "0": [ { "index": "0", - "id": "1667235037440" + "id": "1667233834272" } ] }, @@ -785,17 +865,17 @@ "options": {} }, { - "id": "1667235012156", + "id": "1667233826092", "component": "timer", - "tab": "1667235000217", + "tab": "1667233810390", "name": "Timer", - "x": 38.08332824707031, - "y": 249, + "x": 115.88333129882812, + "y": 227, "connections": { "0": [ { "index": "0", - "id": "1667235009598" + "id": "1667233820282" } ] }, @@ -814,17 +894,61 @@ } }, { - "id": "1667235031667", + "id": "1667233834272", + "component": "debug", + "tab": "1667233810390", + "name": "Debug", + "x": 554.8833312988281, + "y": 133, + "connections": {}, + "disabledio": { + "input": [], + "output": [] + }, + "state": { + "text": "Enabled", + "color": "gray" + }, + "color": "#967ADC", + "notes": "", + "options": { + "type": "data", + "repository": false, + "enabled": true + } + }, + { + "id": "1667233843489", + "component": "comment", + "tab": "1667233810390", + "name": "Getting actual time once a day from service-prod01.worksys.io", + "x": 163.88333129882812, + "y": 38, + "connections": {}, + "disabledio": { + "input": [], + "output": [] + }, + "state": { + "text": "", + "color": "gray" + }, + "color": "#704cff", + "notes": "", + "options": {} + }, + { + "id": "1667233894816", "component": "trigger", - "tab": "1667235000217", + "tab": "1667233810390", "name": "Trigger", - "x": 41.08332824707031, - "y": 168, + "x": 118.88333129882812, + "y": 138, "connections": { "0": [ { "index": "0", - "id": "1667235009598" + "id": "1667233820282" } ] }, @@ -841,67 +965,17 @@ "options": {} }, { - "id": "1667235037440", - "component": "debug", - "tab": "1667235000217", - "name": "Debug", - "x": 441.0833282470703, - "y": 162, - "connections": {}, - "disabledio": { - "input": [], - "output": [] - }, - "state": { - "text": "Enabled", - "color": "gray" - }, - "color": "#967ADC", - "notes": "", - "options": { - "type": "data", - "repository": false, - "enabled": true - } - }, - { - "id": "1669850052514", - "component": "debug", - "tab": "1636110831878", - "name": "Http req data", - "x": 372.0833282470703, - "y": 422, - "connections": {}, - "disabledio": { - "input": [ - 0 - ], - "output": [] - }, - "state": { - "text": "Enabled", - "color": "gray" - }, - "color": "#967ADC", - "notes": "", - "options": { - "type": "data", - "repository": false, - "enabled": true - } - }, - { - "id": "1694077414274", + "id": "1694075854662", "component": "httprequest", "tab": "1636110831878", - "name": "grafia-prod01.worksys.io/rerouting74", - "x": 224, - "y": 584, + "name": "grafia-prod01.worksys.io/rerouting76", + "x": 263, + "y": 586, "connections": { "0": [ { "index": "0", - "id": "1694077451207" + "id": "1694075957040" } ] }, @@ -916,19 +990,19 @@ "color": "#5D9CEC", "notes": "", "options": { - "type": "json", - "url": "http://192.168.252.2:8005/rerouting74", + "stringify": "json", "method": "POST", - "stringify": "json" + "url": "http://192.168.252.2:8005/rerouting76", + "type": "json" } }, { - "id": "1694077451207", + "id": "1694075957040", "component": "debug", "tab": "1636110831878", - "name": "rerouting", - "x": 591.0833282470703, - "y": 529, + "name": "To rerouting76", + "x": 599, + "y": 541, "connections": {}, "disabledio": { "input": [ diff --git a/flow/energomonitor_socomec.js b/flow/energomonitor_socomec.js index d47d995..6af47b7 100644 --- a/flow/energomonitor_socomec.js +++ b/flow/energomonitor_socomec.js @@ -12,20 +12,10 @@ exports.readme = `Modbus requests to energomonitor socomec suitcase`; const streamBuilder = require("./helper/energo_streambuilder"); const structure = { - "192.168.1.11": { - 51: "i-35", // nový merák I-35, bez zóny - 16: "i-35", // zmena adresy z 1 na 16 - 13.5.2022 - "6A": "i-60A", - "6B": "i-60B", - "7A": "i-60A", - "7B": "i-60B", - "8A": "i-60A", - "8B": "i-60B", - 9: "i-30", - "10A": "i-60A", - "10B": "i-60B", - "11A": "i-60A", - "11B": "i-60B", + "192.168.1.31": { + 3: "i-35", + 2: "i-30", + 11: "i-35", "12A": "i-60A", "12B": "i-60B", "13A": "i-60A", @@ -34,59 +24,19 @@ const structure = { "14B": "i-60B", "15A": "i-60A", "15B": "i-60B", - 5: "i-30", - "2A": "i-60A", - "2B": "i-60B", - "3A": "i-60A", - "3B": "i-60B", - "4A": "i-60A", - "4B": "i-60B", -//novo nainstalovane 28.10.2024 - "21A": "i-60A", - "21B": "i-60B" - - // "36B": "i-60B" // vymyslene kvoli chybe - }, - "192.168.1.12": { - 18: "i-35", - "2A": "i-60A", - "2B": "i-60B", - "3A": "i-60A", - "3B": "i-60B", - "4A": "i-60A", - "4B": "i-60B", - "5A": "i-60A", - "5B": "i-60B", - "6A": "i-60A", - "6B": "i-60B", - "7A": "i-60A", - "7B": "i-60B", - "8A": "i-60A", - "8B": "i-60B", - "9A": "i-60A", - "9B": "i-60B", - "10A": "i-60A", - "10B": "i-60B", - "11A": "i-60A", - "11B": "i-60B", - "12A": "i-60A", - "12B": "i-60B", - "13A": "i-60A", - "13B": "i-60B", - "14A": "i-60A", - "14B": "i-60B", - "15A": "i-60A", - "15B": "i-60B", - "16A": "i-60A", - "16B": "i-60B", - "17A": "i-60A", - "17B": "i-60B" + 16: "i-30", + 21: "i-30", + "22A": "i-60A", + "22B": "i-60B", + "23A": "i-60A", + "23B": "i-60B", + "24A": "i-60A", + "24B": "i-60B", + // 76: "i-30"//vymyslene pre testovanie } }; - - exports.install = function(instance) { const modbus = require('jsmodbus'); @@ -94,8 +44,7 @@ exports.install = function(instance) { require('events').EventEmitter.defaultMaxListeners = 20; - - const allModulesEnergy = {unipi_74: ""}; // key to identify source data + const allModulesEnergy = {unipi_76: ""}; // key to identify source data const date = new Date(); let hour = date.getHours(); @@ -130,85 +79,48 @@ exports.install = function(instance) { // "multiplier":1, // }, // ] - // } + // }, + // "192.168.1.12": { + // "streams": [ + // { + // "unitId": 18, + // "section": "", + // "name": 18488, + // "tb_value": "total_energy", + // "bytes": 2, + // "multiplier": 1, + // "month": 0 + // } + // ] + // } // } const tbNames = { - "192.168.1.11": { - "51": "1JMYvnx2RzKEo4aWQ7D93vAL8yZV3m9NBePXbrdj", // nový merák I-35, bez zóny - "16": "6lQGaY9RDywdVzObj0PZer7Pg4NBn3exEK51LWZq", // zmena adresy z 1 na 16, 13.5.2022 - "6A": "JzwxZXOvDj1bVrN4nkWeR8A8qdyBl3MRKLpGPgaQ", - "6B": "g9OxBZ5KRwNznlY6pApbGmkWXvjdEL4eGQobMDy2", - "7A": "OzNMgZ9n43qPbjXmy7zOgGA2DKdYvW5e6pxGRrVa", - "7B": "JX1ObgmqGZ54DMyYL7aJzJAEVdve38WKRzwjNrQ9", - "8A": "RvmwNz8QPblKp41GD7l4WK7JrLVYoBO92dMegn6W", - "8B": "RO8rjaBDy21qPQJzW7oKpD7pK3xmNleVZg9Ed4Gw", - "9": "3JjOWdylwgNLzxVab7NPjw0Z2vG64rq8PEB5QmDo", - "10A": "Z5KyJe9nEg1QNbWlX0wmnM7oDjBLdqzR83VGv624", - "10B": "1JMYvnx2RzKEo4aWQ7D9xzAL8yZV3m9NBePXbrdj", - "11A": "PjLblDgRBO6WQqnxmkJwga7Jv3ewZN4p5a89yKdY", - "11B": "dz4ojlpP85JMgDLZWkQ12jkaKYqQexEr62GXRV1y", - "12A": "d5xjWYMwEJon6rLlK7yl3wkqgV4DaOeNB9ZX3Gzb", - "12B": "gRoJEyXVx4qD9er287LwbOkwBzGldaPjLWQKm3Mv", - "13A": "K94XLav1glVRnyQ6r01V3Wkme3YJwBxM5oOzdP2j", - "13B": "d9x2V5LGYBzXp4mMRAOPr10PloaqJwnQj6DgrNe3", - "14A": "B5EoxeMVp4zwr8nqW0Gen57RjvD1PNamOGbLg63Z", - "14B": "aw4eELG2DlPMdn1JW0Bz4Z0qQXOZRN3xB5yp8VKr", - "15A": "ZmRwd93QL4gaezxEbAx1Xw01prn2XjlPvGyqJ6BO", - "15B": "eod9aRWLVl34Gx1Dn7VYmDk2rz6qjgmpEXwQJN5Z", - "5": "3a5oqJN1bgnx4Ol9dk8BdqAByE6jQ8mKDWMpGrLV", - "2A": "EjgWGnXaLy9opPOz20ngWQk86BlYM3w1deVQvbKr", - "2B": "wvKJdZML6mXP4DzWBAXOK87jxNloa5g23Ve9Y1ry", - "3A": "Nzp2OoJlqn6r1ZgvdA3RqE7abBwP5G4eE3RQmyxD", - "3B": "PLBJzmK1r3Gynd6OW0g2WzAe5wV4vx9bDEqNgYR8", - "4A": "52dD6ZlV1QaOpRBmbAqvWb0KnGzWMLj4eJq38Pgo", - "4B": "rDbQ84xzwgdqEoPm3kbPWWA9anOZY1RXyBv2LVM6", - "21A": "1558", - "21B": "1559" - // "36B": "vymyslene kvoli chybe" - }, - "192.168.1.12": { - "18": "m6EYyZoJ4gWexdjVPARapL7RDOq9wv2N5XzKGplr", - "2A": "E6Kg9oDnLWyzPRMva7vW8yAJxp4VG58qO2w1lZYe", - "2B": "roKgWqY95V3mXMRzyAjrW6AbLjexpJPvaGDBw826", - "3A": "nJL5lPMwBx23YpqRe0rqa4AdamXvWVbOrD4gNzy8", - "3B": "XMBbew5z4ELrZa2mRAdZW9k8vPN6gy3DdVYlpKjq", - "4A": "gYbDLqlyZVoRerQpB72GgvAWJnwM5z24POKa8Exj", - "4B": "zdQO8GwxDqjRgP4137Y5eo7NyKlpem2nL65rvVJY", - "5A": "5dBNwRp9graYJxZn409R28klVov1b2QLPDqGm6XK", - "5B": "JzwxZXOvDj1bVrN4nkWeZ8A8qdyBl3MRKLpGPgaQ", - "6A": "zrR51V2ajQ9ZLygPKkEPVW0YDq38xOJolENBXGnv", - "6B": "g9OxBZ5KRwNznlY6pApbymkWXvjdEL4eGQobMDy2", - "7A": "OzNMgZ9n43qPbjXmy7zOyGA2DKdYvW5e6pxGRrVa", - "7B": "JX1ObgmqGZ54DMyYL7aJZJAEVdve38WKRzwjNrQ9", - "8A": "RvmwNz8QPblKp41GD7l4yK7JrLVYoBO92dMegn6W", - "8B": "RO8rjaBDy21qPQJzW7oKyD7pK3xmNleVZg9Ed4Gw", - "9A": "3JjOWdylwgNLzxVab7NPxw0Z2vG64rq8PEB5QmDo", - "9B": "Z5KyJe9nEg1QNbWlX0wmyM7oDjBLdqzR83VGv624", - "10A": "1JMYvnx2RzKEo4aWQ7D9MzAL8yZV3m9NBePXbrdj", - "10B": "PjLblDgRBO6WQqnxmkJwea7Jv3ewZN4p5a89yKdY", - "11A": "WlVJBygjDZMeKX3vnAMWvLk8NqdmG2x1Y69LQ4P5", - "11B": "dz4ojlpP85JMgDLZWkQ1njkaKYqQexEr62GXRV1y", - "12A": "BaY3Xpy1EbKGjLq2O7m9W27rx8owgQz9P4dDJRmN", - "12B": "DbQY6zyveZRwK5drV0Zl4j7joE4XJM83N9xl2nWq", - "13A": "apKVJBwOyrP35m2lv7KEqd0YXbeWNd64En9GxRqg", - "13B": "o9vbeQlLMVg8j5dq4kedWy0NxZpEmnXzwYKO1ar2", - "14A": "gP1eOZVj3Q9lv5aDEk4MbP7rdpqW8yLm2BbKzJxM", - "14B": "2O14VBzl8aDmWdNw3A53vOkGyZ5qLJoEMpj6R9ng", - "15A": "pE5X8NQPaow6vlOZxk6Yjw0q42ezGBMyWgDVjR3L", - "15B": "d5xjWYMwEJon6rLlK7ylywkqgV4DaOeNB9ZX3Gzb", - "16A": "6lQGaY9RDywdVzObj0PZdr7Pg4NBn3exEK51LWZq", - "16B": "m6EYyZoJ4gWexdjVPARaYL7RDOq9wv2N5XzKGplr", - "17A": "gRoJEyXVx4qD9er287LwBOkwBzGldaPjLWQKm3Mv", - "17B": "K94XLav1glVRnyQ6r01VpWkme3YJwBxM5oOzdP2j" + "192.168.1.31": { + "3": "JX1ObgmqGZ54DMyYL7aJMlAEVdve38WKRzwjNrQ9", + "2": "RO8rjaBDy21qPQJzW7oKN17pK3xmNleVZg9Ed4Gw", + "11": "RvmwNz8QPblKp41GD7l4NY7JrLVYoBO92dMegn6W", + "12A": "K94XLav1glVRnyQ6r01VZ3kme3YJwBxM5oOzdP2j", + "12B": "3JjOWdylwgNLzxVab7NPpJ0Z2vG64rq8PEB5QmDo", + "13A": "Z5KyJe9nEg1QNbWlX0wmNP7oDjBLdqzR83VGv624", + "13B": "PjLblDgRBO6WQqnxmkJwpb7Jv3ewZN4p5a89yKdY", + "14A": "dz4ojlpP85JMgDLZWkQ1p3kaKYqQexEr62GXRV1y", + "14B": "d9x2V5LGYBzXp4mMRAOPpV0PloaqJwnQj6DgrNe3", + "15A": "1JMYvnx2RzKEo4aWQ7D9pXAL8yZV3m9NBePXbrdj", + "15B": "d5xjWYMwEJon6rLlK7ylNxkqgV4DaOeNB9ZX3Gzb", + "16": "gRoJEyXVx4qD9er287LwpEkwBzGldaPjLWQKm3Mv", + "21": "3JjOWdylwgNLzxVab7NPyn0Z2vG64rq8PEB5QmDo", + "22A": "Z5KyJe9nEg1QNbWlX0wmEB7oDjBLdqzR83VGv624", + "22B": "1JMYvnx2RzKEo4aWQ7D9y5AL8yZV3m9NBePXbrdj", + "23A": "PjLblDgRBO6WQqnxmkJwyr7Jv3ewZN4p5a89yKdY", + "23B": "dz4ojlpP85JMgDLZWkQ1GGkaKYqQexEr62GXRV1y", + "24A": "d5xjWYMwEJon6rLlK7ylZmkqgV4DaOeNB9ZX3Gzb", + "24B": "gRoJEyXVx4qD9er287LwyvkwBzGldaPjLWQKm3Mv" + // "76": "vymyslene pre testovanie" } }; - const meter51 = ["total_energy","phase_1_power","phase_2_power","phase_3_power","phase_1_voltage","phase_2_voltage", - "phase_3_voltage","phase_1_react_power","phase_2_react_power","phase_3_react_power","phase_1_apparent_power", - "phase_2_apparent_power","phase_3_apparent_power","total_active_power","total_reactive_power","total_apparent_power"]; - class SocketWithClients { @@ -223,7 +135,7 @@ exports.install = function(instance) { this.streams = data.streams; //pole this.startSocket(); - } + } startSocket = () => { @@ -240,14 +152,14 @@ exports.install = function(instance) { this.socket.on('error', function(e) { console.log('socket connection error', e); if(e.code == 'ECONNREFUSED' || e.code == 'ECONNRESET') { - console.log(exports.title + ' Waiting 1 minute before trying to connect again'); - setTimeout(obj.startSocket, 60000); + console.log(exports.title + ' Waiting 10 seconds before trying to connect again'); + setTimeout(obj.startSocket, 10000); } }); this.socket.on('close', function() { - console.log('Socket connection closed ' + exports.title + ' Waiting 1 minute before trying to connect again'); - setTimeout(obj.startSocket, 60000); + console.log('Socket connection closed ' + exports.title + ' Waiting 10 seconds before trying to connect again'); + setTimeout(obj.startSocket, 10000); }); // we create client for all modules (unitIds) and push them into dictionary @@ -286,7 +198,7 @@ exports.install = function(instance) { let date = Date.now(); let tbval = this.streams[this.index].tb_value; - // console.log("citam tieto hodnoty",unitId, register, tbval); + // console.log("citam tieto hodnoty", unitId, register, tbval); let obj = this; this.clients[unitId].readHoldingRegisters(register, bytes) @@ -303,10 +215,11 @@ exports.install = function(instance) { console.log("error pri citani z grafie", register, unitId, section, tbNames[obj.ip][unitId + section], tbval); - //! IMPLEMENTOVAT POSIELANIE CHYB PODLA POSLEDNHO REGISTRA V MODULE === "total_power_factor" + // IMPLEMENTOVAT POSIELANIE CHYB PODLA POSLEDNHO REGISTRA V MODULE === "total_power_factor" if(tbval === "total_power_factor") { obj.sendNokStatus(tbNames[obj.ip][unitId + section], date); + if(arguments["0"].err == "Offline") { obj.socket.emit("close"); @@ -314,7 +227,7 @@ exports.install = function(instance) { } } - //! POSIELANIE NOK STATUSU - posle sa az pri poslednom registri z daneho unitu, nie pri kazdej chybnej hlaske + // POSIELANIE NOK STATUSU - posle sa az pri poslednom registri z daneho unitu, nie pri kazdej chybnej hlaske // if(obj.index + 1 == lenghtOfStreams) // { // obj.sendNokStatus(tbNames[obj.ip][unitId + section], date); @@ -323,10 +236,10 @@ exports.install = function(instance) { // { // obj.sendNokStatus(tbNames[obj.ip][unitId + section], date); // } - - //console.error(require('util').inspect(arguments, { - // depth: null - //})) + + console.error(require('util').inspect(arguments, { + depth: null + })) obj.index++; setTimeout(obj.readRegisters, 0); @@ -372,8 +285,6 @@ exports.install = function(instance) { if(temp_val >= (2**31)) // ak je MSB bit nastavený, eventuálne sa dá použiť aj (temp_val & 0x80000000), ak vieš robiť logický súčin { - //temp_val = temp_val - 2**31; // odstránim MSB bit, eventuálne sa dá použiť aj (temp_val & 0x7FFFFFFF), ak vieš robiť logický súčin - //temp_val = temp_val * (-1); // spravím z toho zápornú hodnotu temp_val = temp_val - "0xFFFFFFFF" + 1; } } @@ -383,9 +294,7 @@ exports.install = function(instance) { if(temp_val >= (2**15)) // ak je MSB bit nastavený, eventuálne sa dá použiť aj (temp_val & 0x8000), ak vieš robiť logický súčin { - // temp_val = temp_val - 2**15; // odstránim MSB bit, eventuálne sa dá použiť aj (temp_val & 0x7FFF), ak vieš robiť logický súčin - // temp_val = temp_val * (-1); // spravím z toho zápornú hodnotu - temp_val = temp_val - "0xFFFF" + 1; + temp_val = temp_val - "0xFFFF" + 1; } } @@ -398,18 +307,16 @@ exports.install = function(instance) { if(tbName == undefined) return; - // we handle multimeter 51 values: - if voltage or power, we multiply with 55 - if(tbName == '1JMYvnx2RzKEo4aWQ7D93vAL8yZV3m9NBePXbrdj' && meter51.includes(tb_value)) value = parseFloat((value * 55).toFixed(2)); - const values = { "status": "OK", [tb_value]: value }; - // we send "energy_last_month" value, that is equal to "total_energy" value, on first day and first minute of new month ==> it means when month has changed + // we send "energy_last_month" value, that is equal to "total_energy" value, on first day of new month ==> it means when month changes if(tb_value == "total_energy") { + const previousEnergy = a.previousEnergy; a.previousEnergy = value; @@ -429,6 +336,7 @@ exports.install = function(instance) { } allModulesEnergy[this.ip + '@' + unitId + section] = value; + } @@ -448,8 +356,8 @@ exports.install = function(instance) { }; } - const newSocket = new SocketWithClients("192.168.1.11", conversionTable["192.168.1.11"]); - const newSocket2 = new SocketWithClients("192.168.1.12", conversionTable["192.168.1.12"]); + + const newSocket = new SocketWithClients("192.168.1.31", conversionTable["192.168.1.31"]); } diff --git a/flow/helper/DataToTbHandler.js b/flow/helper/DataToTbHandler.js new file mode 100644 index 0000000..8fff312 --- /dev/null +++ b/flow/helper/DataToTbHandler.js @@ -0,0 +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; + } +} + +module.exports = DataToTbHandler; \ No newline at end of file diff --git a/flow/helper/energo_streambuilder.js b/flow/helper/energo_streambuilder.js index 2136ab5..b1e37a9 100644 --- a/flow/helper/energo_streambuilder.js +++ b/flow/helper/energo_streambuilder.js @@ -150,7 +150,7 @@ const makeStreamsTable = (structure) => { const modul = structure[ip][item]; // console.log(modul) //i-35, i-60A ... - + let section = ""; if(modul == "i-60A") { @@ -169,7 +169,7 @@ const makeStreamsTable = (structure) => { const m = multiplier[tb_value]; if(isNaN(item)) item = item.slice(0,-1); - + const stream = { "unitId": parseInt(item), "section": section, @@ -177,7 +177,7 @@ const makeStreamsTable = (structure) => { "tb_value": tb_value, "bytes": b, "multiplier": m, - } + } if(tb_value == "total_energy") { @@ -197,11 +197,14 @@ const makeStreamsTable = (structure) => { }) return conversionTable; -}; +} + const getCurrentMonth = () => { const date = new Date(); return date.getMonth(); }; + + exports.makeStreamsTable = makeStreamsTable; \ No newline at end of file