PR request changes && rvo status added for all devices - em, twilight, thermometer
This commit is contained in:
parent
880edfc604
commit
1b4b9ca973
8 changed files with 230 additions and 195 deletions
|
|
@ -80,6 +80,8 @@ const PRIORITY_TYPES = {
|
|||
node_cmd: 6
|
||||
}
|
||||
|
||||
const TIME_AFTER_WE_UPDATE_LAST_NODE_COMMUNICATION = 600000; // 10 minutes
|
||||
|
||||
//list of command calls to process. Processing in runTasks function
|
||||
let tasks = [];
|
||||
|
||||
|
|
@ -141,7 +143,6 @@ let cmdCounter = {};//key is node, value is counter
|
|||
let cmdNOKNodeCounter = {};//key is node, value is counter
|
||||
|
||||
let testTbName = "deleteAfterTesting" //for status testing purposes;
|
||||
|
||||
//END OF VARIABLE SETTINGS
|
||||
//--------------------------------
|
||||
|
||||
|
|
@ -786,12 +787,9 @@ exports.install = function(instance) {
|
|||
params.register = 87;//Actual time
|
||||
params.rw = 1;//write
|
||||
|
||||
let timestampStart = PRIORITY_TYPES.node_broadcast;
|
||||
|
||||
//other values
|
||||
params.type = "cmd";
|
||||
//params.tbname = tbname;
|
||||
params.timestamp = timestampStart;
|
||||
params.timestamp = Date.now() + 60000;
|
||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||
params.info = "run broadcast: Actual time";
|
||||
|
||||
|
|
@ -1261,18 +1259,13 @@ exports.install = function(instance) {
|
|||
params.register = 6;//Time of dusk - Reg 6
|
||||
params.rw = 1;//write
|
||||
|
||||
let timestampStart = PRIORITY_TYPES.node_broadcast;
|
||||
|
||||
//other values
|
||||
params.type = "cmd";
|
||||
//params.tbname = tbname;
|
||||
params.timestamp = timestampStart;
|
||||
params.timestamp = Date.now() + 60000;
|
||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||
params.info = "Broadcast-duskTime";
|
||||
|
||||
tasks.push(params);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -1296,12 +1289,8 @@ exports.install = function(instance) {
|
|||
params.register = 7;//Time of dawn - Reg 6
|
||||
params.rw = 1;//write
|
||||
|
||||
let timestampStart = PRIORITY_TYPES.node_broadcast;
|
||||
|
||||
//other values
|
||||
params.type = "cmd";
|
||||
//params.tbname = tbname;
|
||||
params.timestamp = timestampStart;
|
||||
params.timestamp = Date.now() + 60000;
|
||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||
params.info = "Broadcast-dawnTime";
|
||||
|
|
@ -1329,12 +1318,8 @@ exports.install = function(instance) {
|
|||
params.register = 87;//Actual time
|
||||
params.rw = 1;//write
|
||||
|
||||
let timestampStart = PRIORITY_TYPES.node_broadcast;
|
||||
|
||||
//other values
|
||||
params.type = "cmd";
|
||||
//params.tbname = tbname;
|
||||
params.timestamp = timestampStart;
|
||||
params.timestamp = Date.now() + 60000;
|
||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||
params.info = "run broadcast: Actual time";
|
||||
|
|
@ -1416,10 +1401,6 @@ exports.install = function(instance) {
|
|||
params.type = "cmd-master";
|
||||
params.register = 4;
|
||||
params.address = 0;
|
||||
|
||||
let timestampStart = PRIORITY_TYPES.fw_detection;
|
||||
params.timestamp = timestampStart;
|
||||
|
||||
params.timestamp = Date.now() + 60000;
|
||||
params.addMinutesToTimestamp = 5;
|
||||
params.tbname = FLOW.OMS_edgeName;
|
||||
|
|
@ -1435,9 +1416,7 @@ exports.install = function(instance) {
|
|||
{
|
||||
let params = getParams(PRIORITY_TYPES.fw_detection);
|
||||
params.type = "process_profiles";
|
||||
|
||||
let timestampStart = PRIORITY_TYPES.relay_profile;
|
||||
params.timestamp = timestampStart;
|
||||
params.timestamp = Date.now() + 60000;
|
||||
params.addMinutesToTimestamp = 60;//60 = every hour
|
||||
params.info = "detekcia nespracovaných profilov linie a nodov";
|
||||
//params.debug = true;
|
||||
|
|
@ -1556,17 +1535,17 @@ exports.install = function(instance) {
|
|||
return true;
|
||||
}
|
||||
|
||||
if(newStatus == true && nodeCurrentStatus == true && nodeObj.time_of_last_communication > now - 600000){
|
||||
if(newStatus == true && nodeCurrentStatus == true && nodeObj.time_of_last_communication > now - TIME_AFTER_WE_UPDATE_LAST_NODE_COMMUNICATION){
|
||||
|
||||
if(node == 638 || node == 637) console.log("true true, return", node, now);
|
||||
return;
|
||||
}
|
||||
|
||||
if(newStatus == true && nodeCurrentStatus == true && nodeObj.time_of_last_communication < now - 600000)
|
||||
if(newStatus == true && nodeCurrentStatus == true && nodeObj.time_of_last_communication < now - TIME_AFTER_WE_UPDATE_LAST_NODE_COMMUNICATION)
|
||||
{
|
||||
dbNodes.modify({ time_of_last_communication: now}).where("node", node).make(function(builder) {
|
||||
builder.callback(function(err, response) {
|
||||
if(err == null) {
|
||||
if(!err) {
|
||||
nodeObj.time_of_last_communication = now;
|
||||
|
||||
if(node == 638 || node == 637) console.log('zapisane do db => status true & true', node, now)
|
||||
|
|
@ -1585,7 +1564,7 @@ exports.install = function(instance) {
|
|||
else {
|
||||
dbNodes.modify({ status: newStatus}).where("node", node).make(function(builder) {
|
||||
builder.callback(function(err, response) {
|
||||
if(err == null) {
|
||||
if(!err) {
|
||||
nodeObj.status = newStatus;
|
||||
|
||||
if(node == 638 || node == 637) console.log('zapisane do db => status false & true', node, now)
|
||||
|
|
@ -1600,7 +1579,7 @@ exports.install = function(instance) {
|
|||
{
|
||||
dbNodes.modify({ status: newStatus, time_of_last_communication: now}).where("node", node).make(function(builder) {
|
||||
builder.callback(function(err, response) {
|
||||
if(err == null) {
|
||||
if(!err) {
|
||||
nodeObj.status = newStatus;
|
||||
nodeObj.time_of_last_communication = now;
|
||||
|
||||
|
|
@ -1989,7 +1968,7 @@ exports.install = function(instance) {
|
|||
startTime = new Date();
|
||||
|
||||
let saveToTb = true;
|
||||
if(tbname == null || tbname == undefined || tbname == "") saveToTb = false;
|
||||
if(!tbname) saveToTb = false;
|
||||
let itIsNodeCommand = listOfCommands.includes(register); //reading data from node (voltage, current, dimming, status)
|
||||
|
||||
let resp = com_generic(nodeAddress, params.recipient, params.rw, register, params.name, params.byte1, params.byte2, params.byte3, params.byte4);
|
||||
|
|
@ -2053,18 +2032,15 @@ exports.install = function(instance) {
|
|||
let result = cmdCounterResolve(nodeAddress);
|
||||
if(result == 0)
|
||||
{
|
||||
|
||||
dbNodes.modify({ processed: true }).where("node", nodeAddress).make(function(builder) {
|
||||
|
||||
builder.callback(function(err, response) {
|
||||
|
||||
sendNotification("CMD Manager: process cmd", FLOW.OMS_edgeName, "dimming_profile_was_successfully_received_by_node", {node: nodeAddress}, "", SEND_TO.tb, instance );
|
||||
|
||||
logger.debug( "--> profil úspešne odoslaný na node č. " + nodeAddress);
|
||||
nodesData[nodeAddress].processed = true;
|
||||
|
||||
});
|
||||
sendNotification("CMD Manager: process cmd", FLOW.OMS_edgeName, "dimming_profile_was_successfully_received_by_node", {node: nodeAddress}, "", SEND_TO.tb, instance );
|
||||
|
||||
logger.debug( "--> profil úspešne odoslaný na node č. " + nodeAddress);
|
||||
nodesData[nodeAddress].processed = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2296,7 +2272,7 @@ exports.install = function(instance) {
|
|||
else responseObj["bytes"] = data;
|
||||
|
||||
let refFlowdata = refFlowdataObj[params.refFlowdataKey];
|
||||
if(refFlowdata !== undefined)
|
||||
if(refFlowdata)
|
||||
{
|
||||
refFlowdata.data = responseObj;
|
||||
instance.send(SEND_TO.http_response, refFlowdata);
|
||||
|
|
@ -2311,17 +2287,21 @@ exports.install = function(instance) {
|
|||
|
||||
if(!FLOW.OMS_edgeName) return;
|
||||
|
||||
//Number of ok and nok nodes on platform does not equals to total number of nodes.
|
||||
//possible error is, that nodesData object is changing all the time. To make a proper calculation of ok,nok luminaires, we make a copy of it:
|
||||
let nodesData_clone = JSON.parse(JSON.stringify(nodesData));
|
||||
|
||||
const ts = Date.now();
|
||||
const keys = Object.keys(nodesData);
|
||||
const keys = Object.keys(nodesData_clone);
|
||||
|
||||
const number_of_luminaires = keys.length;
|
||||
let number_of_ok_luminaires = 0;
|
||||
let number_of_nok_luminaires = 0;
|
||||
|
||||
|
||||
for(let i = 0; i < keys.length; i++)
|
||||
{
|
||||
let key = keys[i];
|
||||
let nodeObj = nodesData[key];
|
||||
let nodeObj = nodesData_clone[key];
|
||||
if(nodeObj.tbname == undefined) continue;
|
||||
|
||||
if(nodeObj.status) number_of_ok_luminaires++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue