version 2025-01-30; send fw version once a day
This commit is contained in:
parent
73a2620add
commit
5233aa38af
3 changed files with 141 additions and 145 deletions
|
|
@ -83,6 +83,7 @@ exports.install = function(instance) {
|
|||
let interval = null;//timeout for procesing tasks
|
||||
let customTasksInterval = null; // interval for reportEdgeDateTimeAndNumberOfLuminaires();
|
||||
let setCorrectTime = null; // interval for setting a correct edgeTime
|
||||
let sendNodeReadout = null; // interval for sending agregate data from node
|
||||
|
||||
let refFlowdataObj = {};
|
||||
|
||||
|
|
@ -173,13 +174,16 @@ exports.install = function(instance) {
|
|||
|
||||
handleRsPort();
|
||||
|
||||
//to ensure, edgeDateTime will be send to tb at full minute
|
||||
customTasksInterval = setInterval(function() {
|
||||
if (new Date().getSeconds() === 0) reportEdgeDateTimeAndNumberOfLuminaires();
|
||||
}, 1000);
|
||||
reportEdgeDateTimeAndNumberOfLuminaires();
|
||||
}, 120000);
|
||||
reportEdgeDateTimeAndNumberOfLuminaires();
|
||||
|
||||
|
||||
setCorrectTime = setInterval(setCorrectPlcTimeOnceADay, 60000 * 60); // 1 hour
|
||||
setCorrectPlcTimeOnceADay();
|
||||
|
||||
sendNodeReadout = setInterval(sendNodesData, 150000);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -280,7 +284,6 @@ exports.install = function(instance) {
|
|||
params.register = 8;
|
||||
params.rw = 1;//write
|
||||
params.timestamp = timestamp;
|
||||
params.addMinutesToTimestamp = 0;
|
||||
params.info = 'turn off/reset node profile';
|
||||
|
||||
cmdCounter[node] = 1;
|
||||
|
|
@ -299,7 +302,6 @@ exports.install = function(instance) {
|
|||
params.register = 8;
|
||||
params.rw = 1;//write
|
||||
params.timestamp = timestamp;
|
||||
params.addMinutesToTimestamp = 0;
|
||||
params.info = 'turn off node profile';
|
||||
|
||||
tasksProfile.push(params);
|
||||
|
|
@ -373,14 +375,13 @@ exports.install = function(instance) {
|
|||
|
||||
logger.debug("processNodeProfile: Threshold lux level for DUSK/DAWN", node);
|
||||
|
||||
let params = getParams(PRIORITY_TYPES.node_cmd);
|
||||
let params = getParams();
|
||||
params.type = "set_node_profile";
|
||||
params.address = node;
|
||||
params.register = 96;
|
||||
params.recipient = 1;
|
||||
params.rw = 1;//write
|
||||
params.timestamp = timestamp;
|
||||
params.addMinutesToTimestamp = 0;
|
||||
params.info = "Threshold lux level for DUSK/DAWN";
|
||||
|
||||
if (nodeProfile.dusk_lux_sensor) {
|
||||
|
|
@ -409,14 +410,13 @@ exports.install = function(instance) {
|
|||
|
||||
logger.debug("processNodeProfile: DUSK/DAWN max. adjust period", node);
|
||||
|
||||
let params = getParams(PRIORITY_TYPES.node_cmd);
|
||||
let params = getParams();
|
||||
params.type = "set_node_profile";
|
||||
params.address = node;
|
||||
params.register = 97;
|
||||
params.recipient = 1;
|
||||
params.rw = 1;//write
|
||||
params.timestamp = timestamp;
|
||||
params.addMinutesToTimestamp = 0;
|
||||
params.info = "DUSK/DAWN max. adjust period";
|
||||
|
||||
if (nodeProfile.astro_clock) {
|
||||
|
|
@ -456,7 +456,6 @@ exports.install = function(instance) {
|
|||
params.recipient = 1;
|
||||
params.rw = 1;//write
|
||||
params.timestamp = timestamp;
|
||||
params.addMinutesToTimestamp = 0;
|
||||
params.info = "Static offset";
|
||||
|
||||
if (nodeProfile.astro_clock) {
|
||||
|
|
@ -644,7 +643,7 @@ exports.install = function(instance) {
|
|||
|
||||
const d = new Date();
|
||||
|
||||
//run broadcast //Actual time
|
||||
// broadcast actual time
|
||||
let params = getParams();
|
||||
params.address = 0xffffffff;//Broadcast
|
||||
params.byte1 = d.getHours();
|
||||
|
|
@ -652,10 +651,10 @@ exports.install = function(instance) {
|
|||
params.recipient = 2;//2 broadcast, address = 0
|
||||
params.register = 87;//Actual time
|
||||
params.rw = 1;//write
|
||||
params.type = "cmd";
|
||||
params.type = "node-onetime-write";
|
||||
params.timestamp = d.getTime() + 30000;
|
||||
params.addMinutesToTimestamp = 0;
|
||||
params.info = "run broadcast: Actual time";
|
||||
//params.debug = true;
|
||||
|
||||
tasks.push(params);
|
||||
|
||||
|
|
@ -680,6 +679,8 @@ exports.install = function(instance) {
|
|||
nodesData[k].time_of_last_communication = time;
|
||||
}
|
||||
|
||||
nodesData[k].readout.status = status;
|
||||
|
||||
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);
|
||||
|
|
@ -689,16 +690,15 @@ exports.install = function(instance) {
|
|||
{
|
||||
let params = getParams();
|
||||
|
||||
params.type = "cmd";
|
||||
params.type = "node-onetime-read";
|
||||
params.tbname = tbname;
|
||||
params.address = node;
|
||||
params.register = 75;//prud
|
||||
params.recipient = 1;//slave
|
||||
params.rw = 0;//read
|
||||
params.timestamp = time + 3000;
|
||||
params.timestamp = time + 4000;
|
||||
params.info = 'read current';
|
||||
//params.debug = true;
|
||||
|
||||
tasks.push(params);
|
||||
}
|
||||
|
||||
|
|
@ -706,13 +706,13 @@ exports.install = function(instance) {
|
|||
{
|
||||
let params = getParams();
|
||||
|
||||
params.type = "cmd";
|
||||
params.type = "node-onetime-read";
|
||||
params.tbname = tbname;
|
||||
params.address = node;
|
||||
params.register = 76;//výkon
|
||||
params.recipient = 1;//slave
|
||||
params.rw = 0;//read
|
||||
params.timestamp = time + 3100;
|
||||
params.timestamp = time + 4100;
|
||||
params.info = 'read power';
|
||||
//params.debug = true;
|
||||
|
||||
|
|
@ -722,13 +722,13 @@ exports.install = function(instance) {
|
|||
{
|
||||
let params = getParams();
|
||||
|
||||
params.type = "cmd";
|
||||
params.type = "node-onetime-read";
|
||||
params.tbname = tbname;
|
||||
params.address = node;
|
||||
params.register = 1;//dimming
|
||||
params.recipient = 1;//slave
|
||||
params.rw = 0;//read
|
||||
params.timestamp = time + 3200;
|
||||
params.timestamp = time + 4200;
|
||||
params.info = 'read dimming';
|
||||
//params.debug = true;
|
||||
|
||||
|
|
@ -765,6 +765,7 @@ exports.install = function(instance) {
|
|||
|
||||
nodesData[node].node_status_before_offline = nodeStatus === true ? true : false;
|
||||
nodesData[node].status = "OFFLINE";
|
||||
nodesData[node].readout = {};
|
||||
|
||||
sendTelemetry({ ...values }, tbname, date);
|
||||
}
|
||||
|
|
@ -837,12 +838,9 @@ exports.install = function(instance) {
|
|||
|
||||
//BUILD TASKS//
|
||||
function buildTasks(params) {
|
||||
//report SETTINGS.edge_fw_version as fw_version
|
||||
//report date as startdate
|
||||
|
||||
//return;
|
||||
console.log("buidTAaasks start ****************", params);
|
||||
|
||||
monitor.info("buildTasks - params", params);
|
||||
|
||||
let processLine; //defined line
|
||||
|
|
@ -983,7 +981,6 @@ exports.install = function(instance) {
|
|||
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
|
||||
if (time_points[t].name == "profileTimepoint") params.addMinutesToTimestamp = 24 * 60;
|
||||
|
|
@ -1015,9 +1012,7 @@ exports.install = function(instance) {
|
|||
params.line = parseInt(line);
|
||||
params.tbname = relaysData[line].tbname;
|
||||
params.value = currentValue;
|
||||
|
||||
params.timestamp = i;
|
||||
params.addMinutesToTimestamp = 0;
|
||||
params.debug = true;
|
||||
|
||||
//logger.debug(now.toLocaleString("sk-SK"));
|
||||
|
|
@ -1045,9 +1040,7 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
|
||||
//PROCESS DEFAULT BROADCASTS
|
||||
//Time of dusk, Time of dawn, Actual Time
|
||||
|
||||
//NOTE: PROCESS DEFAULT BROADCASTS - Time of dusk, Time of dawn, Actual Time
|
||||
if (processBroadcast) {
|
||||
|
||||
let d = new Date();
|
||||
|
|
@ -1055,17 +1048,15 @@ exports.install = function(instance) {
|
|||
let sunCalcResult = calculateDuskDawn();
|
||||
|
||||
{
|
||||
//run broadcast Time of dusk
|
||||
let params = getParams();
|
||||
|
||||
params.address = 0xffffffff;//broadcast
|
||||
params.byte1 = sunCalcResult["dusk_hours"];
|
||||
params.byte2 = sunCalcResult["dusk_minutes"];
|
||||
params.recipient = 2;//2 broadcast,
|
||||
params.register = 6;//Time of dusk - Reg 6
|
||||
params.register = 6;//Time of dusk
|
||||
params.rw = 1;//write
|
||||
|
||||
params.type = "cmd";
|
||||
params.type = "node-regular-write";
|
||||
params.timestamp = time + 60000;
|
||||
params.addMinutesToTimestamp = 60 * 3; //kazde 3 hodiny zisti novy dusk
|
||||
params.info = "Broadcast-duskTime";
|
||||
|
|
@ -1074,17 +1065,15 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
{
|
||||
//run broadcast Time of dawn
|
||||
let params = getParams();
|
||||
|
||||
params.address = 0xffffffff;//broadcast
|
||||
params.byte1 = sunCalcResult["dawn_hours"];
|
||||
params.byte2 = sunCalcResult["dawn_minutes"];
|
||||
params.recipient = 2; //2 broadcast
|
||||
params.register = 7;//Time of dawn - Reg 6
|
||||
params.register = 7;//Time of dawn
|
||||
params.rw = 1;//write
|
||||
|
||||
params.type = "cmd";
|
||||
params.type = "node-regular-write";
|
||||
params.timestamp = time + 60001;
|
||||
params.addMinutesToTimestamp = 60 * 3; //kazde 3 hodiny zisti novy dawn
|
||||
params.info = "Broadcast-dawnTime";
|
||||
|
|
@ -1093,7 +1082,6 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
{
|
||||
//run broadcast Actual time
|
||||
let params = getParams();
|
||||
|
||||
params.address = 0xffffffff;//broadcast
|
||||
|
|
@ -1102,8 +1090,7 @@ exports.install = function(instance) {
|
|||
params.recipient = 2; //2 broadcast
|
||||
params.register = 87;//Actual time
|
||||
params.rw = 1;//write
|
||||
|
||||
params.type = "cmd";
|
||||
params.type = "node-regular-write";
|
||||
params.timestamp = time + 60002;
|
||||
params.addMinutesToTimestamp = 5;
|
||||
params.info = "run broadcast: Actual time";
|
||||
|
|
@ -1113,8 +1100,7 @@ exports.install = function(instance) {
|
|||
|
||||
}
|
||||
|
||||
//process nodes & tasks
|
||||
//reportovanie pre platformu
|
||||
//process nodes & tasks - read node's data
|
||||
if (processNodes) {
|
||||
|
||||
let time = Date.now();
|
||||
|
|
@ -1124,9 +1110,6 @@ exports.install = function(instance) {
|
|||
let tbname = nodesData[k].tbname;
|
||||
let register = 0;
|
||||
|
||||
//logger.debug("generated cmd - buildTasks for node:", address);
|
||||
|
||||
//listOfCommands - READ
|
||||
for (let i = 0; i < listOfCommands.length; i++) {
|
||||
|
||||
register = listOfCommands[i];
|
||||
|
|
@ -1137,11 +1120,11 @@ exports.install = function(instance) {
|
|||
params.address = address;
|
||||
params.recipient = 1;
|
||||
params.register = register;
|
||||
params.type = "cmd";
|
||||
params.type = register == 1 ? "node-dimming-read" : "node-regular-read";
|
||||
params.tbname = tbname;
|
||||
params.timestamp = time + 5000 + i * 500 + addMinutesToTimestamp * 1000; //to make slight time difference
|
||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||
params.info = "generated cmd - buildTasks (node)";
|
||||
params.info = "Node regular read command";
|
||||
|
||||
tasks.push(params);
|
||||
}
|
||||
|
|
@ -1154,7 +1137,7 @@ exports.install = function(instance) {
|
|||
if (!init) return;
|
||||
|
||||
|
||||
//Master node FW version
|
||||
//Master node FW version - modifies SETTINGS.masterNodeIsResponding
|
||||
{
|
||||
let params = getParams();
|
||||
params.type = "cmd-master";
|
||||
|
|
@ -1165,7 +1148,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);
|
||||
}
|
||||
|
|
@ -1174,7 +1156,7 @@ exports.install = function(instance) {
|
|||
{
|
||||
let params = getParams();
|
||||
params.type = "process_profiles";
|
||||
params.timestamp = Date.now() + 60000;
|
||||
params.timestamp = Date.now() + 60001;
|
||||
params.addMinutesToTimestamp = 60;//60 = every hour
|
||||
params.info = "detekcia nespracovaných profilov linie a nodov";
|
||||
//params.debug = true;
|
||||
|
|
@ -1403,31 +1385,25 @@ exports.install = function(instance) {
|
|||
let node = params.address;
|
||||
|
||||
let line = null;
|
||||
let itIsNodeCommand;
|
||||
|
||||
if (nodesData[node] !== undefined) {
|
||||
line = nodesData[node].line;
|
||||
itIsNodeCommand = true;
|
||||
}
|
||||
|
||||
//rpc related
|
||||
if (nodesData[node] !== undefined) line = nodesData[node].line;
|
||||
if (params.line !== undefined) line = params.line;
|
||||
|
||||
let repeatTask = false;
|
||||
if (params.addMinutesToTimestamp > 0 || params.timePointName) repeatTask = true;
|
||||
|
||||
if (repeatTask) {
|
||||
if (type === "cmd" || type === "cmd-master") {
|
||||
//set next start time automatically
|
||||
tasks[0].timestamp = currentTimestamp + tasks[0].addMinutesToTimestamp * 60000;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (params.addMinutesToTimestamp > 0 || params.timePointName) {
|
||||
tasks[0].timestamp = currentTimestamp + tasks[0].addMinutesToTimestamp * 60000;
|
||||
} else {
|
||||
tasks.shift();
|
||||
}
|
||||
|
||||
//kontrola nespracovanych profilov nodov
|
||||
if (type == "process_profiles") {
|
||||
tasks[0].timestamp = currentTimestamp + tasks[0].addMinutesToTimestamp * 60000;
|
||||
|
||||
//na vsetky zapnutych liniach sa spracuju nespracovane profily nodov
|
||||
loadRelaysData();
|
||||
|
||||
interval = setInterval(runTasks, SHORT_INTERVAL);
|
||||
return;
|
||||
}
|
||||
|
|
@ -1504,13 +1480,12 @@ exports.install = function(instance) {
|
|||
const register = params.register;
|
||||
|
||||
if (!SETTINGS.masterNodeIsResponding) {
|
||||
//ak neodpoveda, nebudeme vykonavat ziadne commands, okrem cmd-terminal, a fw version
|
||||
//ak neodpoveda, nebudeme vykonavat ziadne commands, okrem cmd-terminal cmd-master
|
||||
errorHandler.sendMessageToService("Master node is not responding");
|
||||
|
||||
let stop = true;
|
||||
|
||||
//fw version - register == 4
|
||||
if (type == "cmd-terminal" || register == 4) stop = false;
|
||||
if (type == "cmd-terminal" || type == "cmd-master") stop = false;
|
||||
if (stop) {
|
||||
interval = setInterval(runTasks, LONG_INTERVAL);
|
||||
return;
|
||||
|
|
@ -1567,9 +1542,6 @@ exports.install = function(instance) {
|
|||
let sunCalcResult = calculateDuskDawn();
|
||||
params.byte1 = sunCalcResult["dusk_hours"];//h
|
||||
params.byte2 = sunCalcResult["dusk_minutes"];//m
|
||||
|
||||
//TODO astrohodiny
|
||||
let dusk = "Time of dusk: " + sunCalcResult["dusk"];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1579,11 +1551,7 @@ exports.install = function(instance) {
|
|||
let sunCalcResult = calculateDuskDawn();
|
||||
params.byte1 = sunCalcResult["dawn_hours"];//h
|
||||
params.byte2 = sunCalcResult["dawn_minutes"];//m
|
||||
|
||||
//TODO astrohodiny
|
||||
let dawn = "Time of dawn: " + sunCalcResult["dawn"];
|
||||
}
|
||||
|
||||
}
|
||||
//-----------------------
|
||||
|
||||
|
|
@ -1594,7 +1562,6 @@ exports.install = function(instance) {
|
|||
|
||||
let saveToTb = true;
|
||||
if (!tbname) saveToTb = false;
|
||||
let itIsNodeCommand = listOfCommands.includes(register); //reading data from node (voltage, current, dimming, status)
|
||||
|
||||
let resp = com_generic(node, params.recipient, params.rw, register, params.name, params.byte1, params.byte2, params.byte3, params.byte4);
|
||||
let readBytes = 11;
|
||||
|
|
@ -1615,23 +1582,13 @@ exports.install = function(instance) {
|
|||
let message_type = result.type;
|
||||
let error = result.error;
|
||||
|
||||
if (params.debug != "generated cmd") {
|
||||
//debug("writeData: done " + message_type + " duration: " + timeDiff + " message_type: " + params.debug, params);
|
||||
if (params.hasOwnProperty("debug")) {
|
||||
if (params.debug) {
|
||||
console.log("detected response:", result);
|
||||
logger.debug("Cmd-mngr: writeData done " + message_type + " duration: " + timeDiff + " type: " + params.debug, params, result);
|
||||
}
|
||||
}
|
||||
|
||||
// if(params.hasOwnProperty("debug"))
|
||||
// {
|
||||
// if(params.debug)
|
||||
// {
|
||||
// console.log("detected response:", result);
|
||||
|
||||
// logger.debug("writeData: done " + message_typetype + " duration: " + timeDiff + " type: " + params.debug, params, result);
|
||||
// }
|
||||
// }
|
||||
|
||||
//debug("writeData: done " + message_type + " duration: " + timeDiff + " message_type: " + params.debug);
|
||||
//debug("writeData done", message_type, "duration", timeDiff, "message_type", params.debug, result);
|
||||
|
||||
let values = {};
|
||||
|
||||
//CMD FINISHED
|
||||
|
|
@ -1664,6 +1621,7 @@ exports.install = function(instance) {
|
|||
if (itIsNodeCommand) {
|
||||
values.comm_status = "OK";
|
||||
values.status = "OK";
|
||||
nodesData[node].readout = { ...nodesData[node].readout, ...values };
|
||||
}
|
||||
|
||||
//master node
|
||||
|
|
@ -1682,8 +1640,8 @@ exports.install = function(instance) {
|
|||
//logger.debug("saveToTb", saveToTb, tbname, values);
|
||||
}
|
||||
|
||||
if (saveToTb) {
|
||||
sendTelemetry(values, tbname)
|
||||
if (saveToTb && type != "node-regular-read") {
|
||||
sendTelemetry(values, tbname);
|
||||
}
|
||||
else {
|
||||
if (type == "cmd-terminal") {
|
||||
|
|
@ -1749,7 +1707,18 @@ exports.install = function(instance) {
|
|||
|
||||
let updateStatus = updateNodeStatus(node, false);
|
||||
|
||||
console.log("cmd_man: handleNokRsPort: ", node, register, message);
|
||||
if (itIsNodeCommand) {
|
||||
values.comm_status = "NOK";
|
||||
nodesData[node].readout.comm_status = "NOK";
|
||||
}
|
||||
|
||||
if (updateStatus) {
|
||||
values.status = "NOK";
|
||||
nodesData[node].readout.status = "NOK";
|
||||
}
|
||||
|
||||
if (type === "node-regular-read") return;
|
||||
|
||||
//master node
|
||||
if (node == 0) {
|
||||
sendNotification("CMD Manager: process cmd", SETTINGS.rvoTbName, "master_node_is_not_responding", {}, "", SEND_TO.tb, instance, "rvo_status");
|
||||
|
|
@ -1769,21 +1738,21 @@ exports.install = function(instance) {
|
|||
}
|
||||
}
|
||||
|
||||
if (itIsNodeCommand) {
|
||||
values.comm_status = "NOK";
|
||||
}
|
||||
|
||||
if (updateStatus) {
|
||||
values.status = "NOK";
|
||||
}
|
||||
|
||||
// console.log("------",node, register, type, itIsNodeCommand, updateStatus, saveToTb, values);
|
||||
if (saveToTb && Object.keys(values).length > 0) {
|
||||
sendTelemetry(values, tbName)
|
||||
if (saveToTb) {
|
||||
sendTelemetry(values, tbName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function sendNodesData() {
|
||||
Object.keys(nodesData).forEach(node => {
|
||||
if (nodesData[node]["status"] !== "OFFLINE") {
|
||||
sendTelemetry(nodesData[node].readout, nodesData[node].tbname);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* function handles requests from terminal
|
||||
|
|
@ -1871,7 +1840,7 @@ exports.install = function(instance) {
|
|||
"number_of_luminaires": number_of_luminaires,
|
||||
"number_of_ok_luminaires": number_of_ok_luminaires,
|
||||
"number_of_nok_luminaires": number_of_nok_luminaires,
|
||||
"edge_date_time": ts
|
||||
"edge_date_time": ts - ts % 60000 //round to full minute
|
||||
};
|
||||
|
||||
sendTelemetry(values, SETTINGS.rvoTbName, ts);
|
||||
|
|
@ -1934,11 +1903,11 @@ exports.install = function(instance) {
|
|||
clearInterval(interval);
|
||||
clearInterval(customTasksInterval);
|
||||
clearInterval(setCorrectTime);
|
||||
clearInterval(sendNodeReadout);
|
||||
rsPort.close();
|
||||
});
|
||||
|
||||
|
||||
instance.on("0", flowdata => {
|
||||
instance.on("0", _ => {
|
||||
main();
|
||||
})
|
||||
|
||||
|
|
@ -2142,20 +2111,17 @@ exports.install = function(instance) {
|
|||
value = parseInt(value);
|
||||
if (value > 0) value = value + 128;
|
||||
|
||||
//set dimming - LUM1_13 - 647 je node linie 1 kt. dobre vidime
|
||||
params.type = "cmd";
|
||||
params.type = "node-onetime-write";
|
||||
params.tbname = tbname;
|
||||
params.address = node;
|
||||
params.register = 1;//dimming
|
||||
params.recipient = 1;//slave
|
||||
params.register = 1;
|
||||
params.recipient = 1;
|
||||
params.byte4 = value;
|
||||
params.rw = 1;//write
|
||||
params.rw = 1;
|
||||
params.timestamp = PRIORITY_TYPES.high_priority;
|
||||
params.info = 'set dimming from platform';
|
||||
//params.debug = true;
|
||||
|
||||
//ak linia je
|
||||
|
||||
//debug(params);
|
||||
logger.debug("dimming", params);
|
||||
|
||||
|
|
@ -2168,15 +2134,15 @@ exports.install = function(instance) {
|
|||
{
|
||||
let params = getParams(PRIORITY_TYPES.high_priority);
|
||||
|
||||
params.type = "cmd";
|
||||
params.type = "node-onetime-read";
|
||||
params.tbname = tbname;
|
||||
params.address = node;
|
||||
params.register = 1;//dimming
|
||||
params.recipient = 1;//slave
|
||||
params.rw = 0;//read
|
||||
params.register = 1;
|
||||
params.recipient = 1;
|
||||
params.rw = 0;
|
||||
params.timestamp = PRIORITY_TYPES.high_priority;
|
||||
params.info = 'read dimming (after set dimming from platform)';
|
||||
params.debug = true;
|
||||
//params.debug = true;
|
||||
|
||||
tasks.push(params);
|
||||
}
|
||||
|
|
@ -2185,15 +2151,15 @@ exports.install = function(instance) {
|
|||
{
|
||||
let params = getParams(PRIORITY_TYPES.high_priority);
|
||||
|
||||
params.type = "cmd";
|
||||
params.type = "node-onetime-read";
|
||||
params.tbname = tbname;
|
||||
params.address = node;
|
||||
params.register = 76;
|
||||
params.recipient = 1;//slave
|
||||
params.rw = 0;//read
|
||||
params.recipient = 1;
|
||||
params.rw = 0;
|
||||
params.timestamp = PRIORITY_TYPES.high_priority;
|
||||
params.info = 'read Input Power (after set dimming from platform)';
|
||||
params.debug = true;
|
||||
//params.debug = true;
|
||||
|
||||
tasks.push(params);
|
||||
}
|
||||
|
|
@ -2202,15 +2168,15 @@ exports.install = function(instance) {
|
|||
{
|
||||
let params = getParams(PRIORITY_TYPES.high_priority);
|
||||
|
||||
params.type = "cmd";
|
||||
params.type = "node-onetime-read";
|
||||
params.tbname = tbname;
|
||||
params.address = node;
|
||||
params.register = 75;
|
||||
params.recipient = 1;//slave
|
||||
params.rw = 0;//read
|
||||
params.recipient = 1;
|
||||
params.rw = 0;
|
||||
params.timestamp = PRIORITY_TYPES.high_priority;
|
||||
params.info = 'read Input Current (after set dimming from platform)';
|
||||
params.debug = true;
|
||||
//params.debug = true;
|
||||
|
||||
tasks.push(params);
|
||||
}
|
||||
|
|
@ -2219,24 +2185,22 @@ exports.install = function(instance) {
|
|||
{
|
||||
let params = getParams(PRIORITY_TYPES.high_priority);
|
||||
|
||||
params.type = "cmd";
|
||||
params.type = "node-onetime-read";
|
||||
params.tbname = tbname;
|
||||
params.address = node;
|
||||
params.register = 77;
|
||||
params.recipient = 1;//slave
|
||||
params.rw = 0;//read
|
||||
params.recipient = 1;
|
||||
params.rw = 0;
|
||||
params.timestamp = PRIORITY_TYPES.high_priority;
|
||||
params.info = 'read power factor - Cos phi (after set dimming from platform)';
|
||||
params.debug = true;
|
||||
params.info = 'read power factor (after set dimming from platform)';
|
||||
//params.debug = true;
|
||||
|
||||
tasks.push(params);
|
||||
}
|
||||
|
||||
}, 4000);
|
||||
|
||||
|
||||
nodeWasFound = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -2803,7 +2767,7 @@ exports.install = function(instance) {
|
|||
values["dawn_time"] = timestamp;
|
||||
}
|
||||
|
||||
//FW verzia
|
||||
//FW verzia nodu
|
||||
if (register == 89) {
|
||||
//formát: "Byte3: Byte2.Byte1 (Byte0)"
|
||||
values["fw_version"] = byte3 + ":" + byte2 + "." + byte1 + "(" + byte0 + ")";
|
||||
|
|
|
|||
|
|
@ -62,9 +62,10 @@ exports.install = async function(instance) {
|
|||
//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"];
|
||||
Object.keys(dbs.nodesData).forEach(node => dbs.nodesData[node].readout = {})
|
||||
|
||||
dbs.settings = {
|
||||
edge_fw_version: "2025-01-21", //rok-mesiac-den
|
||||
edge_fw_version: "2025-01-30", //rok-mesiac-den
|
||||
language: responseSettings[0]["lang"],
|
||||
rvo_name: responseSettings[0]["rvo_name"],
|
||||
project_id: responseSettings[0]["project_id"],
|
||||
|
|
|
|||
|
|
@ -5,11 +5,10 @@ class DataToTbHandler {
|
|||
|
||||
// time, after new value for the given key will be resend to tb (e.g. {status: "OK"})
|
||||
this.timeToHoldTbValue = 30 * 60; //30 minutes
|
||||
|
||||
this.previousValues = {};
|
||||
this.debug = false;
|
||||
this.messageCounter = 0;
|
||||
|
||||
this.itIsNodeReadout = false;
|
||||
this.sender = "";
|
||||
|
||||
// if attribute change difference is less than limit value, we do not send to tb.
|
||||
|
|
@ -25,11 +24,12 @@ class DataToTbHandler {
|
|||
Phase_2_power: 2,
|
||||
Phase_3_power: 2,
|
||||
total_power: 2,
|
||||
total_energy: 1,
|
||||
Phase_1_pow_factor: 0.1,
|
||||
Phase_2_pow_factor: 0.1,
|
||||
Phase_3_pow_factor: 0.1,
|
||||
power_factor: 0.1,
|
||||
lifetime: 0.5,
|
||||
lifetime: 2,
|
||||
voltage: 2,
|
||||
power: 2,
|
||||
frequency: 3,
|
||||
|
|
@ -59,28 +59,34 @@ class DataToTbHandler {
|
|||
return true;
|
||||
}
|
||||
|
||||
sendToTb(dataToTb, instance) {
|
||||
|
||||
let keys = Object.keys(dataToTb);
|
||||
sendToTb(data, instance) {
|
||||
|
||||
//not to modify data object, we do deep copy:
|
||||
let dataCopy = JSON.parse(JSON.stringify(data));
|
||||
|
||||
let keys = Object.keys(dataCopy);
|
||||
|
||||
if (keys.length == 0) {
|
||||
if (this.debug) console.log("sendToTb received empty object", dataToTb);
|
||||
if (this.debug) console.log("sendToTb received empty object", dataCopy);
|
||||
return;
|
||||
}
|
||||
|
||||
let tbname = keys[0];
|
||||
let ts;
|
||||
|
||||
let arrayOfValues = dataToTb[tbname];
|
||||
let arrayOfValues = dataCopy[tbname];
|
||||
let arrayOfValuesToSend = [];
|
||||
|
||||
for (let i = 0; i < arrayOfValues.length; i++) {
|
||||
|
||||
ts = arrayOfValues[i].ts;
|
||||
let values = this.prepareValuesForTb(tbname, ts, arrayOfValues[i].values);
|
||||
|
||||
if (!this.isEmptyObject(values)) {
|
||||
arrayOfValuesToSend.push({ ts: ts, values: values });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (arrayOfValuesToSend.length == 0) {
|
||||
|
|
@ -99,15 +105,20 @@ class DataToTbHandler {
|
|||
instance.send(this.index, dataToTbModified);
|
||||
}
|
||||
|
||||
|
||||
getDiffTimestamp(key) {
|
||||
//TODO set different value for given key!!!
|
||||
//if(key == "status") this.timeToHoldTbValue = 2*60*60;//2h
|
||||
return this.timeToHoldTbValue * 1000;
|
||||
}
|
||||
|
||||
|
||||
prepareValuesForTb(tbname, timestamp, values) {
|
||||
|
||||
let keys = Object.keys(values);
|
||||
|
||||
if (keys.includes("lifetime")) this.itIsNodeReadout = true;
|
||||
|
||||
if (!this.previousValues.hasOwnProperty(tbname)) {
|
||||
this.previousValues[tbname] = {};
|
||||
}
|
||||
|
|
@ -115,6 +126,7 @@ class DataToTbHandler {
|
|||
//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];
|
||||
|
||||
|
|
@ -123,15 +135,34 @@ class DataToTbHandler {
|
|||
continue;
|
||||
}
|
||||
|
||||
// attributeData ==> voltage: {ts:333333, value:5}
|
||||
// attributeData ==> {voltage: {ts:333333, value:5}}
|
||||
let attributeData = this.previousValues[tbname][key];
|
||||
let attributeToChange = false;
|
||||
if (key in this.attributeChangeLimit) attributeToChange = true;
|
||||
let limit = this.attributeChangeLimit[key];
|
||||
let timestampDiffToRemoveKey;
|
||||
|
||||
//this will ensure "node statecode" will be sent just once an hour
|
||||
if (this.itIsNodeReadout && key === "statecode") {
|
||||
attributeData.value = value;
|
||||
this.itIsNodeReadout = false;
|
||||
timestampDiffToRemoveKey = 1 * 60 * 60 * 1000; // 1 hour
|
||||
}
|
||||
|
||||
if (key === "twilight_sensor" && value > 100) {
|
||||
attributeData.value = value;
|
||||
}
|
||||
|
||||
//if edge, master or node version do not change, send just once a day:
|
||||
if (["edge_fw_version", "master_node_version", "fw_version"].includes(key)) {
|
||||
timestampDiffToRemoveKey = 24 * 60 * 60 * 1000;
|
||||
}
|
||||
|
||||
if (attributeData.value === value || attributeToChange && Math.abs(attributeData.value - value) < limit) {
|
||||
|
||||
let diff = timestamp - attributeData.ts;
|
||||
let timestampDiffToRemoveKey = this.getDiffTimestamp(key);
|
||||
if (!timestampDiffToRemoveKey) timestampDiffToRemoveKey = this.getDiffTimestamp(key);
|
||||
|
||||
if (diff > timestampDiffToRemoveKey) {
|
||||
attributeData.ts = Date.now();
|
||||
//if(this.debug) console.log(this.sender + ": update ts for key", key, "diff is", diff, "messageCounter", this.messageCounter);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue