version 2025-01-21; offline node status, do not turn lines on startup if not needed
This commit is contained in:
parent
4c59ccd095
commit
73a2620add
3 changed files with 164 additions and 251 deletions
|
|
@ -275,9 +275,6 @@ exports.install = function(instance) {
|
|||
let params = getParams(PRIORITY_TYPES.node_cmd);
|
||||
params.type = "set_node_profile";
|
||||
params.address = node;
|
||||
params.byte1 = 0;
|
||||
params.byte2 = 0;
|
||||
params.byte3 = 0;
|
||||
params.byte4 = 96;
|
||||
params.recipient = 1;
|
||||
params.register = 8;
|
||||
|
|
@ -297,9 +294,6 @@ exports.install = function(instance) {
|
|||
let params = getParams(PRIORITY_TYPES.node_cmd);
|
||||
params.type = "set_node_profile";
|
||||
params.address = node;
|
||||
params.byte1 = 0;
|
||||
params.byte2 = 0;
|
||||
params.byte3 = 0;
|
||||
params.byte4 = 96;
|
||||
params.recipient = 1;
|
||||
params.register = 8;
|
||||
|
|
@ -345,8 +339,6 @@ exports.install = function(instance) {
|
|||
params.address = node;
|
||||
params.byte1 = parseInt(t[0]);//hh
|
||||
params.byte2 = parseInt(t[1]);//mm
|
||||
params.byte3 = 0;//ss
|
||||
params.byte4 = 0;//
|
||||
params.recipient = 1;
|
||||
params.register = register;
|
||||
params.rw = 1;//write
|
||||
|
|
@ -362,9 +354,6 @@ exports.install = function(instance) {
|
|||
params = getParams(PRIORITY_TYPES.node_cmd);
|
||||
params.type = "set_node_profile";
|
||||
params.address = node;
|
||||
params.byte1 = 0;
|
||||
params.byte2 = 0;
|
||||
params.byte3 = 0;//ss
|
||||
params.byte4 = parseInt(dim_value) + 128;//
|
||||
params.recipient = 1;
|
||||
params.register = register;
|
||||
|
|
@ -653,28 +642,18 @@ exports.install = function(instance) {
|
|||
|
||||
logger.debug("--->reportOnlineNodeStatus for line", line);
|
||||
|
||||
const d = new Date();
|
||||
|
||||
//run broadcast //Actual time
|
||||
let params = {};
|
||||
|
||||
var d = new Date();
|
||||
let hours = d.getHours();
|
||||
let minutes = d.getMinutes();
|
||||
let seconds = d.getSeconds();
|
||||
|
||||
let time = d.getTime(); // time in ms
|
||||
|
||||
let params = getParams();
|
||||
params.address = 0xffffffff;//Broadcast
|
||||
params.byte1 = hours;//h
|
||||
params.byte2 = minutes;//m
|
||||
params.byte3 = seconds;//s
|
||||
params.byte4 = 0;
|
||||
params.byte1 = d.getHours();
|
||||
params.byte2 = d.getMinutes();
|
||||
params.recipient = 2;//2 broadcast, address = 0
|
||||
params.register = 87;//Actual time
|
||||
params.rw = 1;//write
|
||||
|
||||
//other values
|
||||
params.type = "cmd";
|
||||
params.timestamp = Date.now() + 60000;
|
||||
params.timestamp = d.getTime() + 30000;
|
||||
params.addMinutesToTimestamp = 0;
|
||||
params.info = "run broadcast: Actual time";
|
||||
|
||||
|
|
@ -684,42 +663,31 @@ exports.install = function(instance) {
|
|||
setTimeout(function() {
|
||||
//Po zapnutí línie - spraviť hromadný refresh stavu práve zapnutých svietidiel
|
||||
|
||||
let time = Date.now();
|
||||
|
||||
for (let k in nodesData) {
|
||||
|
||||
//potrebujem nody k danej linii
|
||||
if (line == nodesData[k].line || line == undefined) {
|
||||
|
||||
let tbname = nodesData[k].tbname;
|
||||
let node = nodesData[k].node;
|
||||
let status = "NOK";
|
||||
|
||||
// if status of node was "OK" before switching it off, we set the node's time_of_last_communication on time, it was switched on again and send OK status to tb.
|
||||
if (nodesData[k].status) {
|
||||
if (nodesData[k].node_status_before_offline == true || nodesData[k].status === true) {
|
||||
status = "OK";
|
||||
nodesData[k].time_of_last_communication = time;
|
||||
}
|
||||
|
||||
updateNodeStatus(k, status === "OK" ? true : false);
|
||||
if (nodesData[k].hasOwnProperty("node_status_before_offline")) delete nodesData[k].node_status_before_offline;
|
||||
sendTelemetry({ status: status }, tbname, time);
|
||||
|
||||
//vyreportovanie dimmingu, prud, vykon - current, input power pre liniu pre vsetky nody
|
||||
//vyreportovanie dimming, current, input power pre liniu pre vsetky nody
|
||||
//Prud
|
||||
{
|
||||
let params = getParams(PRIORITY_TYPES.high_priority);
|
||||
|
||||
params.type = "cmd";
|
||||
params.tbname = tbname;
|
||||
params.address = node;
|
||||
params.register = 1;//dimming
|
||||
params.recipient = 1;//slave
|
||||
params.rw = 0;//read
|
||||
params.timestamp = PRIORITY_TYPES.high_priority;
|
||||
params.info = 'read dimming';
|
||||
//params.debug = true;
|
||||
|
||||
tasks.push(params);
|
||||
}
|
||||
|
||||
//Prúd
|
||||
{
|
||||
let params = getParams(PRIORITY_TYPES.high_priority);
|
||||
let params = getParams();
|
||||
|
||||
params.type = "cmd";
|
||||
params.tbname = tbname;
|
||||
|
|
@ -727,16 +695,16 @@ exports.install = function(instance) {
|
|||
params.register = 75;//prud
|
||||
params.recipient = 1;//slave
|
||||
params.rw = 0;//read
|
||||
params.timestamp = PRIORITY_TYPES.high_priority;
|
||||
params.timestamp = time + 3000;
|
||||
params.info = 'read current';
|
||||
//params.debug = true;
|
||||
|
||||
tasks.push(params);
|
||||
}
|
||||
|
||||
//výkon
|
||||
//vykon
|
||||
{
|
||||
let params = getParams(PRIORITY_TYPES.high_priority);
|
||||
let params = getParams();
|
||||
|
||||
params.type = "cmd";
|
||||
params.tbname = tbname;
|
||||
|
|
@ -744,14 +712,32 @@ exports.install = function(instance) {
|
|||
params.register = 76;//výkon
|
||||
params.recipient = 1;//slave
|
||||
params.rw = 0;//read
|
||||
params.timestamp = PRIORITY_TYPES.high_priority;
|
||||
params.timestamp = time + 3100;
|
||||
params.info = 'read power';
|
||||
//params.debug = true;
|
||||
|
||||
tasks.push(params);
|
||||
}
|
||||
//dimming
|
||||
{
|
||||
let params = getParams();
|
||||
|
||||
params.type = "cmd";
|
||||
params.tbname = tbname;
|
||||
params.address = node;
|
||||
params.register = 1;//dimming
|
||||
params.recipient = 1;//slave
|
||||
params.rw = 0;//read
|
||||
params.timestamp = time + 3200;
|
||||
params.info = 'read dimming';
|
||||
//params.debug = true;
|
||||
|
||||
tasks.push(params);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}, sec * 1000);
|
||||
}
|
||||
|
||||
|
|
@ -775,17 +761,12 @@ exports.install = function(instance) {
|
|||
if (line == nodesData[node].line || line == undefined) {
|
||||
|
||||
let tbname = nodesData[node].tbname;
|
||||
const dataToTb = {
|
||||
[tbname]: [
|
||||
{
|
||||
"ts": date,
|
||||
"values": values
|
||||
}
|
||||
]
|
||||
}
|
||||
let nodeStatus = nodesData[node].status;
|
||||
|
||||
//NOTE: we can not use sendTelemetry function, as it modifies input data (values object)
|
||||
instance.send(SEND_TO.tb, dataToTb);
|
||||
nodesData[node].node_status_before_offline = nodeStatus === true ? true : false;
|
||||
nodesData[node].status = "OFFLINE";
|
||||
|
||||
sendTelemetry({ ...values }, tbname, date);
|
||||
}
|
||||
|
||||
}, (index + 1) * 300);
|
||||
|
|
@ -801,7 +782,7 @@ exports.install = function(instance) {
|
|||
info: info
|
||||
};
|
||||
|
||||
logger.debug("linia", line, obj);
|
||||
//logger.debug("linia", line, obj);
|
||||
instance.send(SEND_TO.dido_controller, obj);
|
||||
}
|
||||
|
||||
|
|
@ -884,14 +865,16 @@ exports.install = function(instance) {
|
|||
processLine = params.line;
|
||||
}
|
||||
|
||||
//load profiles pre vsetky linie:
|
||||
let now = new Date();
|
||||
|
||||
//process line profiles
|
||||
if (processLineProfiles) {
|
||||
//process line profiles
|
||||
|
||||
let keys = Object.keys(relaysData);
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let line = parseInt(keys[i]); //line is turned off by default
|
||||
|
||||
let line = parseInt(keys[i]);
|
||||
let profilestr = relaysData[line].profile;
|
||||
|
||||
if (processLine != undefined) {
|
||||
|
|
@ -994,13 +977,12 @@ exports.install = function(instance) {
|
|||
start_time.setDate(start_time.getDate() + 1);
|
||||
}
|
||||
|
||||
let params = getParams(PRIORITY_TYPES.relay_profile);
|
||||
let params = getParams();
|
||||
params.type = "relay";
|
||||
params.line = parseInt(line);
|
||||
params.value = time_points[t].value;
|
||||
params.tbname = relaysData[line].tbname;
|
||||
params.timestamp = start_time.getTime();
|
||||
|
||||
params.addMinutesToTimestamp = 0;
|
||||
|
||||
// it timepoints are not calculated (dawn, dusk, lux_timepoint), but static points in line profile, we just repeat the task every day
|
||||
|
|
@ -1028,13 +1010,13 @@ exports.install = function(instance) {
|
|||
monitor.info("-->time_points final", line, time_points);
|
||||
|
||||
//ensure to turn on/off according to calculated currentValue
|
||||
let params = getParams(PRIORITY_TYPES.terminal);
|
||||
let params = getParams();
|
||||
params.type = "relay";
|
||||
params.line = parseInt(line);
|
||||
params.tbname = relaysData[line].tbname;
|
||||
params.value = currentValue;
|
||||
|
||||
params.timestamp = PRIORITY_TYPES.terminal;
|
||||
params.timestamp = i;
|
||||
params.addMinutesToTimestamp = 0;
|
||||
params.debug = true;
|
||||
|
||||
|
|
@ -1050,12 +1032,14 @@ exports.install = function(instance) {
|
|||
} catch (error) {
|
||||
if (profilestr !== "") {
|
||||
//errLogger.error(profilestr, error);
|
||||
console.log(`Cmd_manager: Unable to process line profile ${line}. Error: `, error);
|
||||
errorHandler.sendMessageToService(profilestr + "-" + error, 0, "js_error");
|
||||
} else {
|
||||
turnLine("off", line, "No line profile. Switching it off on startup");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//logger.debug("tasks:");
|
||||
//logger.debug(tasks);
|
||||
}
|
||||
|
|
@ -1065,60 +1049,44 @@ exports.install = function(instance) {
|
|||
//Time of dusk, Time of dawn, Actual Time
|
||||
|
||||
if (processBroadcast) {
|
||||
let addMinutesToTimestamp = 5;
|
||||
|
||||
let d = new Date();
|
||||
let time = d.getTime();
|
||||
let sunCalcResult = calculateDuskDawn();
|
||||
|
||||
{
|
||||
//run broadcast Time of dusk
|
||||
addMinutesToTimestamp = 60 * 3; //kazde 3 hodiny zisti novy dusk
|
||||
|
||||
let params = getParams(PRIORITY_TYPES.node_broadcast);
|
||||
|
||||
let sunCalcResult = calculateDuskDawn();
|
||||
let dusk_hours = sunCalcResult["dusk_hours"];
|
||||
let dusk_minutes = sunCalcResult["dusk_minutes"];
|
||||
let params = getParams();
|
||||
|
||||
params.address = 0xffffffff;//broadcast
|
||||
params.byte1 = dusk_hours;//h
|
||||
params.byte2 = dusk_minutes;//m
|
||||
params.byte3 = 0;//s
|
||||
params.byte4 = 0;
|
||||
params.byte1 = sunCalcResult["dusk_hours"];
|
||||
params.byte2 = sunCalcResult["dusk_minutes"];
|
||||
params.recipient = 2;//2 broadcast,
|
||||
params.register = 6;//Time of dusk - Reg 6
|
||||
params.rw = 1;//write
|
||||
|
||||
//other values
|
||||
params.type = "cmd";
|
||||
params.timestamp = Date.now() + 60000;
|
||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||
params.timestamp = time + 60000;
|
||||
params.addMinutesToTimestamp = 60 * 3; //kazde 3 hodiny zisti novy dusk
|
||||
params.info = "Broadcast-duskTime";
|
||||
|
||||
tasks.push(params);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
//run broadcast Time of dawn
|
||||
addMinutesToTimestamp = 60 * 3; //kazde 3 hodiny zisti novy dawn
|
||||
|
||||
let params = getParams(PRIORITY_TYPES.node_broadcast);
|
||||
|
||||
let sunCalcResult = calculateDuskDawn();
|
||||
let dawn_hours = sunCalcResult["dawn_hours"];
|
||||
let dawn_minutes = sunCalcResult["dawn_minutes"];
|
||||
let params = getParams();
|
||||
|
||||
params.address = 0xffffffff;//broadcast
|
||||
params.byte1 = dawn_hours;//h
|
||||
params.byte2 = dawn_minutes;//m
|
||||
params.byte3 = 0;//s
|
||||
params.byte4 = 0;
|
||||
params.byte1 = sunCalcResult["dawn_hours"];
|
||||
params.byte2 = sunCalcResult["dawn_minutes"];
|
||||
params.recipient = 2; //2 broadcast
|
||||
params.register = 7;//Time of dawn - Reg 6
|
||||
params.rw = 1;//write
|
||||
|
||||
//other values
|
||||
params.type = "cmd";
|
||||
params.timestamp = Date.now() + 60000;
|
||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||
params.timestamp = time + 60001;
|
||||
params.addMinutesToTimestamp = 60 * 3; //kazde 3 hodiny zisti novy dawn
|
||||
params.info = "Broadcast-dawnTime";
|
||||
|
||||
tasks.push(params);
|
||||
|
|
@ -1126,28 +1094,18 @@ exports.install = function(instance) {
|
|||
|
||||
{
|
||||
//run broadcast Actual time
|
||||
addMinutesToTimestamp = 5;
|
||||
|
||||
let params = getParams(PRIORITY_TYPES.node_broadcast);
|
||||
|
||||
var d = new Date();
|
||||
let hours = d.getHours();
|
||||
let minutes = d.getMinutes();
|
||||
let seconds = d.getSeconds();
|
||||
let params = getParams();
|
||||
|
||||
params.address = 0xffffffff;//broadcast
|
||||
params.byte1 = hours;//h
|
||||
params.byte2 = minutes;//m
|
||||
params.byte3 = seconds;//s
|
||||
params.byte4 = 0;
|
||||
params.byte1 = d.getHours();
|
||||
params.byte2 = d.getMinutes();
|
||||
params.recipient = 2; //2 broadcast
|
||||
params.register = 87;//Actual time
|
||||
params.rw = 1;//write
|
||||
|
||||
//other values
|
||||
params.type = "cmd";
|
||||
params.timestamp = Date.now() + 60000;
|
||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||
params.timestamp = time + 60002;
|
||||
params.addMinutesToTimestamp = 5;
|
||||
params.info = "run broadcast: Actual time";
|
||||
|
||||
tasks.push(params);
|
||||
|
|
@ -1158,6 +1116,9 @@ exports.install = function(instance) {
|
|||
//process nodes & tasks
|
||||
//reportovanie pre platformu
|
||||
if (processNodes) {
|
||||
|
||||
let time = Date.now();
|
||||
|
||||
for (let k in nodesData) {
|
||||
let address = parseInt(k);
|
||||
let tbname = nodesData[k].tbname;
|
||||
|
|
@ -1167,37 +1128,24 @@ exports.install = function(instance) {
|
|||
|
||||
//listOfCommands - READ
|
||||
for (let i = 0; i < listOfCommands.length; i++) {
|
||||
|
||||
register = listOfCommands[i];
|
||||
|
||||
let params = getParams(PRIORITY_TYPES.node_cmd);
|
||||
|
||||
//core rpc values
|
||||
params.address = address;
|
||||
params.byte1 = 0;
|
||||
params.byte2 = 0;
|
||||
params.byte3 = 0;
|
||||
params.byte4 = 0;
|
||||
params.recipient = 1;
|
||||
params.register = register;
|
||||
params.rw = 0;
|
||||
|
||||
let addMinutesToTimestamp = priorities[register];
|
||||
|
||||
let timestampStart = PRIORITY_TYPES.node_cmd; //run imediatelly in function runTasks
|
||||
if (addMinutesToTimestamp > 1) {
|
||||
timestampStart = timestampStart + addMinutesToTimestamp * 60000;
|
||||
}
|
||||
let params = getParams();
|
||||
|
||||
//other values
|
||||
params.address = address;
|
||||
params.recipient = 1;
|
||||
params.register = register;
|
||||
params.type = "cmd";
|
||||
params.tbname = tbname;
|
||||
params.timestamp = timestampStart;
|
||||
params.timestamp = time + 5000 + i * 500 + addMinutesToTimestamp * 1000; //to make slight time difference
|
||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||
params.info = "generated cmd - buildTasks (node)";
|
||||
|
||||
tasks.push(params);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1206,12 +1154,9 @@ exports.install = function(instance) {
|
|||
if (!init) return;
|
||||
|
||||
|
||||
//Priebežne (raz za cca 5 minút) je potrebné vyčítať z Master nodu verziu jeho FW.
|
||||
//Jedná sa o register 10. Rovnaká interpretácia ako pri FW verzii nodu.
|
||||
//Adresa mastera je 0. V prípade že kedykoľvek nastane situácia že Master Node neodpovedá (napríklad pri vyčítaní telemetrie z nodu nevráti žiadne dáta),
|
||||
//tak treba vyreportovať string "NOK".
|
||||
//Master node FW version
|
||||
{
|
||||
let params = getParams(PRIORITY_TYPES.fw_detection);
|
||||
let params = getParams();
|
||||
params.type = "cmd-master";
|
||||
params.register = 4;
|
||||
params.address = 0;
|
||||
|
|
@ -1220,7 +1165,6 @@ exports.install = function(instance) {
|
|||
params.tbname = SETTINGS.rvoTbName;
|
||||
params.info = "Master node FW verzia";
|
||||
//params.debug = true;
|
||||
|
||||
//this will set SETTINGS.masterNodeIsResponding
|
||||
|
||||
tasks.push(params);
|
||||
|
|
@ -1228,7 +1172,7 @@ exports.install = function(instance) {
|
|||
|
||||
//kazdu hodinu skontrolovat nastavenie profilov
|
||||
{
|
||||
let params = getParams(PRIORITY_TYPES.fw_detection);
|
||||
let params = getParams();
|
||||
params.type = "process_profiles";
|
||||
params.timestamp = Date.now() + 60000;
|
||||
params.addMinutesToTimestamp = 60;//60 = every hour
|
||||
|
|
@ -1336,7 +1280,12 @@ exports.install = function(instance) {
|
|||
|
||||
let data = null;
|
||||
|
||||
if (newStatus == true && nodeCurrentStatus == true && nodeObj.time_of_last_communication > now - TIME_AFTER_WE_UPDATE_LAST_NODE_COMMUNICATION) return;
|
||||
if (nodeCurrentStatus === "OFFLINE") {
|
||||
data = { status: newStatus };
|
||||
nodeDbStatusModify(node, data);
|
||||
return;
|
||||
}
|
||||
else if (newStatus == true && nodeCurrentStatus == true && nodeObj.time_of_last_communication > now - TIME_AFTER_WE_UPDATE_LAST_NODE_COMMUNICATION) return;
|
||||
else if (newStatus == true && nodeCurrentStatus == true && nodeObj.time_of_last_communication < now - TIME_AFTER_WE_UPDATE_LAST_NODE_COMMUNICATION) {
|
||||
data = { time_of_last_communication: now };
|
||||
nodeDbStatusModify(node, data);
|
||||
|
|
@ -1476,7 +1425,7 @@ exports.install = function(instance) {
|
|||
if (type == "process_profiles") {
|
||||
tasks[0].timestamp = currentTimestamp + tasks[0].addMinutesToTimestamp * 60000;
|
||||
|
||||
//vsetky linie kt. su zapnute, a spracuju sa nespracovane profily nodov
|
||||
//na vsetky zapnutych liniach sa spracuju nespracovane profily nodov
|
||||
loadRelaysData();
|
||||
|
||||
interval = setInterval(runTasks, SHORT_INTERVAL);
|
||||
|
|
@ -1517,7 +1466,7 @@ exports.install = function(instance) {
|
|||
|
||||
turnLine(onOrOff, params.line, info);
|
||||
|
||||
interval = setInterval(runTasks, SHORT_INTERVAL);
|
||||
interval = setInterval(runTasks, LONG_INTERVAL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1554,7 +1503,6 @@ exports.install = function(instance) {
|
|||
|
||||
const register = params.register;
|
||||
|
||||
//high_priority
|
||||
if (!SETTINGS.masterNodeIsResponding) {
|
||||
//ak neodpoveda, nebudeme vykonavat ziadne commands, okrem cmd-terminal, a fw version
|
||||
errorHandler.sendMessageToService("Master node is not responding");
|
||||
|
|
@ -1609,8 +1557,6 @@ exports.install = function(instance) {
|
|||
var d = new Date();
|
||||
params.byte1 = d.getHours();//h
|
||||
params.byte2 = d.getMinutes();//m
|
||||
params.byte3 = 0;//s
|
||||
params.byte4 = 0;
|
||||
}
|
||||
|
||||
//SET DUSK/DAWN FOR BROADCAST
|
||||
|
|
@ -1621,8 +1567,6 @@ exports.install = function(instance) {
|
|||
let sunCalcResult = calculateDuskDawn();
|
||||
params.byte1 = sunCalcResult["dusk_hours"];//h
|
||||
params.byte2 = sunCalcResult["dusk_minutes"];//m
|
||||
params.byte3 = 0;//s
|
||||
params.byte4 = 0;
|
||||
|
||||
//TODO astrohodiny
|
||||
let dusk = "Time of dusk: " + sunCalcResult["dusk"];
|
||||
|
|
@ -1635,8 +1579,6 @@ exports.install = function(instance) {
|
|||
let sunCalcResult = calculateDuskDawn();
|
||||
params.byte1 = sunCalcResult["dawn_hours"];//h
|
||||
params.byte2 = sunCalcResult["dawn_minutes"];//m
|
||||
params.byte3 = 0;//s
|
||||
params.byte4 = 0;
|
||||
|
||||
//TODO astrohodiny
|
||||
let dawn = "Time of dawn: " + sunCalcResult["dawn"];
|
||||
|
|
@ -1752,7 +1694,7 @@ exports.install = function(instance) {
|
|||
}
|
||||
else {
|
||||
|
||||
terminalCommandResponse(params, "ERROR", data)
|
||||
terminalCommandResponse(params, "ERROR", data);
|
||||
handleNokResponseOnRsPort("handleNOK else block", params, itIsNodeCommand, saveToTb);
|
||||
|
||||
if (params.hasOwnProperty("debug")) {
|
||||
|
|
@ -1805,9 +1747,9 @@ exports.install = function(instance) {
|
|||
|
||||
let values = {};
|
||||
|
||||
// console.log(message);
|
||||
let updateStatus = updateNodeStatus(node, false);
|
||||
|
||||
console.log("cmd_man: handleNokRsPort: ", node, register, message);
|
||||
//master node
|
||||
if (node == 0) {
|
||||
sendNotification("CMD Manager: process cmd", SETTINGS.rvoTbName, "master_node_is_not_responding", {}, "", SEND_TO.tb, instance, "rvo_status");
|
||||
|
|
@ -1917,8 +1859,12 @@ exports.install = function(instance) {
|
|||
let nodeObj = nodesData_clone[key];
|
||||
if (nodeObj.tbname == undefined) continue;
|
||||
|
||||
if (nodeObj.status) number_of_ok_luminaires++;
|
||||
if (nodeObj.status === "OFFLINE") {
|
||||
nodeObj.node_status_before_offline === true ? number_of_ok_luminaires++ : number_of_nok_luminaires++;
|
||||
}
|
||||
else if (nodeObj.status == true) number_of_ok_luminaires++;
|
||||
else number_of_nok_luminaires++;
|
||||
|
||||
}
|
||||
|
||||
const values = {
|
||||
|
|
@ -2376,16 +2322,11 @@ exports.install = function(instance) {
|
|||
relaysData[line].profile = profile;
|
||||
|
||||
loadRelaysData(line)
|
||||
|
||||
//TODO build tasks by mala bezat az ked je vsetko loadRelaysData
|
||||
//spracovane, pravdepodobne treba spravit promisy
|
||||
logger.debug("loadRelaysData DONE for line", line);
|
||||
console.log("zacina buildTasks po loadRelaysData.........")
|
||||
|
||||
buildTasks({ processLineProfiles: true, line: line });
|
||||
|
||||
sendNotification("CMD manager - set profile from worksys", tbname, "switching_profile_was_processed_for_line", { line: line }, profile, SEND_TO.tb, instance);
|
||||
|
||||
});
|
||||
});
|
||||
break;
|
||||
|
|
|
|||
110
flow/db_init.js
110
flow/db_init.js
|
|
@ -37,69 +37,69 @@ const { initNotification } = require('./helper/notification_reporter');
|
|||
|
||||
exports.install = async function(instance) {
|
||||
|
||||
const dbNodes = TABLE("nodes");
|
||||
const dbRelays = TABLE("relays");
|
||||
const dbSettings = TABLE("settings");
|
||||
const dbPins = TABLE("pins");
|
||||
const dbNotifications = TABLE("notifications");
|
||||
const dbNodes = TABLE("nodes");
|
||||
const dbRelays = TABLE("relays");
|
||||
const dbSettings = TABLE("settings");
|
||||
const dbPins = TABLE("pins");
|
||||
const dbNotifications = TABLE("notifications");
|
||||
|
||||
FLOW.GLOBALS = {};
|
||||
const dbs = FLOW.GLOBALS;
|
||||
FLOW.GLOBALS = {};
|
||||
const dbs = FLOW.GLOBALS;
|
||||
|
||||
const responseSettings = await promisifyBuilder(dbSettings.find());
|
||||
const responseNodes = await promisifyBuilder(dbNodes.find());
|
||||
const responsePins = await promisifyBuilder(dbPins.find());
|
||||
const responseRelays = await promisifyBuilder(dbRelays.find());
|
||||
const response = await promisifyBuilder(dbNotifications.find());
|
||||
const responseSettings = await promisifyBuilder(dbSettings.find());
|
||||
const responseNodes = await promisifyBuilder(dbNodes.find());
|
||||
const responsePins = await promisifyBuilder(dbPins.find());
|
||||
const responseRelays = await promisifyBuilder(dbRelays.find());
|
||||
const response = await promisifyBuilder(dbNotifications.find());
|
||||
|
||||
dbs.pinsData = makeMapFromDbResult(responsePins, "pin");
|
||||
dbs.relaysData = makeMapFromDbResult(responseRelays, "line");
|
||||
dbs.nodesData = makeMapFromDbResult(responseNodes, "node");
|
||||
dbs.notificationsData = makeMapFromDbResult(response, "key");
|
||||
dbs.pinsData = makeMapFromDbResult(responsePins, "pin");
|
||||
dbs.relaysData = makeMapFromDbResult(responseRelays, "line");
|
||||
dbs.nodesData = makeMapFromDbResult(responseNodes, "node");
|
||||
dbs.notificationsData = makeMapFromDbResult(response, "key");
|
||||
|
||||
//+|354|nodesdata.....+|482|nodesdata....
|
||||
//for some reason, if last line in nodes.table is not empty, flow wrote more nodes data in one row,
|
||||
//so we have to add empty line at the bottom of nodes table to avoid this.
|
||||
//now, remove empty lines from nodesData database:
|
||||
if(dbs.nodesData.hasOwnProperty("0")) delete dbs.nodesData["0"];
|
||||
//+|354|nodesdata.....+|482|nodesdata....
|
||||
//for some reason, if last line in nodes.table is not empty, flow wrote more nodes data in one row,
|
||||
//so we have to add empty line at the bottom of nodes table to avoid this.
|
||||
//now, remove empty lines from nodesData database:
|
||||
if (dbs.nodesData.hasOwnProperty("0")) delete dbs.nodesData["0"];
|
||||
|
||||
dbs.settings = {
|
||||
edge_fw_version : "2025-01-13", //rok-mesiac-den
|
||||
language : responseSettings[0]["lang"],
|
||||
rvo_name : responseSettings[0]["rvo_name"],
|
||||
project_id : responseSettings[0]["project_id"],
|
||||
rvoTbName : dbs.relaysData[0]["tbname"],
|
||||
temperature_address : responseSettings[0]["temperature_address"],
|
||||
controller_type : responseSettings[0]["controller_type"],
|
||||
serial_port : responseSettings[0]["serial_port"],
|
||||
node_status_nok_time : responseSettings[0]["node_status_nok_time"] * 60 * 60 * 1000 ,// hour * minutes *
|
||||
latitude : responseSettings[0]["latitude"],
|
||||
longitude : responseSettings[0]["longitude"],
|
||||
no_voltage : new Set(),//modbus_citysys - elektromer
|
||||
backup_on_failure : responseSettings[0]["backup_on_failure"],
|
||||
restore_from_backup : responseSettings[0]["restore_from_backup"],
|
||||
restore_backup_wait : responseSettings[0]["restore_backup_wait"],
|
||||
mqtt_host : responseSettings[0]["mqtt_host"],
|
||||
mqtt_clientid : responseSettings[0]["mqtt_clientid"],
|
||||
mqtt_username : responseSettings[0]["mqtt_username"],
|
||||
mqtt_port : responseSettings[0]["mqtt_port"],
|
||||
phases: responseSettings[0]["phases"],
|
||||
cloud_topic: responseSettings[0]["cloud_topic"],
|
||||
|
||||
//dynamic values
|
||||
masterNodeIsResponding : true, //cmd_manager
|
||||
maintenance_mode : false,
|
||||
}
|
||||
dbs.settings = {
|
||||
edge_fw_version: "2025-01-21", //rok-mesiac-den
|
||||
language: responseSettings[0]["lang"],
|
||||
rvo_name: responseSettings[0]["rvo_name"],
|
||||
project_id: responseSettings[0]["project_id"],
|
||||
rvoTbName: dbs.relaysData[0]["tbname"],
|
||||
temperature_address: responseSettings[0]["temperature_address"],
|
||||
controller_type: responseSettings[0]["controller_type"],
|
||||
serial_port: responseSettings[0]["serial_port"],
|
||||
node_status_nok_time: responseSettings[0]["node_status_nok_time"] * 60 * 60 * 1000,// hour * minutes *
|
||||
latitude: responseSettings[0]["latitude"],
|
||||
longitude: responseSettings[0]["longitude"],
|
||||
no_voltage: new Set(),//modbus_citysys - elektromer
|
||||
backup_on_failure: responseSettings[0]["backup_on_failure"],
|
||||
restore_from_backup: responseSettings[0]["restore_from_backup"],
|
||||
restore_backup_wait: responseSettings[0]["restore_backup_wait"],
|
||||
mqtt_host: responseSettings[0]["mqtt_host"],
|
||||
mqtt_clientid: responseSettings[0]["mqtt_clientid"],
|
||||
mqtt_username: responseSettings[0]["mqtt_username"],
|
||||
mqtt_port: responseSettings[0]["mqtt_port"],
|
||||
phases: responseSettings[0]["phases"],
|
||||
cloud_topic: responseSettings[0]["cloud_topic"],
|
||||
|
||||
FLOW.dbLoaded = true;
|
||||
initNotification();
|
||||
//dynamic values
|
||||
masterNodeIsResponding: true, //cmd_manager
|
||||
maintenance_mode: false,
|
||||
}
|
||||
|
||||
setTimeout(()=> {
|
||||
console.log("DB_INIT - data loaded");
|
||||
instance.send(0, "_")
|
||||
}, 5000)
|
||||
FLOW.dbLoaded = true;
|
||||
initNotification();
|
||||
|
||||
};
|
||||
setTimeout(() => {
|
||||
console.log("DB_INIT - data loaded");
|
||||
instance.send(0, "_")
|
||||
}, 5000)
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ state_of_contactor - podľa indexu stykača sa reportuje jeho stav, teda stykač
|
|||
const { errLogger, logger, monitor } = require('./helper/logger');
|
||||
const SerialPort = require('serialport');
|
||||
const WebSocket = require('ws');
|
||||
//const { exec } = require('child_process');
|
||||
const { runSyncExec } = require('./helper/serialport_helper');
|
||||
const { bytesToInt, resizeArray } = require('./helper/utils');
|
||||
const { sendNotification } = require('./helper/notification_reporter');
|
||||
|
|
@ -71,7 +70,6 @@ let rvoTbName;
|
|||
let GLOBALS; //FLOW global GLOBALS
|
||||
let SETTINGS; // GLOBALS.settings
|
||||
let controller_type;
|
||||
let contactorSwitchCounter = 0; //how many times line contactor switched ?
|
||||
|
||||
let alarmStatus = "OFF";
|
||||
|
||||
|
|
@ -128,7 +126,7 @@ exports.install = function(instance) {
|
|||
|
||||
//status for calculating Statecodes
|
||||
let deviceStatus = { //key is device name: temperature,....
|
||||
"state_of_main_switch": "Off", //Hlavný istič
|
||||
"state_of_main_switch": "Off", //Hlavný istič (po novom druhy dverovy kontakt)
|
||||
"rotary_switch_state": "Off", //Prevádzkový mód
|
||||
"door_condition": "closed", //Dverový kontakt
|
||||
"em": "OK", //elektromer rvo
|
||||
|
|
@ -203,13 +201,10 @@ exports.install = function(instance) {
|
|||
|
||||
sendTelemetry(values, rvoTbName);
|
||||
|
||||
let time = 5 * 1000;
|
||||
setTimeout(function() {
|
||||
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "buildTasks" });
|
||||
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "buildTasks" });
|
||||
|
||||
sendNotification("rsPort.open()", rvoTbName, "flow_start", {}, "", SEND_TO.tb, instance);
|
||||
monitor.info("-->FLOW bol spustený", rvoTbName, SETTINGS.edge_fw_version);
|
||||
}, time);
|
||||
sendNotification("rsPort.open()", rvoTbName, "flow_start", {}, "", SEND_TO.tb, instance);
|
||||
monitor.info("-->FLOW bol spustený", rvoTbName, SETTINGS.edge_fw_version);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -309,6 +304,7 @@ exports.install = function(instance) {
|
|||
|
||||
initialSetting();
|
||||
|
||||
setTimeout(function() { ws.send(JSON.stringify({ cmd: "all" })) }, 5000);
|
||||
// we request dev info about neuron device from evok to keep websocket connection alive
|
||||
// for some reason this request returns no data, but connection keeps alive
|
||||
startRequests = setInterval(() => {
|
||||
|
|
@ -574,13 +570,13 @@ exports.install = function(instance) {
|
|||
sendRvoStatus();
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// we expect array as flowdata.data
|
||||
instance.on("1", flowdata => {
|
||||
|
||||
console.log(flowdata.data);
|
||||
//console.log(flowdata.data);
|
||||
|
||||
if (!flowdata.data instanceof Object) return;
|
||||
|
||||
|
|
@ -588,11 +584,7 @@ exports.install = function(instance) {
|
|||
let line = obj.line;
|
||||
let force = obj.force;
|
||||
let info = obj.info;
|
||||
|
||||
//how many times did the lines switched ? if all lines (except line 0) has switched, we request data from evok:
|
||||
contactorSwitchCounter++;
|
||||
if(contactorSwitchCounter == Object.keys(relaysData).length-1 && ws) setTimeout(function(){ws.send(JSON.stringify({cmd:"all"}))},5000);
|
||||
|
||||
|
||||
if (obj.command == "on") turnLine("on", line, undefined, force, info);
|
||||
else if (obj.command == "off") turnLine("off", line, undefined, force, info);
|
||||
else if (obj.command == "turnOnAlarm") turnAlarm("on");
|
||||
|
|
@ -815,26 +807,6 @@ exports.install = function(instance) {
|
|||
let value = "On";
|
||||
if (newPinValue === 0) value = "Off";
|
||||
|
||||
//Hlavný istič
|
||||
//! po novom uz 'state of main switch' nemame. Namiesto neho je 'door_condition', kedze mame dvoje dveri
|
||||
//! takze ked pride z evoku signal pre 'input1_05', handlujeme ho ako 'door_condition'
|
||||
// if(type === "!!!state_of_main_switch")
|
||||
// {
|
||||
// if (newPinValue === 0 && newPinValue !== previousValues[pinIndex])
|
||||
// {
|
||||
// sendNotification("switchLogic", rvoTbName, "main_switch_has_been_turned_off", {}, "", SEND_TO.tb, instance , "state_of_main_switch");
|
||||
// values["status"] = "NOK";
|
||||
|
||||
// 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";
|
||||
// }
|
||||
// }
|
||||
|
||||
//Prevádzkový mód
|
||||
if (type == "rotary_switch_state") {
|
||||
// combination of these two pins required to get result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue