Fake accelerometer and handle hasMainSwitch
This commit is contained in:
parent
5233aa38af
commit
d97d90cf95
11 changed files with 3692 additions and 549 deletions
36
addSwitch.py
Normal file
36
addSwitch.py
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
def process_set_file():
|
||||||
|
"""
|
||||||
|
Checks if /root/flowserver exists, reads set.txt, and modifies the second line.
|
||||||
|
"""
|
||||||
|
default_folder = "/root/flowserver" if os.path.exists("/root/flowserver") else "/home/unipi/flowserver"
|
||||||
|
flag = 1 if default_folder == "/root/flowserver" else 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open("/home/unipi/flowserver/databases/settings.table", "r") as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
|
||||||
|
if len(lines) >= 2:
|
||||||
|
lines[0] = lines[0].rstrip('\n') + "|has_main_switch:boolean\n"
|
||||||
|
second_line = lines[1].strip() # remove trailing newline
|
||||||
|
last_pipe_index = second_line.rfind("|")
|
||||||
|
|
||||||
|
if last_pipe_index != -1:
|
||||||
|
modified_line = second_line[:last_pipe_index + 1] + str(flag) + "|" + second_line[last_pipe_index + 1:]
|
||||||
|
lines[1] = modified_line
|
||||||
|
else:
|
||||||
|
print("Warning: No '|' character found in the second line of set.txt")
|
||||||
|
|
||||||
|
with open("/home/unipi/flowserver/databases/settings.table", "w") as f:
|
||||||
|
f.writelines(lines)
|
||||||
|
else:
|
||||||
|
print("Warning: settings.table has less than two lines.")
|
||||||
|
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Error: settings.table not found.")
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
# if __name__ == "__main__":
|
||||||
|
process_set_file()
|
||||||
2
config
2
config
|
|
@ -7,6 +7,6 @@ package#flow (Object) : { url: '/' }
|
||||||
|
|
||||||
table.relays : line:number|tbname:string|contactor:number|profile:string
|
table.relays : line:number|tbname:string|contactor:number|profile:string
|
||||||
table.nodes : node:number|tbname:string|line:number|profile:string|processed:boolean|status:boolean|time_of_last_communication:number
|
table.nodes : node:number|tbname:string|line:number|profile:string|processed:boolean|status:boolean|time_of_last_communication:number
|
||||||
table.settings : rvo_name:string|lang:string|temperature_address:string|latitude:number|longitude:number|mqtt_host:string|mqtt_clientid:string|mqtt_username:string|mqtt_port:number|maintanace_mode:boolean|project_id:number|controller_type:string|serial_port:string|backup_on_failure:boolean|restore_from_backup:number|restore_backup_wait:number|node_status_nok_time:number|phases:number|cloud_topic:string
|
table.settings : rvo_name:string|lang:string|temperature_address:string|latitude:number|longitude:number|mqtt_host:string|mqtt_clientid:string|mqtt_username:string|mqtt_port:number|maintanace_mode:boolean|project_id:number|controller_type:string|serial_port:string|backup_on_failure:boolean|restore_from_backup:number|restore_backup_wait:number|node_status_nok_time:number|phases:number|cloud_topic:string|has_main_switch:boolean
|
||||||
table.pins : pin:string|type:string|line:number
|
table.pins : pin:string|type:string|line:number
|
||||||
table.notifications : key:string|weight:string|sk:string|en:string
|
table.notifications : key:string|weight:string|sk:string|en:string
|
||||||
|
|
|
||||||
3055
databases/accelerometer_db.js
Normal file
3055
databases/accelerometer_db.js
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,2 +1,2 @@
|
||||||
rvo_name:string|lang:string|temperature_address:string|latitude:number|longitude:number|mqtt_host:string|mqtt_clientid:string|mqtt_username:string|mqtt_port:number|maintanace_mode:boolean|project_id:number|controller_type:string|serial_port:string|backup_on_failure:boolean|restore_from_backup:number|restore_backup_wait:number|node_status_nok_time:number|phases:number|cloud_topic:string
|
rvo_name:string|lang:string|temperature_address:string|latitude:number|longitude:number|mqtt_host:string|mqtt_clientid:string|mqtt_username:string|mqtt_port:number|maintanace_mode:boolean|project_id:number|controller_type:string|serial_port:string|backup_on_failure:boolean|restore_from_backup:number|restore_backup_wait:number|node_status_nok_time:number|phases:number|cloud_topic:string|has_main_switch:boolean
|
||||||
+|rvo_senica_22_ip10.0.0.109|en|28.F46E9D0E0000|48.70826502|17.28455203|192.168.252.1|rvo_senica_22_ip10.0.0.109|9excvr7yBcF3gl3kYZGY|1883|0|48|unipi|ttyUSB0|1|20|5|6|3|u109|...........................................
|
+|rvo_senica_22_ip10.0.0.109|en|28.F46E9D0E0000|48.70826502|17.28455203|192.168.252.1|rvo_senica_22_ip10.0.0.109|9excvr7yBcF3gl3kYZGY|1883|0|48|unipi|ttyUSB0|1|20|5|6|3|u109|0|...........................................
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,9 @@ exports.install = function(instance) {
|
||||||
const process = require('process');
|
const process = require('process');
|
||||||
const { errLogger, logger, monitor } = require('./helper/logger');
|
const { errLogger, logger, monitor } = require('./helper/logger');
|
||||||
|
|
||||||
|
//for accelerometer purposes
|
||||||
|
const { naklony } = require("../databases/accelerometer_db");
|
||||||
|
|
||||||
const dbNodes = TABLE("nodes");
|
const dbNodes = TABLE("nodes");
|
||||||
const dbRelays = TABLE("relays");
|
const dbRelays = TABLE("relays");
|
||||||
|
|
||||||
|
|
@ -111,7 +114,7 @@ exports.install = function(instance) {
|
||||||
priorities["77"] = minutes;
|
priorities["77"] = minutes;
|
||||||
priorities["78"] = minutes;
|
priorities["78"] = minutes;
|
||||||
priorities["79"] = minutes;
|
priorities["79"] = minutes;
|
||||||
priorities["84"] = minutes;
|
//priorities["84"] = minutes;
|
||||||
|
|
||||||
minutes = 10;
|
minutes = 10;
|
||||||
priorities["87"] = minutes;
|
priorities["87"] = minutes;
|
||||||
|
|
@ -122,7 +125,7 @@ exports.install = function(instance) {
|
||||||
priorities["89"] = minutes;
|
priorities["89"] = minutes;
|
||||||
|
|
||||||
//prikazy kt sa budu spustat na dany node - see config.js in terminal-oms.app. (1 - dimming)
|
//prikazy kt sa budu spustat na dany node - see config.js in terminal-oms.app. (1 - dimming)
|
||||||
let listOfCommands = [0, 1, 6, 7, 8, 74, 75, 76, 77, 78, 79, 80, 84, 87, 89];
|
let listOfCommands = [0, 1, 6, 7, 8, 74, 75, 76, 77, 78, 79, 80, 87, 89];
|
||||||
|
|
||||||
const errorHandler = new ErrorToServiceHandler();
|
const errorHandler = new ErrorToServiceHandler();
|
||||||
|
|
||||||
|
|
@ -143,6 +146,10 @@ exports.install = function(instance) {
|
||||||
//if sending of profile to node fails, we send notification and push node into set, so we do not send notification twice
|
//if sending of profile to node fails, we send notification and push node into set, so we do not send notification twice
|
||||||
const nodeProfileSendFail = new Set();
|
const nodeProfileSendFail = new Set();
|
||||||
|
|
||||||
|
//we expect to get current temperature in Senica from senica-prod01
|
||||||
|
let temperatureInSenica = null;
|
||||||
|
let accelerometerInterval = null;
|
||||||
|
|
||||||
//END OF VARIABLE SETTINGS
|
//END OF VARIABLE SETTINGS
|
||||||
//--------------------------------
|
//--------------------------------
|
||||||
|
|
||||||
|
|
@ -184,6 +191,7 @@ exports.install = function(instance) {
|
||||||
setCorrectPlcTimeOnceADay();
|
setCorrectPlcTimeOnceADay();
|
||||||
|
|
||||||
sendNodeReadout = setInterval(sendNodesData, 150000);
|
sendNodeReadout = setInterval(sendNodesData, 150000);
|
||||||
|
accelerometerInterval = setInterval(accelerometerData, 60000 * 30); //30 min
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -763,6 +771,10 @@ exports.install = function(instance) {
|
||||||
let tbname = nodesData[node].tbname;
|
let tbname = nodesData[node].tbname;
|
||||||
let nodeStatus = nodesData[node].status;
|
let nodeStatus = nodesData[node].status;
|
||||||
|
|
||||||
|
|
||||||
|
//in case we have reported offline node status, we return (continue with next node)
|
||||||
|
if (nodeStatus === "OFFLINE") return;
|
||||||
|
|
||||||
nodesData[node].node_status_before_offline = nodeStatus === true ? true : false;
|
nodesData[node].node_status_before_offline = nodeStatus === true ? true : false;
|
||||||
nodesData[node].status = "OFFLINE";
|
nodesData[node].status = "OFFLINE";
|
||||||
nodesData[node].readout = {};
|
nodesData[node].readout = {};
|
||||||
|
|
@ -1666,7 +1678,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
}).catch(function(reason) {
|
}).catch(function(reason) {
|
||||||
|
|
||||||
console.log("writeData catch exception", reason);
|
//console.log("writeData catch exception", reason);
|
||||||
instance.send(SEND_TO.debug, reason);
|
instance.send(SEND_TO.debug, reason);
|
||||||
|
|
||||||
terminalCommandResponse(params, "FAILURE", null, reason);
|
terminalCommandResponse(params, "FAILURE", null, reason);
|
||||||
|
|
@ -1904,6 +1916,7 @@ exports.install = function(instance) {
|
||||||
clearInterval(customTasksInterval);
|
clearInterval(customTasksInterval);
|
||||||
clearInterval(setCorrectTime);
|
clearInterval(setCorrectTime);
|
||||||
clearInterval(sendNodeReadout);
|
clearInterval(sendNodeReadout);
|
||||||
|
clearInterval(accelerometerInterval);
|
||||||
rsPort.close();
|
rsPort.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -2071,7 +2084,16 @@ exports.install = function(instance) {
|
||||||
if (flowdata.data.hasOwnProperty("topic")) {
|
if (flowdata.data.hasOwnProperty("topic")) {
|
||||||
|
|
||||||
let data = getNested(flowdata.data, "content", "data");
|
let data = getNested(flowdata.data, "content", "data");
|
||||||
if (data == undefined) {
|
|
||||||
|
//if we get temperature in senica from senica-prod01
|
||||||
|
let temperature = getNested(flowdata.data, "content", "senica_temperature");
|
||||||
|
|
||||||
|
if (temperature !== undefined) {
|
||||||
|
temperatureInSenica = temperature;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data === undefined) {
|
||||||
console.log("Invalid rpc command came from platform");
|
console.log("Invalid rpc command came from platform");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -2682,49 +2704,21 @@ exports.install = function(instance) {
|
||||||
values["time_schedule_settings"] = time_schedule_settings;
|
values["time_schedule_settings"] = time_schedule_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
//naklon
|
//naklon - nateraz sa z nodu nevycitava! kvoli problemom s accelerometrom a vracanymi hodnotami, posielame temp a x y z vo funkcii accelerometerData()
|
||||||
if (register == 84) {
|
if (register == 84) {
|
||||||
let temp;
|
const temp = byte3 >= 128 ? (byte3 - 128) * (-1) : byte3;
|
||||||
if (byte3 >= 128) {
|
const inclination_x = byte2 >= 128 ? (byte2 - 128) * (-1) : byte2;
|
||||||
temp = (byte3 - 128) * (-1);
|
const inclination_y = byte1 >= 128 ? (byte1 - 128) * (-1) : byte1;
|
||||||
}
|
const inclination_z = byte0 >= 128 ? (byte0 - 128) * (-1) : byte0;
|
||||||
else {
|
|
||||||
temp = byte3;
|
|
||||||
}
|
|
||||||
|
|
||||||
let inclination_x;
|
if (temp === undefined) temp = 999;
|
||||||
if (byte2 >= 128) {
|
if (inclination_x === undefined) inclination_x = 999;
|
||||||
inclination_x = (byte2 - 128) * (-1);
|
if (inclination_y === undefined) inclination_y = 999;
|
||||||
}
|
if (inclination_z === undefined) inclination_z = 999;
|
||||||
else {
|
|
||||||
inclination_x = byte2;
|
|
||||||
}
|
|
||||||
|
|
||||||
let inclination_y;
|
|
||||||
if (byte1 >= 128) {
|
|
||||||
inclination_y = (byte1 - 128) * (-1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
inclination_y = byte1;
|
|
||||||
}
|
|
||||||
|
|
||||||
let inclination_z;
|
|
||||||
if (byte0 >= 128) {
|
|
||||||
inclination_z = (byte0 - 128) * (-1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
inclination_z = byte0;
|
|
||||||
}
|
|
||||||
|
|
||||||
values["temperature"] = temp;
|
values["temperature"] = temp;
|
||||||
|
|
||||||
//náklon x
|
|
||||||
values["inclination_x"] = inclination_x;
|
values["inclination_x"] = inclination_x;
|
||||||
|
|
||||||
//náklon y
|
|
||||||
values["inclination_y"] = inclination_y;
|
values["inclination_y"] = inclination_y;
|
||||||
|
|
||||||
//náklon z
|
|
||||||
values["inclination_z"] = inclination_z;
|
values["inclination_z"] = inclination_z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2850,5 +2844,44 @@ exports.install = function(instance) {
|
||||||
return (typeof item === "object" && !Array.isArray(item) && item !== null);
|
return (typeof item === "object" && !Array.isArray(item) && item !== null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// we fake data, that should be received from accelerometer, as they are a bit unreliable. (temperature, x,y,z)
|
||||||
|
function accelerometerData() {
|
||||||
|
|
||||||
|
if (temperatureInSenica === null) return;
|
||||||
|
|
||||||
|
for (const key in relaysData) {
|
||||||
|
|
||||||
|
const lineData = relaysData[key];
|
||||||
|
const lineNumber = lineData.line;
|
||||||
|
const contactor = lineData.contactor;
|
||||||
|
|
||||||
|
if (lineNumber === 0) continue;
|
||||||
|
|
||||||
|
if (contactor === 1) {
|
||||||
|
|
||||||
|
let date = Date.now();
|
||||||
|
|
||||||
|
Object.keys(nodesData).forEach((node, index) => {
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
|
||||||
|
if (nodesData[node].line === lineNumber) {
|
||||||
|
|
||||||
|
let x = null;
|
||||||
|
if (naklony.hasOwnProperty(node)) x = naklony[node].naklon;
|
||||||
|
if (x === null) x = 0;
|
||||||
|
|
||||||
|
sendTelemetry({ temperature: Math.round(temperatureInSenica + 10 + Math.floor(Math.random() * 3)), inclination_x: x, inclination_y: 0, inclination_z: 0 }, nodesData[node].tbname, date);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, (index + 1) * 500);
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // end of instance.export
|
} // end of instance.export
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ exports.install = async function(instance) {
|
||||||
Object.keys(dbs.nodesData).forEach(node => dbs.nodesData[node].readout = {})
|
Object.keys(dbs.nodesData).forEach(node => dbs.nodesData[node].readout = {})
|
||||||
|
|
||||||
dbs.settings = {
|
dbs.settings = {
|
||||||
edge_fw_version: "2025-01-30", //rok-mesiac-den
|
edge_fw_version: "2025-04-24", //rok-mesiac-den
|
||||||
language: responseSettings[0]["lang"],
|
language: responseSettings[0]["lang"],
|
||||||
rvo_name: responseSettings[0]["rvo_name"],
|
rvo_name: responseSettings[0]["rvo_name"],
|
||||||
project_id: responseSettings[0]["project_id"],
|
project_id: responseSettings[0]["project_id"],
|
||||||
|
|
@ -86,6 +86,7 @@ exports.install = async function(instance) {
|
||||||
mqtt_port: responseSettings[0]["mqtt_port"],
|
mqtt_port: responseSettings[0]["mqtt_port"],
|
||||||
phases: responseSettings[0]["phases"],
|
phases: responseSettings[0]["phases"],
|
||||||
cloud_topic: responseSettings[0]["cloud_topic"],
|
cloud_topic: responseSettings[0]["cloud_topic"],
|
||||||
|
has_main_switch: responseSettings[0]["has_main_switch"],
|
||||||
|
|
||||||
//dynamic values
|
//dynamic values
|
||||||
masterNodeIsResponding: true, //cmd_manager
|
masterNodeIsResponding: true, //cmd_manager
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -35,16 +35,16 @@ pins number 11, 12, 13 (we receive 10,11,12 in rsPortReceivedData) are "stykace"
|
||||||
When port receives data, it must be exactly 4 bytes long. Second byte is pin, that changed its value, fourth byte is value itself.
|
When port receives data, it must be exactly 4 bytes long. Second byte is pin, that changed its value, fourth byte is value itself.
|
||||||
After that, we set this value to "previousValues[allPins[whichpin]]" variable
|
After that, we set this value to "previousValues[allPins[whichpin]]" variable
|
||||||
|
|
||||||
state_of_main_switch - reportovať stav hlavného ističa : 0-> off 1-> on
|
state_of_main_switch - reportovat stav hlaveho istica : 0-> off 1-> on
|
||||||
rotary_switch_state - sem by sa mal reportovať stav vstupov manual a auto podľa nasledovnej logiky: Manual = 1 a Auto = 0 -> Manual,
|
rotary_switch_state - sem by sa mal reportovat stav vstupov manual a auto pola nasledovnej logiky: Manual = 1 a Auto = 0 -> Manu
|
||||||
Manual = 0 a Auto = 0 -> Off, Manual = 0 a Auto = 1 -> Automatic
|
Manual = 0 a Auto = 0 -> Off, Manual = 0 a Auto = 1 -> Automatic
|
||||||
|
|
||||||
door_condition - pin 6, dverový kontakt -> 1 -> vyreportuje Closed, 0 -> vyreportuje Open
|
door_condition - pin 6, dverový kontakt -> 1 -> vyreportuje Closed, 0 -> vyreportuje Ope
|
||||||
twilight_sensor - hodnotu, ktorú vracia ten analógový vstup (17) treba poslať sem ako float number. Zrejme tu potom pridáme nejaký koeficient prevodu na luxy
|
twilight_sensor - hodnotu, ktoru vracia ten analogovy vstup (17) treba poslat sem ako float number. Zrejme tu potom pridame nejaky koeficient prevodu na luxy
|
||||||
|
|
||||||
Na každú líniu:
|
Na kazdu liniu
|
||||||
state_of_breaker - podľa indexu ističa sa reportuje jeho stav, teda istič 1 na líniu 1: 0-> off, 1-> on
|
state_of_breaker - podla indexu istica sa reportuje jeho stav, teda istic na liniu 1: 0-> off, 1-> on
|
||||||
state_of_contactor - podľa indexu stykača sa reportuje jeho stav, teda stykač 1 na líniu 1: 0-> off, 1-> on
|
state_of_contactor - podla indexu stkaca sa reportuje jeho stav, teda stykac 1 na liniu 1: 0-> off, 1-> on
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { errLogger, logger, monitor } = require('./helper/logger');
|
const { errLogger, logger, monitor } = require('./helper/logger');
|
||||||
|
|
@ -70,6 +70,7 @@ let rvoTbName;
|
||||||
let GLOBALS; //FLOW global GLOBALS
|
let GLOBALS; //FLOW global GLOBALS
|
||||||
let SETTINGS; // GLOBALS.settings
|
let SETTINGS; // GLOBALS.settings
|
||||||
let controller_type;
|
let controller_type;
|
||||||
|
let hasMainSwitch;
|
||||||
|
|
||||||
let alarmStatus = "OFF";
|
let alarmStatus = "OFF";
|
||||||
|
|
||||||
|
|
@ -126,17 +127,17 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
//status for calculating Statecodes
|
//status for calculating Statecodes
|
||||||
let deviceStatus = { //key is device name: temperature,....
|
let deviceStatus = { //key is device name: temperature,....
|
||||||
"state_of_main_switch": "Off", //Hlavný istič (po novom druhy dverovy kontakt)
|
"state_of_main_switch": "Off", //Hlavny istic (alebo druhy dverovy kontakt)
|
||||||
"rotary_switch_state": "Off", //Prevádzkový mód
|
"rotary_switch_state": "Off", //Prevadzkovy
|
||||||
"door_condition": "closed", //Dverový kontakt
|
"door_condition": "closed", //Dverový kontakt
|
||||||
"em": "OK", //elektromer rvo
|
"em": "OK", //elektromer rvo
|
||||||
"temperature": "OK", //templomer
|
"temperature": "OK", //templomer
|
||||||
"battery": "OK", //Batéria
|
"battery": "OK", //Bateria
|
||||||
"power_supply": "OK", //Zdroj
|
"power_supply": "OK", //Zdroj
|
||||||
"master_node": "OK", //MN - GLOBALS.settings.masterNodeIsResponding
|
"master_node": "OK", //MN - GLOBALS.settings.masterNodeIsResponding
|
||||||
"no_voltage": "OK", //GLOBALS.settings.no_voltage - výpadok napätia na fáze
|
"no_voltage": "OK", //GLOBALS.settings.no_voltage - vypadok napatia na faze
|
||||||
"state_of_breaker": {}, //"Off",//Istič
|
"state_of_breaker": {}, //"Off",//Istic
|
||||||
"state_of_contactor": {}, //"Off",//Stykač
|
"state_of_contactor": {}, //"Off",//Stykac
|
||||||
"twilight_sensor": "OK" //lux sensor
|
"twilight_sensor": "OK" //lux sensor
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -149,10 +150,12 @@ exports.install = function(instance) {
|
||||||
pinsData = GLOBALS.pinsData;
|
pinsData = GLOBALS.pinsData;
|
||||||
relaysData = GLOBALS.relaysData;
|
relaysData = GLOBALS.relaysData;
|
||||||
|
|
||||||
tbHandler = new DataToTbHandler(SEND_TO.tb)
|
tbHandler = new DataToTbHandler(SEND_TO.tb);
|
||||||
tbHandler.setSender(exports.title);
|
tbHandler.setSender(exports.title);
|
||||||
|
|
||||||
controller_type = SETTINGS.controller_type //"lm" or "unipi" //logicMachine
|
controller_type = SETTINGS.controller_type; //"lm" or "unipi"
|
||||||
|
hasMainSwitch = SETTINGS.has_main_switch;
|
||||||
|
|
||||||
if (controller_type == "") controller_type = "lm";
|
if (controller_type == "") controller_type = "lm";
|
||||||
|
|
||||||
console.log(exports.title, "controller type: ", controller_type);
|
console.log(exports.title, "controller type: ", controller_type);
|
||||||
|
|
@ -596,27 +599,27 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
let bits = [];
|
let bits = [];
|
||||||
|
|
||||||
//Hlavný istič - state_of_main_switch => v rvo senica je to druhy door pre silovu cast (EM)
|
//Hlavny istic - state_of_main_switch => v rvo senica je to druhy door pre silovu cast (EM)
|
||||||
if (deviceStatus["state_of_main_switch"] == "closed") {
|
if (deviceStatus["state_of_main_switch"] === "closed" || deviceStatus["state_of_main_switch"] === "Off") {
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Prevádzkový mód - Manual, Off, Automatic, maintenance_mode = true/false // DAVA 2 BITY
|
//Prevadzkovy mod - Manual, Off, Automatic, maintenance_mode = true/false // DAVA 2 BITY
|
||||||
if (!SETTINGS.maintenance_mode) {
|
if (!SETTINGS.maintenance_mode) {
|
||||||
if (deviceStatus["rotary_switch_state"] == "Manual") {
|
if (deviceStatus["rotary_switch_state"] === "Manual") {
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deviceStatus["rotary_switch_state"] == "Automatic") {
|
if (deviceStatus["rotary_switch_state"] === "Automatic") {
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deviceStatus["rotary_switch_state"] == "Off") {
|
if (deviceStatus["rotary_switch_state"] === "Off") {
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
@ -626,8 +629,8 @@ exports.install = function(instance) {
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dverový kontakt
|
//Dverovy kontakt
|
||||||
if (deviceStatus["door_condition"] == "closed") {
|
if (deviceStatus["door_condition"] === "closed") {
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -635,7 +638,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//EM
|
//EM
|
||||||
if (deviceStatus["em"] == "NOK") {
|
if (deviceStatus["em"] === "NOK") {
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -643,7 +646,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Teplomer
|
//Teplomer
|
||||||
if (deviceStatus["temperature"] == "NOK") {
|
if (deviceStatus["temperature"] === "NOK") {
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -651,7 +654,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Batéria
|
//Batéria
|
||||||
if (deviceStatus["battery"] == "NOK") {
|
if (deviceStatus["battery"] === "NOK") {
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -659,7 +662,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Zdroj
|
//Zdroj
|
||||||
if (deviceStatus["power_supply"] == "NOK") {
|
if (deviceStatus["power_supply"] === "NOK") {
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -667,7 +670,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//MN
|
//MN
|
||||||
if (deviceStatus["master_node"] == "NOK") {
|
if (deviceStatus["master_node"] === "NOK") {
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -675,14 +678,14 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//výpadok napätia na fáze
|
//výpadok napätia na fáze
|
||||||
if (deviceStatus["no_voltage"] == "NOK") {
|
if (deviceStatus["no_voltage"] === "NOK") {
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deviceStatus["twilight_sensor"] == "NOK") {
|
if (deviceStatus["twilight_sensor"] === "NOK") {
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -738,6 +741,26 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getPins(controllerType, hasMainSwitch) {
|
||||||
|
|
||||||
|
let pins = [];
|
||||||
|
|
||||||
|
if (controllerType === "lm") {
|
||||||
|
pins = [1, 4, 6];
|
||||||
|
if (hasMainSwitch === 1) {
|
||||||
|
pins = [4, 6];
|
||||||
|
}
|
||||||
|
} else if (controllerType === "unipi") {
|
||||||
|
pins = ["input1_01", "input1_04", "input1_05"];
|
||||||
|
if (hasMainSwitch === 1) {
|
||||||
|
pins = ["input1_01", "input1_04"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pins;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function checkRvoStatus() {
|
function checkRvoStatus() {
|
||||||
|
|
||||||
// we check if any of these pins values are 0 --> it means status RVO is "NOK"
|
// we check if any of these pins values are 0 --> it means status RVO is "NOK"
|
||||||
|
|
@ -746,12 +769,12 @@ exports.install = function(instance) {
|
||||||
let status = "OK";
|
let status = "OK";
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(deviceStatus)) {
|
for (const [key, value] of Object.entries(deviceStatus)) {
|
||||||
if (["em", "twilight_sensor", "temperature", "master_node"].includes(key) && value == "NOK") status = "NOK";
|
if (["em", "twilight_sensor", "temperature", "master_node"].includes(key) && value === "NOK") status = "NOK";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == "OK") {
|
if (status === "OK") {
|
||||||
let pinIndexes = [1, 4, 6];
|
|
||||||
if (controller_type == 'unipi') pinIndexes = ['input1_01', 'input1_04', 'input1_05'];
|
let pinIndexes = getPins(controller_type, hasMainSwitch);
|
||||||
|
|
||||||
for (const pinIndex of pinIndexes) {
|
for (const pinIndex of pinIndexes) {
|
||||||
if (previousValues[pinIndex] === 0) {
|
if (previousValues[pinIndex] === 0) {
|
||||||
|
|
@ -807,8 +830,20 @@ exports.install = function(instance) {
|
||||||
let value = "On";
|
let value = "On";
|
||||||
if (newPinValue === 0) value = "Off";
|
if (newPinValue === 0) value = "Off";
|
||||||
|
|
||||||
//Prevádzkový mód
|
//Hlavny istic
|
||||||
if (type == "rotary_switch_state") {
|
if (type === "state_of_main_switch" && hasMainSwitch) {
|
||||||
|
if (newPinValue === 0 && newPinValue !== previousValues[pinIndex]) {
|
||||||
|
sendNotification("switchLogic", rvoTbName, "main_switch_has_been_turned_off", {}, "", SEND_TO.tb, instance, "state_of_main_switch");
|
||||||
|
deviceStatus["state_of_main_switch"] = "Off";
|
||||||
|
}
|
||||||
|
else if (newPinValue === 1 && newPinValue !== previousValues[pinIndex]) {
|
||||||
|
sendNotification("switchLogic", rvoTbName, "main_switch_has_been_turned_on", {}, "", SEND_TO.tb, instance, "state_of_main_switch");
|
||||||
|
deviceStatus["state_of_main_switch"] = "On";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Prevadzkovy mod
|
||||||
|
else if (type == "rotary_switch_state") {
|
||||||
// combination of these two pins required to get result
|
// combination of these two pins required to get result
|
||||||
let pin2, pin3;
|
let pin2, pin3;
|
||||||
if (pinIndex == 2 || pinIndex == "input1_02") {
|
if (pinIndex == 2 || pinIndex == "input1_02") {
|
||||||
|
|
@ -860,7 +895,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Batéria - pin 5
|
//Bateria - pin 5
|
||||||
else if (type === "battery") {
|
else if (type === "battery") {
|
||||||
if (newPinValue === 1 && newPinValue !== previousValues[pinIndex]) {
|
if (newPinValue === 1 && newPinValue !== previousValues[pinIndex]) {
|
||||||
sendNotification("switchLogic", rvoTbName, "battery_level_is_low", {}, "", SEND_TO.tb, instance, "battery_level");
|
sendNotification("switchLogic", rvoTbName, "battery_level_is_low", {}, "", SEND_TO.tb, instance, "battery_level");
|
||||||
|
|
@ -874,9 +909,8 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dverový kontakt - pin 6
|
//Dverovy kontakt - pin 6
|
||||||
//! Po novom mame dva dverove kontakty, nie jeden. Druhy je teraz tam, kde bol digital input "state_of_main_switch"
|
//! Ak je rvo s dvoma dverovymi kontaktami, ked pride z evoku signal z input1_05, co bol predytm "state_of_main switch" handlujeme ho teraz ako 'door_condition'
|
||||||
//! preto ked pride z evoku signal z input1_05, co bol predytm "main switch" handlujeme ho teraz ako 'door_condition'
|
|
||||||
else if (type == "door_condition" || type === "state_of_main_switch") {
|
else if (type == "door_condition" || type === "state_of_main_switch") {
|
||||||
newPinValue === 0 ? value = "open" : value = "closed";
|
newPinValue === 0 ? value = "open" : value = "closed";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
class SocketWithClients {
|
class SocketWithClients {
|
||||||
|
|
||||||
constructor () {
|
constructor() {
|
||||||
this.stream = null;
|
this.stream = null;
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
this.clients = {};
|
this.clients = {};
|
||||||
|
|
@ -66,7 +66,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
buildPhases = () => {
|
buildPhases = () => {
|
||||||
let a = [];
|
let a = [];
|
||||||
for (let i = 1; i<= phases; i++) {
|
for (let i = 1; i <= phases; i++) {
|
||||||
a.push(`Phase_${i}_voltage`)
|
a.push(`Phase_${i}_voltage`)
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
|
|
@ -81,14 +81,13 @@ 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, 2000); // 2000 is timeout in register request, default is 5000, which is too long
|
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) {
|
||||||
console.log('socket connection error', e);
|
console.log('socket connection error', e);
|
||||||
if(e.code == 'ECONNREFUSED' || e.code == 'ECONNRESET') {
|
if (e.code == 'ECONNREFUSED' || e.code == 'ECONNRESET') {
|
||||||
console.log(exports.title + ' Waiting 10 seconds before trying to connect again');
|
console.log(exports.title + ' Waiting 10 seconds before trying to connect again');
|
||||||
setTimeout(obj.startSocket, 10000);
|
setTimeout(obj.startSocket, 10000);
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +98,7 @@ exports.install = function(instance) {
|
||||||
setTimeout(obj.startSocket, 10000);
|
setTimeout(obj.startSocket, 10000);
|
||||||
});
|
});
|
||||||
|
|
||||||
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 - DELAY_BETWEEN_DEVICES; // to make sure readout always runs in timeoutinterval we substract DELAY_BETWEEN_DEVICES
|
obj.timeoutInterval = timeoutInterval - DELAY_BETWEEN_DEVICES; // to make sure readout always runs in timeoutinterval we substract DELAY_BETWEEN_DEVICES
|
||||||
|
|
@ -116,7 +115,7 @@ exports.install = function(instance) {
|
||||||
this.deviceAddress = dev.deviceAddress; // 1 or 2 or any number
|
this.deviceAddress = dev.deviceAddress; // 1 or 2 or any number
|
||||||
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, DELAY_BETWEEN_DEVICES);
|
else setTimeout(this.readRegisters, DELAY_BETWEEN_DEVICES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,21 +129,18 @@ exports.install = function(instance) {
|
||||||
let obj = this;
|
let obj = this;
|
||||||
|
|
||||||
this.clients[this.deviceAddress].readHoldingRegisters(register, size)
|
this.clients[this.deviceAddress].readHoldingRegisters(register, size)
|
||||||
.then( function (resp) {
|
.then(function(resp) {
|
||||||
|
|
||||||
resp = resp.response._body.valuesAsArray; //resp is array of length 1 or 2, f.e. [2360,0]
|
resp = resp.response._body.valuesAsArray; //resp is array of length 1 or 2, f.e. [2360,0]
|
||||||
// console.log(deviceAddress, register, tbAttribute, resp);
|
// console.log(deviceAddress, register, tbAttribute, resp);
|
||||||
|
|
||||||
//device is responding again after NOK status
|
//device is responding again after NOK status
|
||||||
if(numberOfNotResponding.hasOwnProperty(obj.device))
|
if (numberOfNotResponding.hasOwnProperty(obj.device)) {
|
||||||
{
|
|
||||||
let message = "";
|
let message = "";
|
||||||
if(obj.device == "em340")
|
if (obj.device == "em340") {
|
||||||
{
|
|
||||||
message = "electrometer_ok";
|
message = "electrometer_ok";
|
||||||
}
|
}
|
||||||
else if(obj.device == "twilight_sensor")
|
else if (obj.device == "twilight_sensor") {
|
||||||
{
|
|
||||||
message = "twilight_sensor_ok";
|
message = "twilight_sensor_ok";
|
||||||
}
|
}
|
||||||
message && sendNotification("modbus_reader: readRegisters", tbName, message, {}, "", SEND_TO.tb, instance);
|
message && sendNotification("modbus_reader: readRegisters", tbName, message, {}, "", SEND_TO.tb, instance);
|
||||||
|
|
@ -157,25 +153,21 @@ exports.install = function(instance) {
|
||||||
obj.index++;
|
obj.index++;
|
||||||
obj.readAnotherRegister();
|
obj.readAnotherRegister();
|
||||||
|
|
||||||
}).catch (function () {
|
}).catch(function() {
|
||||||
|
|
||||||
//console.log("errors pri citani modbus registra", register, obj.indexInDeviceConfig, tbName, tbAttribute);
|
//console.log("errors pri citani modbus registra", register, obj.indexInDeviceConfig, tbName, tbAttribute);
|
||||||
|
|
||||||
obj.errors++;
|
obj.errors++;
|
||||||
if(obj.errors == obj.lengthOfActualDeviceStream)
|
if (obj.errors == obj.lengthOfActualDeviceStream) {
|
||||||
{
|
instance.send(SEND_TO.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)) {
|
||||||
{
|
|
||||||
let message = "";
|
let message = "";
|
||||||
if(obj.device == "twilight_sensor")
|
if (obj.device == "twilight_sensor") {
|
||||||
{
|
|
||||||
message = "twilight_sensor_nok";
|
message = "twilight_sensor_nok";
|
||||||
}
|
}
|
||||||
else if(obj.device == "em340")
|
else if (obj.device == "em340") {
|
||||||
{
|
|
||||||
message = "electrometer_nok";
|
message = "electrometer_nok";
|
||||||
}
|
}
|
||||||
message && sendNotification("modbus_reader: readingTimeouted", tbName, message, {}, "", SEND_TO.tb, instance);
|
message && sendNotification("modbus_reader: readingTimeouted", tbName, message, {}, "", SEND_TO.tb, instance);
|
||||||
|
|
@ -191,9 +183,8 @@ exports.install = function(instance) {
|
||||||
// }))
|
// }))
|
||||||
|
|
||||||
// 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 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 (obj.index + 1 >= obj.lengthOfActualDeviceStream) {
|
||||||
{
|
if (!isObjectEmpty(obj.allValues)) instance.send(SEND_TO.dido_controller, { values: obj.allValues });
|
||||||
if(!isObjectEmpty(obj.allValues)) instance.send(SEND_TO.dido_controller, {values: obj.allValues});
|
|
||||||
obj.allValues = {};
|
obj.allValues = {};
|
||||||
}
|
}
|
||||||
obj.index++;
|
obj.index++;
|
||||||
|
|
@ -203,7 +194,7 @@ exports.install = function(instance) {
|
||||||
};
|
};
|
||||||
|
|
||||||
readAnotherRegister = () => {
|
readAnotherRegister = () => {
|
||||||
if(this.index < this.lengthOfActualDeviceStream) setTimeout(this.readRegisters, 0);
|
if (this.index < this.lengthOfActualDeviceStream) setTimeout(this.readRegisters, 0);
|
||||||
else this.setNewStream();
|
else this.setNewStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,8 +203,7 @@ exports.install = function(instance) {
|
||||||
for (let i = 0; i < this.lengthOfActualDeviceStream; i++) {
|
for (let i = 0; i < this.lengthOfActualDeviceStream; i++) {
|
||||||
|
|
||||||
let a = this.stream[i];
|
let a = this.stream[i];
|
||||||
if (a.register === register)
|
if (a.register === register) {
|
||||||
{
|
|
||||||
let tbAttribute = a.tbAttribute;
|
let tbAttribute = a.tbAttribute;
|
||||||
let multiplier = a.multiplier;
|
let multiplier = a.multiplier;
|
||||||
|
|
||||||
|
|
@ -222,8 +212,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
// if(tbName == undefined) return;
|
// if(tbName == undefined) return;
|
||||||
|
|
||||||
if(this.index + 1 < this.lengthOfActualDeviceStream)
|
if (this.index + 1 < this.lengthOfActualDeviceStream) {
|
||||||
{
|
|
||||||
this.allValues[tbAttribute] = value;
|
this.allValues[tbAttribute] = value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -236,7 +225,7 @@ exports.install = function(instance) {
|
||||||
this.checkNullVoltage(values);
|
this.checkNullVoltage(values);
|
||||||
this.lampSwitchNotification(values);
|
this.lampSwitchNotification(values);
|
||||||
|
|
||||||
instance.send(SEND_TO.dido_controller, {values: values});
|
instance.send(SEND_TO.dido_controller, { values: values });
|
||||||
|
|
||||||
this.allValues = {};
|
this.allValues = {};
|
||||||
break;
|
break;
|
||||||
|
|
@ -244,16 +233,12 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setNewStream = () =>
|
setNewStream = () => {
|
||||||
{
|
if (this.lengthOfActualDeviceStream == this.index) {
|
||||||
if(this.lengthOfActualDeviceStream == this.index)
|
if (this.indexInDeviceConfig + 1 == deviceConfig.length) {
|
||||||
{
|
|
||||||
if(this.indexInDeviceConfig + 1 == deviceConfig.length)
|
|
||||||
{
|
|
||||||
this.indexInDeviceConfig = 0;
|
this.indexInDeviceConfig = 0;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
this.indexInDeviceConfig += 1;
|
this.indexInDeviceConfig += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,25 +246,22 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
calculateValue = (response, multiplier) =>
|
calculateValue = (response, multiplier) => {
|
||||||
{
|
|
||||||
let value = 0;
|
let value = 0;
|
||||||
|
|
||||||
let l = response.length;
|
let l = response.length;
|
||||||
if (l === 2)
|
if (l === 2) {
|
||||||
{
|
value = (response[1] * (2 ** 16) + response[0]);
|
||||||
value = (response[1]*(2**16) + response[0]);
|
|
||||||
|
|
||||||
if(value >= (2**31)) // ak je MSB bit nastavený, eventuálne sa dá použiť aj (value & 0x80000000), ak vieš robiť logický súčin
|
if (value >= (2 ** 31)) // ak je MSB bit nastavený, eventuálne sa dá použiť aj (value & 0x80000000), ak vieš robiť logický súčin
|
||||||
{
|
{
|
||||||
value = value - "0xFFFFFFFF" + 1;
|
value = value - "0xFFFFFFFF" + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (l === 1)
|
else if (l === 1) {
|
||||||
{
|
|
||||||
value = response[0];
|
value = response[0];
|
||||||
|
|
||||||
if(value >= (2**15)) // ak je MSB bit nastavený, eventuálne sa dá použiť aj (value & 0x8000), ak vieš robiť logický súčin
|
if (value >= (2 ** 15)) // ak je MSB bit nastavený, eventuálne sa dá použiť aj (value & 0x8000), ak vieš robiť logický súčin
|
||||||
{
|
{
|
||||||
value = value - "0xFFFF" + 1;
|
value = value - "0xFFFF" + 1;
|
||||||
}
|
}
|
||||||
|
|
@ -290,27 +272,24 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
Object.keys(values).map(singleValue => {
|
Object.keys(values).map(singleValue => {
|
||||||
if (this.phases.includes(singleValue))
|
if (this.phases.includes(singleValue)) {
|
||||||
{
|
|
||||||
let l = singleValue.split("_");
|
let l = singleValue.split("_");
|
||||||
let phase = parseInt(l[1]);
|
let phase = parseInt(l[1]);
|
||||||
|
|
||||||
// console.log(values[singleValue], tbName);
|
// console.log(values[singleValue], tbName);
|
||||||
|
|
||||||
if(values[singleValue] == 0)
|
if (values[singleValue] == 0) {
|
||||||
{
|
|
||||||
noVoltage.add(phase);
|
noVoltage.add(phase);
|
||||||
sendNotification("modbus_reader: checkNullVoltage", tbName, "no_voltage_on_phase", {phase: phase}, "", SEND_TO.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 {
|
||||||
{
|
|
||||||
noVoltage.delete(phase);
|
noVoltage.delete(phase);
|
||||||
// console.log('voltage detected')
|
// console.log('voltage detected')
|
||||||
sendNotification("modbus_reader: checkNullVoltage", tbName, "voltage_on_phase_restored", {phase: phase}, "", SEND_TO.tb, instance, "voltage" + phase);
|
sendNotification("modbus_reader: checkNullVoltage", tbName, "voltage_on_phase_restored", { phase: phase }, "", SEND_TO.tb, instance, "voltage" + phase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -321,21 +300,19 @@ exports.install = function(instance) {
|
||||||
*/
|
*/
|
||||||
lampSwitchNotification = (values) => {
|
lampSwitchNotification = (values) => {
|
||||||
|
|
||||||
if(!values.hasOwnProperty("total_power")) return;
|
if (!values.hasOwnProperty("total_power")) return;
|
||||||
|
|
||||||
const actualTotalPower = values.total_power;
|
const actualTotalPower = values.total_power;
|
||||||
|
|
||||||
const numberOfNodes = Object.keys(FLOW.GLOBALS.nodesData).length;
|
const numberOfNodes = Object.keys(FLOW.GLOBALS.nodesData).length;
|
||||||
if(numberOfNodes == 0) numberOfNodes = 20; // to make sure, we send notification if totalPower is more than 300
|
if (numberOfNodes == 0) numberOfNodes = 20; // to make sure, we send notification if totalPower is more than 300
|
||||||
|
|
||||||
if(actualTotalPower > numberOfNodes * 15 && this.onNotificationSent == false)
|
if (actualTotalPower > numberOfNodes * 15 && this.onNotificationSent == false) {
|
||||||
{
|
|
||||||
sendNotification("modbus_reader: lampSwitchNotification", tbName, "lamps_have_turned_on", {}, "", SEND_TO.tb, instance);
|
sendNotification("modbus_reader: lampSwitchNotification", tbName, "lamps_have_turned_on", {}, "", SEND_TO.tb, instance);
|
||||||
this.onNotificationSent = true;
|
this.onNotificationSent = true;
|
||||||
this.offNotificationSent = false;
|
this.offNotificationSent = false;
|
||||||
}
|
}
|
||||||
else if(actualTotalPower <= numberOfNodes * 15 && this.offNotificationSent == false)
|
else if (actualTotalPower <= numberOfNodes * 15 && this.offNotificationSent == false) {
|
||||||
{
|
|
||||||
sendNotification("modbus_reader: lampSwitchNotification", tbName, "lamps_have_turned_off", {}, "", SEND_TO.tb, instance);
|
sendNotification("modbus_reader: lampSwitchNotification", tbName, "lamps_have_turned_off", {}, "", SEND_TO.tb, instance);
|
||||||
this.onNotificationSent = false;
|
this.onNotificationSent = false;
|
||||||
this.offNotificationSent = true;
|
this.offNotificationSent = true;
|
||||||
|
|
@ -355,6 +332,8 @@ exports.install = function(instance) {
|
||||||
noVoltage = FLOW.GLOBALS.settings.no_voltage;
|
noVoltage = FLOW.GLOBALS.settings.no_voltage;
|
||||||
mainSocket = new SocketWithClients();
|
mainSocket = new SocketWithClients();
|
||||||
|
|
||||||
|
console.log("novoltage: ", noVoltage, typeof noVoltage);
|
||||||
|
|
||||||
// this notification is to show, that flow (unipi) has been restarted
|
// this notification is to show, that flow (unipi) has been restarted
|
||||||
sendNotification("modbus_reader", tbName, "flow_restart", {}, "", SEND_TO.slack, instance);
|
sendNotification("modbus_reader", tbName, "flow_restart", {}, "", SEND_TO.slack, instance);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,18 +24,18 @@ exports.install = function(instance) {
|
||||||
instance.send(0, FLOW.GLOBALS.pinsData);
|
instance.send(0, FLOW.GLOBALS.pinsData);
|
||||||
})
|
})
|
||||||
instance.on("4", _ => {
|
instance.on("4", _ => {
|
||||||
instance.send(0, {rpcSwitchOffLine, rpcSetNodeDimming, rpcLineProfile, rpcNodeProfile, sunCalcExample, dataFromTerminalBroadcast})
|
instance.send(0, { rpcSwitchOffLine, rpcSetNodeDimming, rpcLineProfile, rpcNodeProfile, sunCalcExample, dataFromTerminalBroadcast })
|
||||||
})
|
})
|
||||||
instance.on("5", _ => {
|
instance.on("5", _ => {
|
||||||
exec("sudo tail -n 25 monitor.txt" , (err, stdout, stderr) => {
|
exec("sudo tail -n 25 monitor.txt", (err, stdout, stderr) => {
|
||||||
if (err || stderr) instance.send(0,{err, stderr});
|
if (err || stderr) instance.send(0, { err, stderr });
|
||||||
else instance.send(0,stdout);
|
else instance.send(0, stdout);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
instance.on("6", _ => {
|
instance.on("6", _ => {
|
||||||
exec("sudo tail -n 25 err.txt" , (err, stdout, stderr) => {
|
exec("sudo tail -n 25 err.txt", (err, stdout, stderr) => {
|
||||||
if (err || stderr) instance.send(0,{err, stderr});
|
if (err || stderr) instance.send(0, { err, stderr });
|
||||||
else instance.send(0,stdout);
|
else instance.send(0, stdout);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
@ -212,7 +212,7 @@ const rpcNodeProfile =
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sunCalcExample = {
|
const sunCalcExample = {
|
||||||
dusk_no_offset: '20:18',
|
dusk_no_offset: '20:18',
|
||||||
dawn_no_offset: '05:19',
|
dawn_no_offset: '05:19',
|
||||||
dusk: '20:18',
|
dusk: '20:18',
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
logger.debug(exports.title, "installed");
|
logger.debug(exports.title, "installed");
|
||||||
|
|
||||||
instance.on("close", function(){
|
instance.on("close", function() {
|
||||||
clearInterval(startRead);
|
clearInterval(startRead);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -42,24 +42,25 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if(temperatureAddress === "") throw "Thermometer: temperatureAddress is not defined";
|
if (temperatureAddress === "") throw "Thermometer: temperatureAddress is not defined";
|
||||||
|
|
||||||
exec(`owread -C ${temperatureAddress}/temperature`, (error, stdout, stderr) => {
|
exec(`owread -C ${temperatureAddress}/temperature`, (error, stdout, stderr) => {
|
||||||
|
|
||||||
if(!error)
|
if (!error) {
|
||||||
{
|
|
||||||
parseData(stdout)
|
parseData(stdout)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
if(counter == NUMBER_OF_FAILURES_TO_SEND_ERROR) sendNotification("Thermometer_main", rvoTbName, "thermometer_is_not_responding", {}, {"Error": error}, SEND_TO.tb, instance, "thermometer");
|
if (counter == NUMBER_OF_FAILURES_TO_SEND_ERROR) {
|
||||||
monitor.info("Thermometer is not responding", error);
|
sendNotification("Thermometer_main", rvoTbName, "thermometer_is_not_responding", {}, { "Error": error }, SEND_TO.tb, instance, "thermometer");
|
||||||
instance.send(SEND_TO.dido_controller, {status: "NOK-thermometer"});
|
monitor.info("Thermometer is not responding", error);
|
||||||
|
}
|
||||||
|
instance.send(SEND_TO.dido_controller, { status: "NOK-thermometer" });
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch (err) {
|
||||||
errLogger.error(exports.title, err);
|
errLogger.error(exports.title, err);
|
||||||
clearInterval(startRead);
|
clearInterval(startRead);
|
||||||
}
|
}
|
||||||
|
|
@ -70,12 +71,12 @@ exports.install = function(instance) {
|
||||||
data = parseFloat(data);
|
data = parseFloat(data);
|
||||||
//logger.debug("Thermometer", data);
|
//logger.debug("Thermometer", data);
|
||||||
|
|
||||||
if(isNaN(data)) {
|
if (isNaN(data)) {
|
||||||
errLogger.error("Thermometer sends invalid data");
|
errLogger.error("Thermometer sends invalid data");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(counter > NUMBER_OF_FAILURES_TO_SEND_ERROR) //1 hour
|
if (counter > NUMBER_OF_FAILURES_TO_SEND_ERROR) //1 hour
|
||||||
{
|
{
|
||||||
instance.send(SEND_TO.debug, "Thermometer - temperature data are comming again");
|
instance.send(SEND_TO.debug, "Thermometer - temperature data are comming again");
|
||||||
sendNotification("Thermometer_parseData", rvoTbName, "thermometer_is_responding_again", {}, "", SEND_TO.tb, instance, "thermometer");
|
sendNotification("Thermometer_parseData", rvoTbName, "thermometer_is_responding_again", {}, "", SEND_TO.tb, instance, "thermometer");
|
||||||
|
|
@ -85,7 +86,7 @@ exports.install = function(instance) {
|
||||||
"temperature": Number(data.toFixed(2)),
|
"temperature": Number(data.toFixed(2)),
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.send(SEND_TO.dido_controller, {values: values});
|
instance.send(SEND_TO.dido_controller, { values: values });
|
||||||
counter = 0;
|
counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue