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
3
config
3
config
|
|
@ -8,5 +8,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_adress:string|latitude:number|longitude:number|mqtt_host:string|mqtt_clientid:string|mqtt_username:string|mqtt_port:number|maintanace_mode:boolean|projects_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
|
table.settings : rvo_name:string|lang:string|temperature_adress:string|latitude:number|longitude:number|mqtt_host:string|mqtt_clientid:string|mqtt_username:string|mqtt_port:number|maintanace_mode:boolean|projects_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
|
||||||
table.pins : pin:number|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
|
||||||
|
table.status : thermometer:string|em:string|twilight_sensor:string
|
||||||
|
|
|
||||||
2
databases/status.table
Normal file
2
databases/status.table
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
thermometer:string|em:string|twilight_sensor:string
|
||||||
|
+|OK|OK|OK|.............
|
||||||
|
|
@ -80,6 +80,8 @@ const PRIORITY_TYPES = {
|
||||||
node_cmd: 6
|
node_cmd: 6
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TIME_AFTER_WE_UPDATE_LAST_NODE_COMMUNICATION = 600000; // 10 minutes
|
||||||
|
|
||||||
//list of command calls to process. Processing in runTasks function
|
//list of command calls to process. Processing in runTasks function
|
||||||
let tasks = [];
|
let tasks = [];
|
||||||
|
|
||||||
|
|
@ -141,7 +143,6 @@ let cmdCounter = {};//key is node, value is counter
|
||||||
let cmdNOKNodeCounter = {};//key is node, value is counter
|
let cmdNOKNodeCounter = {};//key is node, value is counter
|
||||||
|
|
||||||
let testTbName = "deleteAfterTesting" //for status testing purposes;
|
let testTbName = "deleteAfterTesting" //for status testing purposes;
|
||||||
|
|
||||||
//END OF VARIABLE SETTINGS
|
//END OF VARIABLE SETTINGS
|
||||||
//--------------------------------
|
//--------------------------------
|
||||||
|
|
||||||
|
|
@ -786,12 +787,9 @@ exports.install = function(instance) {
|
||||||
params.register = 87;//Actual time
|
params.register = 87;//Actual time
|
||||||
params.rw = 1;//write
|
params.rw = 1;//write
|
||||||
|
|
||||||
let timestampStart = PRIORITY_TYPES.node_broadcast;
|
|
||||||
|
|
||||||
//other values
|
//other values
|
||||||
params.type = "cmd";
|
params.type = "cmd";
|
||||||
//params.tbname = tbname;
|
params.timestamp = Date.now() + 60000;
|
||||||
params.timestamp = timestampStart;
|
|
||||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||||
params.info = "run broadcast: Actual time";
|
params.info = "run broadcast: Actual time";
|
||||||
|
|
||||||
|
|
@ -1261,18 +1259,13 @@ exports.install = function(instance) {
|
||||||
params.register = 6;//Time of dusk - Reg 6
|
params.register = 6;//Time of dusk - Reg 6
|
||||||
params.rw = 1;//write
|
params.rw = 1;//write
|
||||||
|
|
||||||
let timestampStart = PRIORITY_TYPES.node_broadcast;
|
|
||||||
|
|
||||||
//other values
|
//other values
|
||||||
params.type = "cmd";
|
params.type = "cmd";
|
||||||
//params.tbname = tbname;
|
|
||||||
params.timestamp = timestampStart;
|
|
||||||
params.timestamp = Date.now() + 60000;
|
params.timestamp = Date.now() + 60000;
|
||||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||||
params.info = "Broadcast-duskTime";
|
params.info = "Broadcast-duskTime";
|
||||||
|
|
||||||
tasks.push(params);
|
tasks.push(params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -1296,12 +1289,8 @@ exports.install = function(instance) {
|
||||||
params.register = 7;//Time of dawn - Reg 6
|
params.register = 7;//Time of dawn - Reg 6
|
||||||
params.rw = 1;//write
|
params.rw = 1;//write
|
||||||
|
|
||||||
let timestampStart = PRIORITY_TYPES.node_broadcast;
|
|
||||||
|
|
||||||
//other values
|
//other values
|
||||||
params.type = "cmd";
|
params.type = "cmd";
|
||||||
//params.tbname = tbname;
|
|
||||||
params.timestamp = timestampStart;
|
|
||||||
params.timestamp = Date.now() + 60000;
|
params.timestamp = Date.now() + 60000;
|
||||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||||
params.info = "Broadcast-dawnTime";
|
params.info = "Broadcast-dawnTime";
|
||||||
|
|
@ -1329,12 +1318,8 @@ exports.install = function(instance) {
|
||||||
params.register = 87;//Actual time
|
params.register = 87;//Actual time
|
||||||
params.rw = 1;//write
|
params.rw = 1;//write
|
||||||
|
|
||||||
let timestampStart = PRIORITY_TYPES.node_broadcast;
|
|
||||||
|
|
||||||
//other values
|
//other values
|
||||||
params.type = "cmd";
|
params.type = "cmd";
|
||||||
//params.tbname = tbname;
|
|
||||||
params.timestamp = timestampStart;
|
|
||||||
params.timestamp = Date.now() + 60000;
|
params.timestamp = Date.now() + 60000;
|
||||||
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
params.addMinutesToTimestamp = addMinutesToTimestamp;
|
||||||
params.info = "run broadcast: Actual time";
|
params.info = "run broadcast: Actual time";
|
||||||
|
|
@ -1416,10 +1401,6 @@ exports.install = function(instance) {
|
||||||
params.type = "cmd-master";
|
params.type = "cmd-master";
|
||||||
params.register = 4;
|
params.register = 4;
|
||||||
params.address = 0;
|
params.address = 0;
|
||||||
|
|
||||||
let timestampStart = PRIORITY_TYPES.fw_detection;
|
|
||||||
params.timestamp = timestampStart;
|
|
||||||
|
|
||||||
params.timestamp = Date.now() + 60000;
|
params.timestamp = Date.now() + 60000;
|
||||||
params.addMinutesToTimestamp = 5;
|
params.addMinutesToTimestamp = 5;
|
||||||
params.tbname = FLOW.OMS_edgeName;
|
params.tbname = FLOW.OMS_edgeName;
|
||||||
|
|
@ -1435,9 +1416,7 @@ exports.install = function(instance) {
|
||||||
{
|
{
|
||||||
let params = getParams(PRIORITY_TYPES.fw_detection);
|
let params = getParams(PRIORITY_TYPES.fw_detection);
|
||||||
params.type = "process_profiles";
|
params.type = "process_profiles";
|
||||||
|
params.timestamp = Date.now() + 60000;
|
||||||
let timestampStart = PRIORITY_TYPES.relay_profile;
|
|
||||||
params.timestamp = timestampStart;
|
|
||||||
params.addMinutesToTimestamp = 60;//60 = every hour
|
params.addMinutesToTimestamp = 60;//60 = every hour
|
||||||
params.info = "detekcia nespracovaných profilov linie a nodov";
|
params.info = "detekcia nespracovaných profilov linie a nodov";
|
||||||
//params.debug = true;
|
//params.debug = true;
|
||||||
|
|
@ -1556,17 +1535,17 @@ exports.install = function(instance) {
|
||||||
return true;
|
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);
|
if(node == 638 || node == 637) console.log("true true, return", node, now);
|
||||||
return;
|
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) {
|
dbNodes.modify({ time_of_last_communication: now}).where("node", node).make(function(builder) {
|
||||||
builder.callback(function(err, response) {
|
builder.callback(function(err, response) {
|
||||||
if(err == null) {
|
if(!err) {
|
||||||
nodeObj.time_of_last_communication = now;
|
nodeObj.time_of_last_communication = now;
|
||||||
|
|
||||||
if(node == 638 || node == 637) console.log('zapisane do db => status true & true', node, 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 {
|
else {
|
||||||
dbNodes.modify({ status: newStatus}).where("node", node).make(function(builder) {
|
dbNodes.modify({ status: newStatus}).where("node", node).make(function(builder) {
|
||||||
builder.callback(function(err, response) {
|
builder.callback(function(err, response) {
|
||||||
if(err == null) {
|
if(!err) {
|
||||||
nodeObj.status = newStatus;
|
nodeObj.status = newStatus;
|
||||||
|
|
||||||
if(node == 638 || node == 637) console.log('zapisane do db => status false & true', node, now)
|
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) {
|
dbNodes.modify({ status: newStatus, time_of_last_communication: now}).where("node", node).make(function(builder) {
|
||||||
builder.callback(function(err, response) {
|
builder.callback(function(err, response) {
|
||||||
if(err == null) {
|
if(!err) {
|
||||||
nodeObj.status = newStatus;
|
nodeObj.status = newStatus;
|
||||||
nodeObj.time_of_last_communication = now;
|
nodeObj.time_of_last_communication = now;
|
||||||
|
|
||||||
|
|
@ -1989,7 +1968,7 @@ exports.install = function(instance) {
|
||||||
startTime = new Date();
|
startTime = new Date();
|
||||||
|
|
||||||
let saveToTb = true;
|
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 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);
|
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);
|
let result = cmdCounterResolve(nodeAddress);
|
||||||
if(result == 0)
|
if(result == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
dbNodes.modify({ processed: true }).where("node", nodeAddress).make(function(builder) {
|
dbNodes.modify({ processed: true }).where("node", nodeAddress).make(function(builder) {
|
||||||
|
|
||||||
builder.callback(function(err, response) {
|
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 );
|
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);
|
logger.debug( "--> profil úspešne odoslaný na node č. " + nodeAddress);
|
||||||
nodesData[nodeAddress].processed = true;
|
nodesData[nodeAddress].processed = true;
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2296,7 +2272,7 @@ exports.install = function(instance) {
|
||||||
else responseObj["bytes"] = data;
|
else responseObj["bytes"] = data;
|
||||||
|
|
||||||
let refFlowdata = refFlowdataObj[params.refFlowdataKey];
|
let refFlowdata = refFlowdataObj[params.refFlowdataKey];
|
||||||
if(refFlowdata !== undefined)
|
if(refFlowdata)
|
||||||
{
|
{
|
||||||
refFlowdata.data = responseObj;
|
refFlowdata.data = responseObj;
|
||||||
instance.send(SEND_TO.http_response, refFlowdata);
|
instance.send(SEND_TO.http_response, refFlowdata);
|
||||||
|
|
@ -2311,17 +2287,21 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
if(!FLOW.OMS_edgeName) return;
|
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 ts = Date.now();
|
||||||
const keys = Object.keys(nodesData);
|
const keys = Object.keys(nodesData_clone);
|
||||||
|
|
||||||
const number_of_luminaires = keys.length;
|
const number_of_luminaires = keys.length;
|
||||||
let number_of_ok_luminaires = 0;
|
let number_of_ok_luminaires = 0;
|
||||||
let number_of_nok_luminaires = 0;
|
let number_of_nok_luminaires = 0;
|
||||||
|
|
||||||
for(let i = 0; i < keys.length; i++)
|
for(let i = 0; i < keys.length; i++)
|
||||||
{
|
{
|
||||||
let key = keys[i];
|
let key = keys[i];
|
||||||
let nodeObj = nodesData[key];
|
let nodeObj = nodesData_clone[key];
|
||||||
if(nodeObj.tbname == undefined) continue;
|
if(nodeObj.tbname == undefined) continue;
|
||||||
|
|
||||||
if(nodeObj.status) number_of_ok_luminaires++;
|
if(nodeObj.status) number_of_ok_luminaires++;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ exports.color = '#2134B0';
|
||||||
exports.input = 3;
|
exports.input = 3;
|
||||||
exports.output = ["red", "white", "yellow"];
|
exports.output = ["red", "white", "yellow"];
|
||||||
exports.click = false;
|
exports.click = false;
|
||||||
exports.author = 'Daniel Segeš';
|
|
||||||
exports.icon = 'bolt';
|
exports.icon = 'bolt';
|
||||||
exports.options = { edge: "undefined" };
|
exports.options = { edge: "undefined" };
|
||||||
|
|
||||||
|
|
@ -136,9 +135,11 @@ exports.install = function(instance) {
|
||||||
//process.exit(1);
|
//process.exit(1);
|
||||||
})
|
})
|
||||||
|
|
||||||
let previousValues = {temperature: 0};
|
// temperature value is initialized to -1000. It can be literally anything, we just needs to be able to enter if block in ws.onmessage function, when first temperatere data comes
|
||||||
|
let previousValues = {temperature: {value: -1000, lastTimeTemperatureReceived: Date.now() / 1000}};
|
||||||
let rsPortReceivedData = [];
|
let rsPortReceivedData = [];
|
||||||
|
|
||||||
|
//to be able to get proper twilight values, when
|
||||||
let twilight_sensor_interval = 5;//minutes
|
let twilight_sensor_interval = 5;//minutes
|
||||||
let twilight_sensor = [];
|
let twilight_sensor = [];
|
||||||
const twilight_sensor_array = [];
|
const twilight_sensor_array = [];
|
||||||
|
|
@ -146,7 +147,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
let edgeName = "";
|
let edgeName = "";
|
||||||
|
|
||||||
monitor.info("DI_DO_Relay_Controller installed");
|
monitor.info("DIDO_Relay_Controller installed");
|
||||||
|
|
||||||
//key is PIN number , line: 0 = RVO
|
//key is PIN number , line: 0 = RVO
|
||||||
/*
|
/*
|
||||||
|
|
@ -173,28 +174,25 @@ exports.install = function(instance) {
|
||||||
const dbRelays = TABLE("relays");
|
const dbRelays = TABLE("relays");
|
||||||
let relaysData = {};//key is line
|
let relaysData = {};//key is line
|
||||||
|
|
||||||
|
const dbStatus = TABLE("status");
|
||||||
|
let statusData = null;
|
||||||
|
|
||||||
//status for calculating Statecodes
|
//status for calculating Statecodes
|
||||||
let deviceStatuses = {};//key is device name: temperature,....
|
let deviceStatus = {};//key is device name: temperature,....
|
||||||
deviceStatuses["state_of_main_switch"] = "Off";//Hlavný istič
|
deviceStatus["state_of_main_switch"] = "Off";//Hlavný istič
|
||||||
deviceStatuses["rotary_switch_state"] = "Off";//Prevádzkový mód
|
deviceStatus["rotary_switch_state"] = "Off";//Prevádzkový mód
|
||||||
deviceStatuses["door_condition"] = "closed";//Dverový kontakt
|
deviceStatus["door_condition"] = "closed";//Dverový kontakt
|
||||||
deviceStatuses["em"] = "OK";//elektromer rvo
|
deviceStatus["em"] = "OK";//elektromer rvo
|
||||||
deviceStatuses["temperature"] = "OK";//templomer
|
deviceStatus["temperature"] = "OK";//templomer
|
||||||
deviceStatuses["battery"] = "OK";//Batéria
|
deviceStatus["battery"] = "OK";//Batéria
|
||||||
deviceStatuses["power_supply"] = "OK";//Zdroj
|
deviceStatus["power_supply"] = "OK";//Zdroj
|
||||||
deviceStatuses["master_node"] = "OK";//MN - FLOW.OMS_masterNodeIsResponding
|
deviceStatus["master_node"] = "OK";//MN - FLOW.OMS_masterNodeIsResponding
|
||||||
deviceStatuses["no_voltage"] = "OK";//FLOW.OMS_no_voltage - výpadok napätia na fáze
|
deviceStatus["no_voltage"] = "OK";//FLOW.OMS_no_voltage - výpadok napätia na fáze
|
||||||
|
|
||||||
deviceStatuses["state_of_breaker"] = {};//"Off";//Istič
|
deviceStatus["state_of_breaker"] = {};//"Off";//Istič
|
||||||
deviceStatuses["state_of_contactor"] = {};//"Off";//Stykač
|
deviceStatus["state_of_contactor"] = {};//"Off";//Stykač
|
||||||
deviceStatuses["twilight_sensor"] = "OK"; //lux sensor
|
deviceStatus["twilight_sensor"] = "OK"; //lux sensor
|
||||||
|
|
||||||
/*
|
|
||||||
dbRelays.on('change', function(doc, old) {
|
|
||||||
console.log("'DI_DO_Controller - dbRelays.on('change'");
|
|
||||||
instance.send(SEND_TO.cmd_manager, "reload_relays");
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
const SerialPort = require('serialport');
|
const SerialPort = require('serialport');
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
|
|
@ -202,12 +200,15 @@ exports.install = function(instance) {
|
||||||
let ws = null;
|
let ws = null;
|
||||||
let rsPort = null;
|
let rsPort = null;
|
||||||
|
|
||||||
//const { exec } = require('child_process');
|
const { runSyncExec } = require('./helper/serialport_helper.js');
|
||||||
const { openPort, runSyncExec, writeData } = require('./helper/serialport_helper.js');
|
|
||||||
const { bytesToInt, resizeArray } = require('./helper/utils');
|
const { bytesToInt, resizeArray } = require('./helper/utils');
|
||||||
const { promisifyBuilder, makeMapFromDbResult } = require('./helper/db_helper.js');
|
const { promisifyBuilder, makeMapFromDbResult } = require('./helper/db_helper.js');
|
||||||
const { sendNotification, ERRWEIGHT } = require('./helper/notification_reporter.js');
|
const { sendNotification } = require('./helper/notification_reporter.js');
|
||||||
const bitwise = require('bitwise');
|
const bitwise = require('bitwise');
|
||||||
|
|
||||||
|
const DataToTbHandler = require('./helper/DataToTbHandler.js');
|
||||||
|
const tbHandler = new DataToTbHandler(SEND_TO.tb);
|
||||||
|
tbHandler.setSender(exports.title);
|
||||||
|
|
||||||
const ErrorToServiceHandler = require('./helper/ErrorToServiceHandler.js');
|
const ErrorToServiceHandler = require('./helper/ErrorToServiceHandler.js');
|
||||||
const errorHandler = new ErrorToServiceHandler();
|
const errorHandler = new ErrorToServiceHandler();
|
||||||
|
|
@ -219,6 +220,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
console.log(exports.title, "controller type: ", controller_type);
|
console.log(exports.title, "controller type: ", controller_type);
|
||||||
|
|
||||||
|
|
||||||
async function loadAllDb()
|
async function loadAllDb()
|
||||||
{
|
{
|
||||||
let responsePins = await promisifyBuilder(dbPins.find());
|
let responsePins = await promisifyBuilder(dbPins.find());
|
||||||
|
|
@ -227,6 +229,10 @@ exports.install = function(instance) {
|
||||||
let responseRelays = await promisifyBuilder(dbRelays.find());
|
let responseRelays = await promisifyBuilder(dbRelays.find());
|
||||||
relaysData = makeMapFromDbResult(responseRelays, "line");
|
relaysData = makeMapFromDbResult(responseRelays, "line");
|
||||||
|
|
||||||
|
let responseStatus = await promisifyBuilder(dbStatus.find());
|
||||||
|
statusData = responseStatus[0]; // {thermometer: '{"status":"OK","temperature":0}', em: 'OK', twilight_sensor: 'OK'}
|
||||||
|
deviceStatus["temperature"] = statusData.thermometer;
|
||||||
|
|
||||||
FLOW.OMS_rvo_tbname = relaysData[0].tbname;
|
FLOW.OMS_rvo_tbname = relaysData[0].tbname;
|
||||||
|
|
||||||
if(controller_type === "lm")
|
if(controller_type === "lm")
|
||||||
|
|
@ -300,7 +306,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
instance.send(SEND_TO.tb, dataToTb);
|
instance.send(SEND_TO.tb, dataToTb);
|
||||||
|
|
||||||
let time = 3*1000;
|
let time = 5*1000;
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "buildTasks"});
|
instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "buildTasks"});
|
||||||
|
|
||||||
|
|
@ -425,6 +431,7 @@ exports.install = function(instance) {
|
||||||
}, 150000)
|
}, 150000)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// SAMPLE DATA FROM WEBSOCKET
|
// SAMPLE DATA FROM WEBSOCKET
|
||||||
// {
|
// {
|
||||||
// glob_dev_id: 1,
|
// glob_dev_id: 1,
|
||||||
|
|
@ -453,25 +460,21 @@ exports.install = function(instance) {
|
||||||
data = JSON.parse(data.data);
|
data = JSON.parse(data.data);
|
||||||
|
|
||||||
// data comes in array except of "temperature" ==> it comes as an object
|
// data comes in array except of "temperature" ==> it comes as an object
|
||||||
if(!Array.isArray(data))
|
if(isObject(data))
|
||||||
{
|
{
|
||||||
let value = data['value'];
|
let value = data['value'];
|
||||||
|
previousValues["temperature"]["lastTimeTemperatureReceived"] = data['time'];
|
||||||
|
|
||||||
// temperature value comes very often. To handle it, we check if it change for more than 0.2 degrees, if yes, we send to TB
|
if(deviceStatus["temperature"] === "NOK")
|
||||||
if(Math.abs(previousValues["temperature"] - value) > 0.21 )
|
|
||||||
{
|
{
|
||||||
const dataToTb = {
|
writeThermometerStatusToDb("OK");
|
||||||
[FLOW.OMS_rvo_tbname]: [
|
}
|
||||||
{
|
|
||||||
"ts": Date.now(),
|
// temperature value comes very often. To handle it, we check if it change for more than 0.3 degrees, if yes, we send to TB
|
||||||
"values": {temperature: value}
|
if(Math.abs(previousValues["temperature"]["value"] - value) > 0.21 )
|
||||||
}
|
{
|
||||||
]
|
previousValues["temperature"]["value"] = value;
|
||||||
};
|
sendTelemetry({temperature: value}, FLOW.OMS_rvo_tbname);
|
||||||
|
|
||||||
deviceStatuses["temperature"] = "OK";
|
|
||||||
previousValues["temperature"] = value;
|
|
||||||
instance.send(SEND_TO.tb, dataToTb);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -517,7 +520,6 @@ exports.install = function(instance) {
|
||||||
// }, 150000)
|
// }, 150000)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
instance.on("close", () => {
|
instance.on("close", () => {
|
||||||
if(rsPort) rsPort.close();
|
if(rsPort) rsPort.close();
|
||||||
if(ws) ws.close();
|
if(ws) ws.close();
|
||||||
|
|
@ -526,6 +528,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
loadAllDb();
|
loadAllDb();
|
||||||
|
|
||||||
|
|
||||||
function getPin(line)
|
function getPin(line)
|
||||||
{
|
{
|
||||||
//conversionTable
|
//conversionTable
|
||||||
|
|
@ -605,13 +608,13 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
let bits = [];
|
let bits = [];
|
||||||
|
|
||||||
if(deviceStatuses["state_of_breaker"][line] == "On")
|
if(deviceStatus["state_of_breaker"][line] == "On")
|
||||||
{
|
{
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
else bits.push(1);
|
else bits.push(1);
|
||||||
|
|
||||||
if(deviceStatuses["state_of_contactor"][line] == "On")
|
if(deviceStatus["state_of_contactor"][line] == "On")
|
||||||
{
|
{
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
@ -720,7 +723,7 @@ exports.install = function(instance) {
|
||||||
//pin = "relay1_03" or "input1_01" ... we must make just "1_01" with slice method
|
//pin = "relay1_03" or "input1_01" ... we must make just "1_01" with slice method
|
||||||
let cmd = {"cmd": "set", "dev": "relay", "circuit": pin.slice(5), "value": 1};
|
let cmd = {"cmd": "set", "dev": "relay", "circuit": pin.slice(5), "value": 1};
|
||||||
ws.send(JSON.stringify(cmd));
|
ws.send(JSON.stringify(cmd));
|
||||||
//switchLogic(pin, 1)
|
switchLogic(pin, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -766,7 +769,7 @@ exports.install = function(instance) {
|
||||||
// if(!rsPort.isOpen && !ws)
|
// if(!rsPort.isOpen && !ws)
|
||||||
if(!rsPort && !ws)
|
if(!rsPort && !ws)
|
||||||
{
|
{
|
||||||
errLogger.error("di do controller - port or websocket is not opened");
|
errLogger.error("dido controller - port or websocket is not opened");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -797,7 +800,7 @@ exports.install = function(instance) {
|
||||||
//monitor.info("turnOffLine pin (relay)", pin);
|
//monitor.info("turnOffLine pin (relay)", pin);
|
||||||
let cmd = {"cmd": "set", "dev": "relay", "circuit": pin.slice(5), "value": 0};
|
let cmd = {"cmd": "set", "dev": "relay", "circuit": pin.slice(5), "value": 0};
|
||||||
ws.send(JSON.stringify(cmd));
|
ws.send(JSON.stringify(cmd));
|
||||||
//switchLogic(pin, 0)
|
switchLogic(pin, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -817,15 +820,17 @@ exports.install = function(instance) {
|
||||||
const status = flowdata.data.status;
|
const status = flowdata.data.status;
|
||||||
if(status == "NOK-twilight_sensor")
|
if(status == "NOK-twilight_sensor")
|
||||||
{
|
{
|
||||||
deviceStatuses["twilight_sensor"] = "NOK";
|
deviceStatus["twilight_sensor"] = "NOK";
|
||||||
}
|
}
|
||||||
else if(status == "NOK-em340" || status == "NOK-em111")
|
else if(status == "NOK-em340" || status == "NOK-em111")
|
||||||
{
|
{
|
||||||
deviceStatuses["em"] = "NOK";
|
deviceStatus["em"] = "NOK";
|
||||||
}
|
}
|
||||||
|
//"NOK-thermometer" comes just from LM. Unipi handles thermometer from ws evok.
|
||||||
else if(status == "NOK-thermometer")
|
else if(status == "NOK-thermometer")
|
||||||
{
|
{
|
||||||
deviceStatuses["temperature"] = "NOK";
|
previousValues["temperature"]["lastTimeTemperatureReceived"] = null;
|
||||||
|
deviceStatus["temperature"] = "NOK";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(flowdata.data?.values)
|
else if(flowdata.data?.values)
|
||||||
|
|
@ -834,16 +839,18 @@ exports.install = function(instance) {
|
||||||
if(values.hasOwnProperty("twilight_sensor"))
|
if(values.hasOwnProperty("twilight_sensor"))
|
||||||
{
|
{
|
||||||
instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "lux_sensor", value: values["twilight_sensor"]});
|
instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "lux_sensor", value: values["twilight_sensor"]});
|
||||||
deviceStatuses["twilight_sensor"] = "OK"
|
deviceStatus["twilight_sensor"] = "OK"
|
||||||
}
|
}
|
||||||
|
//"temperature" comes just from LM. Unipi handles thermometer from ws evok.
|
||||||
else if(values.hasOwnProperty("temperature"))
|
else if(values.hasOwnProperty("temperature"))
|
||||||
{
|
{
|
||||||
deviceStatuses["temperature"] = "OK";
|
previousValues["temperature"]["lastTimeTemperatureReceived"] = Date.now() / 1000; //time in seconds
|
||||||
|
deviceStatus["temperature"] = "OK";
|
||||||
}
|
}
|
||||||
// EM
|
// EM
|
||||||
else if(values.hasOwnProperty("total_power") || values.hasOwnProperty("total_energy") || values.hasOwnProperty("power_factor") || values.hasOwnProperty("Phase_1_voltage") || values.hasOwnProperty("Phase_1_current"))
|
else if(values.hasOwnProperty("total_power") || values.hasOwnProperty("total_energy") || values.hasOwnProperty("power_factor") || values.hasOwnProperty("Phase_1_voltage") || values.hasOwnProperty("Phase_1_current"))
|
||||||
{
|
{
|
||||||
deviceStatuses["em"] = "OK";
|
deviceStatus["em"] = "OK";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -876,7 +883,6 @@ exports.install = function(instance) {
|
||||||
else if(obj.command == "turnOnAlarm") turnOnAlarm();
|
else if(obj.command == "turnOnAlarm") turnOnAlarm();
|
||||||
else if(obj.command == "turnOffAlarm") turnOffAlarm();
|
else if(obj.command == "turnOffAlarm") turnOffAlarm();
|
||||||
|
|
||||||
|
|
||||||
//! ake data prichadzaju z cmd_manager.js ???
|
//! ake data prichadzaju z cmd_manager.js ???
|
||||||
//TODO transform to websocket
|
//TODO transform to websocket
|
||||||
if (Array.isArray(obj)){
|
if (Array.isArray(obj)){
|
||||||
|
|
@ -897,11 +903,11 @@ exports.install = function(instance) {
|
||||||
let bits = [];
|
let bits = [];
|
||||||
|
|
||||||
//Hlavný istič - state_of_main_switch
|
//Hlavný istič - state_of_main_switch
|
||||||
if(deviceStatuses["state_of_main_switch"] == "On")
|
if(deviceStatus["state_of_main_switch"] == "On")
|
||||||
{
|
{
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
else if(deviceStatuses["state_of_main_switch"] == "Off")
|
else if(deviceStatus["state_of_main_switch"] == "Off")
|
||||||
{
|
{
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
@ -909,19 +915,19 @@ exports.install = function(instance) {
|
||||||
//Prevádzkový mód - Manual, Off, Automatic, maintenance_mode = true/false // DAVA 2 BITY
|
//Prevádzkový mód - Manual, Off, Automatic, maintenance_mode = true/false // DAVA 2 BITY
|
||||||
if(!FLOW.OMS_maintenance_mode)
|
if(!FLOW.OMS_maintenance_mode)
|
||||||
{
|
{
|
||||||
if(deviceStatuses["rotary_switch_state"] == "Manual")
|
if(deviceStatus["rotary_switch_state"] == "Manual")
|
||||||
{
|
{
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deviceStatuses["rotary_switch_state"] == "Automatic")
|
if(deviceStatus["rotary_switch_state"] == "Automatic")
|
||||||
{
|
{
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deviceStatuses["rotary_switch_state"] == "Off")
|
if(deviceStatus["rotary_switch_state"] == "Off")
|
||||||
{
|
{
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
|
|
@ -933,7 +939,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dverový kontakt
|
//Dverový kontakt
|
||||||
if(deviceStatuses["door_condition"] == "closed")
|
if(deviceStatus["door_condition"] == "closed")
|
||||||
{
|
{
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
@ -943,7 +949,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//EM
|
//EM
|
||||||
if(deviceStatuses["em"] == "NOK")
|
if(deviceStatus["em"] == "NOK")
|
||||||
{
|
{
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
@ -953,7 +959,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Teplomer
|
//Teplomer
|
||||||
if(deviceStatuses["temperature"] == "NOK")
|
if(deviceStatus["temperature"] == "NOK")
|
||||||
{
|
{
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
@ -963,7 +969,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Batéria
|
//Batéria
|
||||||
if(deviceStatuses["battery"] == "NOK")
|
if(deviceStatus["battery"] == "NOK")
|
||||||
{
|
{
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
@ -973,7 +979,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Zdroj
|
//Zdroj
|
||||||
if(deviceStatuses["power_supply"] == "NOK")
|
if(deviceStatus["power_supply"] == "NOK")
|
||||||
{
|
{
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
@ -983,7 +989,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//MN
|
//MN
|
||||||
if(deviceStatuses["master_node"] == "NOK")
|
if(deviceStatus["master_node"] == "NOK")
|
||||||
{
|
{
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
@ -993,7 +999,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//výpadok napätia na fáze
|
//výpadok napätia na fáze
|
||||||
if(deviceStatuses["no_voltage"] == "NOK")
|
if(deviceStatus["no_voltage"] == "NOK")
|
||||||
{
|
{
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
@ -1002,7 +1008,7 @@ exports.install = function(instance) {
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deviceStatuses["twilight_sensor"] == "NOK")
|
if(deviceStatus["twilight_sensor"] == "NOK")
|
||||||
{
|
{
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
@ -1017,7 +1023,7 @@ exports.install = function(instance) {
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log("calculateStateCode - deviceStatuses", deviceStatuses);
|
// console.log("calculateStateCode - deviceStatus", deviceStatus);
|
||||||
// console.log("calculateStateCode", bits);
|
// console.log("calculateStateCode", bits);
|
||||||
|
|
||||||
let byte0 = bitwise.byte.write(bits.slice(0,8).reverse());
|
let byte0 = bitwise.byte.write(bits.slice(0,8).reverse());
|
||||||
|
|
@ -1031,16 +1037,54 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function sendDeviceStatus() {
|
||||||
|
|
||||||
|
const table = {
|
||||||
|
"OK": 1,
|
||||||
|
"NOK": 0
|
||||||
|
};
|
||||||
|
|
||||||
|
const dataToTb = {
|
||||||
|
"electrometer_status": table[deviceStatus["em"]],
|
||||||
|
"twilight_sensor_status": table[deviceStatus["twilight_sensor"]],
|
||||||
|
"thermometer_status": table[deviceStatus["temperature"]],
|
||||||
|
"phase_1_status": 1,
|
||||||
|
"phase_2_status": 1,
|
||||||
|
"phase_3_status": 1,
|
||||||
|
"master_node_status": table[deviceStatus["master_node"]]
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const phase of FLOW.OMS_no_voltage) {
|
||||||
|
if(phase == 1) dataToTb["phase_1_status"] = 0;
|
||||||
|
if(phase == 2) dataToTb["phase_2_status"] = 0;
|
||||||
|
if(phase == 3) dataToTb["phase_3_status"] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//thermometer did not send data for more than a hour. Time in seconds
|
||||||
|
if(deviceStatus["temperature"] === "OK")
|
||||||
|
{
|
||||||
|
if(previousValues["temperature"]["lastTimeTemperatureReceived"] + 3600 < Date.now() / 1000)
|
||||||
|
{
|
||||||
|
writeThermometerStatusToDb("NOK");
|
||||||
|
dataToTb["thermometer_status"] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sendTelemetry(dataToTb, FLOW.OMS_rvo_tbname);
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(sendDeviceStatus, 150000);
|
||||||
|
|
||||||
|
|
||||||
function checkFinalRVOStatus() {
|
function checkFinalRVOStatus() {
|
||||||
|
|
||||||
// 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"
|
||||||
// pinIndex 6 is door_condition - if open in maintenance mode - status = OK
|
// pinIndex 6 is door_condition - if it is opened in maintenance mode - status = OK
|
||||||
|
|
||||||
//set RVO state
|
//set RVO state
|
||||||
|
|
||||||
let status = "OK";
|
let status = "OK";
|
||||||
|
|
||||||
if(deviceStatuses["em"] == "NOK")
|
if(deviceStatus["em"] == "NOK")
|
||||||
{
|
{
|
||||||
let writeToFile = errorHandler.processMessage("checkFinalRVOStatus: EM status is NOK");
|
let writeToFile = errorHandler.processMessage("checkFinalRVOStatus: EM status is NOK");
|
||||||
if(writeToFile) errLogger.error("checkFinalRVOStatus: EM status is NOK");
|
if(writeToFile) errLogger.error("checkFinalRVOStatus: EM status is NOK");
|
||||||
|
|
@ -1048,7 +1092,7 @@ exports.install = function(instance) {
|
||||||
status = "NOK";
|
status = "NOK";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deviceStatuses["twilight_sensor"] == "NOK")
|
if(deviceStatus["twilight_sensor"] == "NOK")
|
||||||
{
|
{
|
||||||
let writeToFile = errorHandler.processMessage("checkFinalRVOStatus: twilight_sensor is NOK");
|
let writeToFile = errorHandler.processMessage("checkFinalRVOStatus: twilight_sensor is NOK");
|
||||||
if(writeToFile) errLogger.error("checkFinalRVOStatus: twilight sensor is NOK");
|
if(writeToFile) errLogger.error("checkFinalRVOStatus: twilight sensor is NOK");
|
||||||
|
|
@ -1057,7 +1101,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//ak teplomer NOK, rvo nok
|
//ak teplomer NOK, rvo nok
|
||||||
if(deviceStatuses["temperature"] == "NOK")
|
if(deviceStatus["temperature"] == "NOK")
|
||||||
{
|
{
|
||||||
|
|
||||||
let writeToFile = errorHandler.processMessage("checkFinalRVOStatus: temperature status is NOK");
|
let writeToFile = errorHandler.processMessage("checkFinalRVOStatus: temperature status is NOK");
|
||||||
|
|
@ -1105,9 +1149,9 @@ exports.install = function(instance) {
|
||||||
errorHandler.sendMessageToService("Master node is not responding");
|
errorHandler.sendMessageToService("Master node is not responding");
|
||||||
status = "NOK";
|
status = "NOK";
|
||||||
|
|
||||||
deviceStatuses["master_node"] = "NOK";
|
deviceStatus["master_node"] = "NOK";
|
||||||
}
|
}
|
||||||
else deviceStatuses["master_node"] = "OK";
|
else deviceStatus["master_node"] = "OK";
|
||||||
|
|
||||||
//console.log("checkFinalRVOStatus", status);
|
//console.log("checkFinalRVOStatus", status);
|
||||||
if(FLOW.OMS_no_voltage.size > 0)
|
if(FLOW.OMS_no_voltage.size > 0)
|
||||||
|
|
@ -1117,14 +1161,13 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
status = "NOK";
|
status = "NOK";
|
||||||
|
|
||||||
deviceStatuses["no_voltage"] = "NOK";
|
deviceStatus["no_voltage"] = "NOK";
|
||||||
}
|
}
|
||||||
else deviceStatuses["no_voltage"] = "OK";
|
else deviceStatus["no_voltage"] = "OK";
|
||||||
|
|
||||||
if(status == "NOK")
|
if(status == "NOK")
|
||||||
{
|
{
|
||||||
sendTelemetry({status: "NOK"}, FLOW.OMS_rvo_tbname);
|
sendTelemetry({status: "NOK"}, FLOW.OMS_rvo_tbname);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1155,13 +1198,13 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let obj = pinsData[pinIndex];
|
let obj = pinsData[pinIndex];
|
||||||
|
|
||||||
if(obj == undefined)
|
if(obj == undefined)
|
||||||
{
|
{
|
||||||
previousValues[pinIndex] = newPinValue;
|
previousValues[pinIndex] = newPinValue;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//tbname is added to pinsData in initialSettings function
|
||||||
let type = obj.type;
|
let type = obj.type;
|
||||||
let line = obj.line;
|
let line = obj.line;
|
||||||
let tbname = obj.tbname;
|
let tbname = obj.tbname;
|
||||||
|
|
@ -1180,13 +1223,13 @@ exports.install = function(instance) {
|
||||||
sendNotification("switchLogic", edgeName, "main_switch_has_been_turned_off", {}, "", SEND_TO.tb, instance , "state_of_main_switch");
|
sendNotification("switchLogic", edgeName, "main_switch_has_been_turned_off", {}, "", SEND_TO.tb, instance , "state_of_main_switch");
|
||||||
values["status"] = "NOK";
|
values["status"] = "NOK";
|
||||||
|
|
||||||
deviceStatuses["state_of_main_switch"] = "Off";
|
deviceStatus["state_of_main_switch"] = "Off";
|
||||||
}
|
}
|
||||||
else if (newPinValue === 1 && newPinValue !== previousValues[pinIndex])
|
else if (newPinValue === 1 && newPinValue !== previousValues[pinIndex])
|
||||||
{
|
{
|
||||||
sendNotification("switchLogic", edgeName, "main_switch_has_been_turned_on", {}, "", SEND_TO.tb, instance , "state_of_main_switch");
|
sendNotification("switchLogic", edgeName, "main_switch_has_been_turned_on", {}, "", SEND_TO.tb, instance , "state_of_main_switch");
|
||||||
|
|
||||||
deviceStatuses["state_of_main_switch"] = "On";
|
deviceStatus["state_of_main_switch"] = "On";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1223,7 +1266,7 @@ exports.install = function(instance) {
|
||||||
if (pin2 == 0 && pin3 == 0) value = "Off";
|
if (pin2 == 0 && pin3 == 0) value = "Off";
|
||||||
if (pin2 == 0 && pin3 == 1) value = "Automatic";
|
if (pin2 == 0 && pin3 == 1) value = "Automatic";
|
||||||
|
|
||||||
deviceStatuses["rotary_switch_state"] = value;
|
deviceStatus["rotary_switch_state"] = value;
|
||||||
|
|
||||||
//automatic - profilu pre nody sa vykonavaju
|
//automatic - profilu pre nody sa vykonavaju
|
||||||
//ak je spracovany, a automatic - tak ho zapnem
|
//ak je spracovany, a automatic - tak ho zapnem
|
||||||
|
|
@ -1242,14 +1285,14 @@ exports.install = function(instance) {
|
||||||
sendNotification("switchLogic", edgeName, "power_supply_has_disconnected_input", {}, "", SEND_TO.tb, instance, "power_supply");
|
sendNotification("switchLogic", edgeName, "power_supply_has_disconnected_input", {}, "", SEND_TO.tb, instance, "power_supply");
|
||||||
values["status"] = "NOK";
|
values["status"] = "NOK";
|
||||||
|
|
||||||
deviceStatuses["power_supply"] = "NOK";
|
deviceStatus["power_supply"] = "NOK";
|
||||||
}
|
}
|
||||||
else if (newPinValue === 1 && newPinValue !== previousValues[pinIndex])
|
else if (newPinValue === 1 && newPinValue !== previousValues[pinIndex])
|
||||||
{
|
{
|
||||||
//sendNotification("switchLogic", edgeName, ERRWEIGHT.NOTICE, "Power supply is is OK", "", SEND_TO.tb, instance);
|
//sendNotification("switchLogic", edgeName, ERRWEIGHT.NOTICE, "Power supply is is OK", "", SEND_TO.tb, instance);
|
||||||
sendNotification("switchLogic", edgeName, "power_supply_works_correctly", {}, "", SEND_TO.tb, instance, "power_supply");
|
sendNotification("switchLogic", edgeName, "power_supply_works_correctly", {}, "", SEND_TO.tb, instance, "power_supply");
|
||||||
|
|
||||||
deviceStatuses["power_supply"] = "OK";
|
deviceStatus["power_supply"] = "OK";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Batéria - pin 5
|
//Batéria - pin 5
|
||||||
|
|
@ -1261,14 +1304,14 @@ exports.install = function(instance) {
|
||||||
sendNotification("switchLogic", edgeName, "battery_level_is_low", {}, "", SEND_TO.tb, instance, "battery_level");
|
sendNotification("switchLogic", edgeName, "battery_level_is_low", {}, "", SEND_TO.tb, instance, "battery_level");
|
||||||
values["status"] = "NOK";
|
values["status"] = "NOK";
|
||||||
|
|
||||||
deviceStatuses["battery"] = "NOK";
|
deviceStatus["battery"] = "NOK";
|
||||||
}
|
}
|
||||||
else if (newPinValue === 0 && newPinValue !== previousValues[pinIndex])
|
else if (newPinValue === 0 && newPinValue !== previousValues[pinIndex])
|
||||||
{
|
{
|
||||||
//sendNotification("switchLogic", edgeName, ERRWEIGHT.NOTICE, "Battery is OK", "", SEND_TO.tb, instance);
|
//sendNotification("switchLogic", edgeName, ERRWEIGHT.NOTICE, "Battery is OK", "", SEND_TO.tb, instance);
|
||||||
sendNotification("switchLogic", edgeName, "battery_level_is_ok", {}, "", SEND_TO.tb, instance, "battery_level");
|
sendNotification("switchLogic", edgeName, "battery_level_is_ok", {}, "", SEND_TO.tb, instance, "battery_level");
|
||||||
|
|
||||||
deviceStatuses["battery"] = "OK";
|
deviceStatus["battery"] = "OK";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Dverový kontakt - pin 6
|
//Dverový kontakt - pin 6
|
||||||
|
|
@ -1310,13 +1353,13 @@ exports.install = function(instance) {
|
||||||
sendNotification("switchLogic", edgeName, "door_has_been_closed", {}, "", SEND_TO.tb, instance, "rvo_door");
|
sendNotification("switchLogic", edgeName, "door_has_been_closed", {}, "", SEND_TO.tb, instance, "rvo_door");
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceStatuses["door_condition"] = value;
|
deviceStatus["door_condition"] = value;
|
||||||
|
|
||||||
}
|
}
|
||||||
//lux sensor
|
//lux sensor
|
||||||
else if(type == "twilight_sensor")
|
else if(type == "twilight_sensor")
|
||||||
{
|
{
|
||||||
//! TODO - to show nok status, if lux value is not changing more then 10 times. From unipi for example comes value from 0-1000.
|
//! TODO - to show nok status, if lux value is not changing more then 10 times.
|
||||||
//Daylight is far more than 1000. So most of the day, when it is sunshine comes just value 1000. But lux sensor is not NOK.
|
//Daylight is far more than 1000. So most of the day, when it is sunshine comes just value 1000. But lux sensor is not NOK.
|
||||||
//This is not the case in LM. If value from LM is the same 10x, there is 99% possibility, that sensor is NOK.
|
//This is not the case in LM. If value from LM is the same 10x, there is 99% possibility, that sensor is NOK.
|
||||||
values["status"] = "OK";
|
values["status"] = "OK";
|
||||||
|
|
@ -1382,65 +1425,45 @@ exports.install = function(instance) {
|
||||||
{
|
{
|
||||||
//sendNotification("switchLogic", edgeName, ERRWEIGHT.INFO, `State of contactor ${line} is now ${value}`, "", SEND_TO.tb, instance );
|
//sendNotification("switchLogic", edgeName, ERRWEIGHT.INFO, `State of contactor ${line} is now ${value}`, "", SEND_TO.tb, instance );
|
||||||
|
|
||||||
if(!(deviceStatuses["state_of_contactor"][line] == value))
|
if(!(deviceStatus["state_of_contactor"][line] == value))
|
||||||
{
|
{
|
||||||
sendNotification("switchLogic", edgeName, "state_of_contactor_for_line", {line: line, value: value}, "", SEND_TO.tb, instance );
|
sendNotification("switchLogic", edgeName, "state_of_contactor_for_line", {line: line, value: value}, "", SEND_TO.tb, instance );
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
deviceStatus["state_of_contactor"][line] = value;
|
||||||
deviceStatuses["state_of_contactor"][line] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
//true, false
|
//true, false
|
||||||
if(value === "On") value = true;
|
if(value === "On") value = true;
|
||||||
else if(value === "Off") value = false;
|
else if(value === "Off") value = false;
|
||||||
|
|
||||||
//modify table relays
|
//modify table relays
|
||||||
dbRelays.modify({ contactor: newPinValue }).where("line", line).make(function(builder) {
|
dbRelays.modify({ contactor: newPinValue }).where("line", line).make(function(builder) {
|
||||||
|
|
||||||
builder.callback(function(err, response) {
|
builder.callback(function(err, response) {
|
||||||
|
if(!err)
|
||||||
/*
|
|
||||||
if(useTurnOffCounter)
|
|
||||||
{
|
{
|
||||||
turnOffCounter--;
|
let time = 0;
|
||||||
|
if(value) time = 1000 * 10;//10 sekund
|
||||||
|
|
||||||
if(turnOffCounter <= 0)
|
let dataChanged = false;
|
||||||
{
|
if(relaysData[line].contactor != value) dataChanged = true;
|
||||||
useTurnOffCounter = false;
|
relaysData[line].contactor = value;
|
||||||
}
|
|
||||||
}
|
//ak bola predchadzajuci stav off a novy stav je on, budu sa nastavovat nespracovane node profiles
|
||||||
*/
|
//a budu sa odosielat commandy, tie vsak mozu zlyhat, a preto potrebujeme ich spusti trochu neskor
|
||||||
|
|
||||||
if(err == undefined)
|
setTimeout(function(){
|
||||||
{
|
instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "reload_relays", line: line, time: time, value: value, dataChanged: dataChanged});
|
||||||
|
}, time);
|
||||||
|
|
||||||
let time = 0;
|
reportLineStatus(line);
|
||||||
if(value) time = 1000 * 10;//10 sekund
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errLogger.error("modify table relays failed", err);
|
||||||
|
}
|
||||||
|
|
||||||
let dataChanged = false;
|
|
||||||
if(relaysData[line].contactor != value) dataChanged = true;
|
|
||||||
relaysData[line].contactor = value;
|
|
||||||
|
|
||||||
//ak bola predchadzajuci stav off a novy stav je on, budu sa nastavovat nespracovane node profiles
|
|
||||||
//a budu sa odosielat commandy, tie vsak mozu zlyhat, a preto potrebujeme ich spusti trochu neskor
|
|
||||||
|
|
||||||
setTimeout(function(){
|
|
||||||
instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "reload_relays", line: line, time: time, value: value, dataChanged: dataChanged});
|
|
||||||
}, time);
|
|
||||||
|
|
||||||
reportLineStatus(line);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
errLogger.error("modify table relays failed", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type === "state_of_breaker")
|
if(type === "state_of_breaker")
|
||||||
|
|
@ -1467,7 +1490,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "state_of_breaker", value: value, line: lineOnSameBraker[i]});
|
instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "state_of_breaker", value: value, line: lineOnSameBraker[i]});
|
||||||
|
|
||||||
deviceStatuses["state_of_breaker"][lineOnSameBraker[i]] = value;
|
deviceStatus["state_of_breaker"][lineOnSameBraker[i]] = value;
|
||||||
reportLineStatus(lineOnSameBraker[i]);
|
reportLineStatus(lineOnSameBraker[i]);
|
||||||
|
|
||||||
values[type] = value;
|
values[type] = value;
|
||||||
|
|
@ -1486,7 +1509,7 @@ exports.install = function(instance) {
|
||||||
{
|
{
|
||||||
instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "state_of_breaker", value: value, line: line + 3});
|
instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "state_of_breaker", value: value, line: line + 3});
|
||||||
|
|
||||||
deviceStatuses["state_of_breaker"][line + 3] = value;
|
deviceStatus["state_of_breaker"][line + 3] = value;
|
||||||
reportLineStatus(line + 3);
|
reportLineStatus(line + 3);
|
||||||
|
|
||||||
values[type] = value;
|
values[type] = value;
|
||||||
|
|
@ -1495,14 +1518,13 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
delete values[type];
|
delete values[type];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value == "Off") values["status"] = "NOK";
|
if(value == "Off") values["status"] = "NOK";
|
||||||
|
|
||||||
deviceStatuses["state_of_breaker"][line] = value;
|
deviceStatus["state_of_breaker"][line] = value;
|
||||||
|
|
||||||
reportLineStatus(line);
|
reportLineStatus(line);
|
||||||
}
|
}
|
||||||
|
|
@ -1569,8 +1591,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function sendTelemetry(values, tbname)
|
function sendTelemetry(values, tbname) {
|
||||||
{
|
|
||||||
let dataToTb = {
|
let dataToTb = {
|
||||||
[tbname]: [
|
[tbname]: [
|
||||||
{
|
{
|
||||||
|
|
@ -1578,12 +1599,33 @@ exports.install = function(instance) {
|
||||||
"values": values
|
"values": values
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
};
|
||||||
|
|
||||||
instance.send(SEND_TO.tb, dataToTb);
|
// instance.send(SEND_TO.tb, dataToTb);
|
||||||
|
tbHandler.sendToTb(dataToTb, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
function writeThermometerStatusToDb(status) {
|
||||||
|
dbStatus.modify({ thermometer: status }).make(function(builder) {
|
||||||
|
builder.callback(function(err, response) {
|
||||||
|
if(!err)
|
||||||
|
{
|
||||||
|
deviceStatus["temperature"] = status;
|
||||||
|
console.log(`Wrote to db status: thermometer ${status}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function isObject (item) {
|
||||||
|
return (typeof item === "object" && !Array.isArray(item) && item !== null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} //end of instance
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ class DataToTbHandler
|
||||||
constructor(index) {
|
constructor(index) {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
|
|
||||||
|
// 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.previousValues = {};
|
||||||
this.debug = false;
|
this.debug = false;
|
||||||
this.messageCounter = 0;
|
this.messageCounter = 0;
|
||||||
|
|
@ -99,14 +102,9 @@ class DataToTbHandler
|
||||||
|
|
||||||
getDiffTimestamp(key)
|
getDiffTimestamp(key)
|
||||||
{
|
{
|
||||||
let seconds = 30*60;//30 minutes
|
|
||||||
|
|
||||||
//TODO set different value for given key!!!
|
//TODO set different value for given key!!!
|
||||||
//if(key == "status") seconds = 2*60*60;//2h
|
//if(key == "status") this.timeToHoldTbValue = 2*60*60;//2h
|
||||||
|
return this.timeToHoldTbValue * 1000;
|
||||||
let timestampDiffToRemoveKey = seconds*1000;
|
|
||||||
|
|
||||||
return timestampDiffToRemoveKey;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareValuesForTb(tbname, timestamp, values)
|
prepareValuesForTb(tbname, timestamp, values)
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,6 @@ exports.install = function(instance) {
|
||||||
let l = singleValue.split("_");
|
let l = singleValue.split("_");
|
||||||
let phase = parseInt(l[1]);
|
let phase = parseInt(l[1]);
|
||||||
|
|
||||||
if(FLOW.OMS_no_voltage == undefined) FLOW.OMS_no_voltage = new Set();
|
|
||||||
// console.log(values[singleValue], tbName);
|
// console.log(values[singleValue], tbName);
|
||||||
|
|
||||||
if(values[singleValue] == 0)
|
if(values[singleValue] == 0)
|
||||||
|
|
|
||||||
|
|
@ -216,5 +216,9 @@ exports.install = function(instance) {
|
||||||
}, 15000);
|
}, 15000);
|
||||||
|
|
||||||
startRead = setInterval(start, timeoutMin * 1000 * 60);
|
startRead = setInterval(start, timeoutMin * 1000 * 60);
|
||||||
|
|
||||||
|
//testing
|
||||||
|
//setInterval(() => {instance.send(instanceSendTo.dido_controller, {status: "NOK-thermometer"})}, 180000);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
@ -73,6 +73,11 @@ let errLogger;
|
||||||
let logger;
|
let logger;
|
||||||
let monitor;
|
let monitor;
|
||||||
|
|
||||||
|
//TODO brokerready and sendBrokerError seems to be the same. Moreover, we use FLOW_OMS_brokerready variable!!
|
||||||
|
//
|
||||||
|
// if there is an error in broker connection, flow logs to monitor.txt. Not to log messages every second, we use sendBrokerError variable
|
||||||
|
let sendBrokerError = true;
|
||||||
|
|
||||||
if(useLog4js)
|
if(useLog4js)
|
||||||
{
|
{
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
@ -217,6 +222,8 @@ exports.install = function(instance) {
|
||||||
instance.status("Connected", "green");
|
instance.status("Connected", "green");
|
||||||
monitor.info("MQTT broker connected");
|
monitor.info("MQTT broker connected");
|
||||||
|
|
||||||
|
sendBrokerError = true;
|
||||||
|
|
||||||
brokerready = true;
|
brokerready = true;
|
||||||
FLOW.OMS_brokerready = brokerready;
|
FLOW.OMS_brokerready = brokerready;
|
||||||
wsmqtt_status = 'connected';
|
wsmqtt_status = 'connected';
|
||||||
|
|
@ -266,8 +273,10 @@ exports.install = function(instance) {
|
||||||
broker.on('error', function(err) {
|
broker.on('error', function(err) {
|
||||||
instance.status("Err: "+ err.code, "red");
|
instance.status("Err: "+ err.code, "red");
|
||||||
instance.send(instanceSendTo.debug, {"message":"Broker ERROR signal received !", "error":err, "opt":opts });
|
instance.send(instanceSendTo.debug, {"message":"Broker ERROR signal received !", "error":err, "opt":opts });
|
||||||
monitor.info('MQTT broker error', err);
|
if(sendBrokerError) {
|
||||||
|
monitor.info('MQTT broker error', err);
|
||||||
|
sendBrokerError = false;
|
||||||
|
}
|
||||||
brokerready = false;
|
brokerready = false;
|
||||||
FLOW.OMS_brokerready = brokerready;
|
FLOW.OMS_brokerready = brokerready;
|
||||||
wsmqtt_status = 'disconnected';
|
wsmqtt_status = 'disconnected';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue