Rvo status handled just in dido_controller
This commit is contained in:
parent
1b4b9ca973
commit
ca39e1266c
6 changed files with 166 additions and 318 deletions
|
|
@ -142,7 +142,6 @@ let nodesData = {};//key is node, value data from db
|
||||||
let cmdCounter = {};//key is node, value is counter
|
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;
|
|
||||||
//END OF VARIABLE SETTINGS
|
//END OF VARIABLE SETTINGS
|
||||||
//--------------------------------
|
//--------------------------------
|
||||||
|
|
||||||
|
|
@ -319,8 +318,6 @@ function processNodeProfile(node)
|
||||||
cmdCounter[node] = 1;
|
cmdCounter[node] = 1;
|
||||||
|
|
||||||
tasks.push(params);
|
tasks.push(params);
|
||||||
|
|
||||||
//sendNotification("CMD Manager: process cmd", relaysData[0].tbname, ERRWEIGHT.NOTICE, "Master node is working again", "", SEND_TO.tb, instance );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1794,9 +1791,7 @@ exports.install = function(instance) {
|
||||||
message = "off";
|
message = "off";
|
||||||
}
|
}
|
||||||
|
|
||||||
//sendNotification("CMD Manager: process cmd", relaysData[0].tbname, ERRWEIGHT.INFO, "aplikovaný bod profilu línie " + params.line + " - stav: " + message, "", SEND_TO.tb, instance, null );
|
|
||||||
sendNotification("CMD Manager: process cmd", FLOW.OMS_edgeName, "switching_profile_point_applied_to_line", {line: params.line, value: message}, "", SEND_TO.tb, instance );
|
sendNotification("CMD Manager: process cmd", FLOW.OMS_edgeName, "switching_profile_point_applied_to_line", {line: params.line, value: message}, "", SEND_TO.tb, instance );
|
||||||
|
|
||||||
interval = setInterval(runTasks, SHORT_INTERVAL);
|
interval = setInterval(runTasks, SHORT_INTERVAL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1936,7 +1931,6 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
//TODO astrohodiny
|
//TODO astrohodiny
|
||||||
let dusk = "Time of dusk: " + sunCalcResult["dusk"];
|
let dusk = "Time of dusk: " + sunCalcResult["dusk"];
|
||||||
//sendNotification("CMD Manager: calculated Time of dusk", relaysData[0].tbname, ERRWEIGHT.INFO, dusk, "", SEND_TO.tb, instance, null );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1956,7 +1950,6 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
//TODO astrohodiny
|
//TODO astrohodiny
|
||||||
let dawn = "Time of dawn: " + sunCalcResult["dawn"];
|
let dawn = "Time of dawn: " + sunCalcResult["dawn"];
|
||||||
//sendNotification("CMD Manager: calculated Time of dusk", relaysData[0].tbname, ERRWEIGHT.INFO, dawn, "", SEND_TO.tb, instance, null );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1968,7 +1961,7 @@ exports.install = function(instance) {
|
||||||
startTime = new Date();
|
startTime = new Date();
|
||||||
|
|
||||||
let saveToTb = true;
|
let saveToTb = true;
|
||||||
if(!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);
|
||||||
|
|
@ -1993,13 +1986,6 @@ exports.install = function(instance) {
|
||||||
let message_type = result.type;
|
let message_type = result.type;
|
||||||
let error = result.error;
|
let error = result.error;
|
||||||
|
|
||||||
//testing purpose node 638, tbname rDbQ84xzwgdqEoPm3kbJQWk9anOZY1RXyBv2LVM6
|
|
||||||
if(tbname == testTbName) {
|
|
||||||
message = "NOK";
|
|
||||||
message_type = "ERROR";
|
|
||||||
error = "type is: ERROR";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(params.debug != "generated cmd")
|
if(params.debug != "generated cmd")
|
||||||
{
|
{
|
||||||
//debug("writeData: done " + message_type + " duration: " + timeDiff + " message_type: " + params.debug, params);
|
//debug("writeData: done " + message_type + " duration: " + timeDiff + " message_type: " + params.debug, params);
|
||||||
|
|
@ -2057,24 +2043,16 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//master node
|
//master node
|
||||||
if(nodeAddress == 0 && register == 4)
|
|
||||||
{
|
|
||||||
values.status = "OK";
|
|
||||||
values["edge_fw_version"] = FLOW.OMS_edge_fw_version;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(nodeAddress == 0)
|
if(nodeAddress == 0)
|
||||||
{
|
{
|
||||||
//sendNotification("CMD Manager: process cmd", relaysData[0].tbname, ERRWEIGHT.NOTICE, "Master node is working again", "", SEND_TO.tb, instance, "rvo_status" );
|
|
||||||
//sendNotification("CMD Manager: process cmd", relaysData[0].tbname, "master_node_is_responding_again", {}, "", SEND_TO.tb, instance, "rvo_status" );
|
|
||||||
sendNotification("CMD Manager: process cmd", FLOW.OMS_edgeName, "master_node_is_responding_again", {}, "", SEND_TO.tb, instance, "rvo_status" );
|
sendNotification("CMD Manager: process cmd", FLOW.OMS_edgeName, "master_node_is_responding_again", {}, "", SEND_TO.tb, instance, "rvo_status" );
|
||||||
FLOW.OMS_masterNodeIsResponding = true;
|
FLOW.OMS_masterNodeIsResponding = true;
|
||||||
|
if(register == 4) values["edge_fw_version"] = FLOW.OMS_edge_fw_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
//odoslanie príkazu z terminálu - dáta
|
//odoslanie príkazu z terminálu - dáta
|
||||||
if(type == "cmd-terminal")
|
if(type == "cmd-terminal")
|
||||||
{
|
{
|
||||||
//sendNotification("CMD Manager: process cmd", relaysData[0].tbname, ERRWEIGHT.DEBUG, "odoslanie príkazu z terminálu", params, SEND_TO.tb, instance, null );
|
|
||||||
sendNotification("CMD Manager: process cmd", FLOW.OMS_edgeName, "command_was_sent_from_terminal_interface", {}, params, SEND_TO.tb, instance );
|
sendNotification("CMD Manager: process cmd", FLOW.OMS_edgeName, "command_was_sent_from_terminal_interface", {}, params, SEND_TO.tb, instance );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2169,23 +2147,23 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
let values = {};
|
let values = {};
|
||||||
|
|
||||||
console.log(message);
|
// console.log(message);
|
||||||
let updateStatus = updateNodeStatus(node, false);
|
let updateStatus = updateNodeStatus(node, false);
|
||||||
|
|
||||||
|
//master node
|
||||||
if(node == 0)
|
if(node == 0)
|
||||||
{
|
{
|
||||||
//sendNotification("CMD Manager: process cmd", relaysData[0].tbname, ERRWEIGHT.ALERT, "Master node not responding", "", SEND_TO.tb, instance, "rvo_status");
|
|
||||||
sendNotification("CMD Manager: process cmd", FLOW.OMS_edgeName, "master_node_is_not_responding", {}, "", SEND_TO.tb, instance, "rvo_status");
|
sendNotification("CMD Manager: process cmd", FLOW.OMS_edgeName, "master_node_is_not_responding", {}, "", SEND_TO.tb, instance, "rvo_status");
|
||||||
logger.debug("master_node_is_not_responding", params);
|
logger.debug("master_node_is_not_responding", params);
|
||||||
FLOW.OMS_masterNodeIsResponding = false;
|
FLOW.OMS_masterNodeIsResponding = false;
|
||||||
|
|
||||||
|
if(register == 4) values["master_node_version"] = "NOK";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type == "set_node_profile")
|
if(type == "set_node_profile")
|
||||||
{
|
{
|
||||||
delete cmdCounter[node];
|
delete cmdCounter[node];
|
||||||
logger.debug( "profil nebol úspešne odoslaný na node č. ", params, resp);
|
logger.debug( "profil nebol úspešne odoslaný na node č. ", params);
|
||||||
|
|
||||||
//sendNotification("CMD Manager: process cmd", tbname, ERRWEIGHT.ALERT, "odosielanie profilu na node č. " + node + " zlyhalo", "", SEND_TO.tb, instance, null );
|
|
||||||
sendNotification("CMD Manager: process cmd", tbName, "configuration_of_dimming_profile_to_node_failed", {node: node}, "", SEND_TO.tb, instance );
|
sendNotification("CMD Manager: process cmd", tbName, "configuration_of_dimming_profile_to_node_failed", {node: node}, "", SEND_TO.tb, instance );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2199,14 +2177,7 @@ exports.install = function(instance) {
|
||||||
values.status = "NOK";
|
values.status = "NOK";
|
||||||
}
|
}
|
||||||
|
|
||||||
//master node
|
// console.log("------",node, register, type, itIsNodeCommand, updateStatus, saveToTb, values);
|
||||||
if(node == 0 && register == 4)
|
|
||||||
{
|
|
||||||
values.status = "NOK";
|
|
||||||
values["master_node_version"] = "NOK";
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("------",node, register, type, itIsNodeCommand, updateStatus, saveToTb, values);
|
|
||||||
if(saveToTb && Object.keys(values).length > 0 && tbName)
|
if(saveToTb && Object.keys(values).length > 0 && tbName)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -2391,12 +2362,6 @@ exports.install = function(instance) {
|
||||||
rsPort.close();
|
rsPort.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.on("1", function(flowdata){
|
|
||||||
if(flowdata.data.hasOwnProperty("testTbName"))
|
|
||||||
{
|
|
||||||
testTbName = flowdata.data.testTbName;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
instance.on("data", async function(flowdata) {
|
instance.on("data", async function(flowdata) {
|
||||||
|
|
||||||
|
|
@ -2535,7 +2500,6 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
tasks.push(params);
|
tasks.push(params);
|
||||||
|
|
||||||
|
|
||||||
//process profiles
|
//process profiles
|
||||||
turnOnOffLinesAccordingToLuxSensor(lux_sensor);
|
turnOnOffLinesAccordingToLuxSensor(lux_sensor);
|
||||||
}
|
}
|
||||||
|
|
@ -2552,14 +2516,7 @@ exports.install = function(instance) {
|
||||||
state_of_breaker[line] = value;
|
state_of_breaker[line] = value;
|
||||||
|
|
||||||
let status = "OK";
|
let status = "OK";
|
||||||
let weight = ERRWEIGHT.NOTICE;
|
if(value == "Off") status = "NOK";
|
||||||
let message = `zapnutý istič línie č. ${line}`;
|
|
||||||
if(value == "Off")
|
|
||||||
{
|
|
||||||
weight = ERRWEIGHT.ERROR;
|
|
||||||
message = `vypnutý istič línie č. ${line}`;
|
|
||||||
status = "NOK";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(dataChanged) {
|
if(dataChanged) {
|
||||||
|
|
||||||
|
|
@ -2588,11 +2545,7 @@ exports.install = function(instance) {
|
||||||
tbHandler.sendToTb(dataToTb, instance);
|
tbHandler.sendToTb(dataToTb, instance);
|
||||||
|
|
||||||
//current value
|
//current value
|
||||||
if(value == "Off")
|
if(value == "Off") reportOfflineNodeStatus(line); //vyreportovat vsetky svietidla na linii
|
||||||
{
|
|
||||||
//vyreportovat vsetky svietdla na linii
|
|
||||||
reportOfflineNodeStatus(line);
|
|
||||||
}
|
|
||||||
else reportOnlineNodeStatus(line);
|
else reportOnlineNodeStatus(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2788,7 +2741,6 @@ exports.install = function(instance) {
|
||||||
if(profile === "") logger.debug("worksys - update node profile done - profile is empty");
|
if(profile === "") logger.debug("worksys - update node profile done - profile is empty");
|
||||||
|
|
||||||
//profil úspešne prijatý pre node č. xx
|
//profil úspešne prijatý pre node č. xx
|
||||||
//sendNotification("CMD manager", tbname, ERRWEIGHT.INFO, `profil úspešne poslaný z platformy na RVO pre node č. ${node}`, profile, SEND_TO.tb, instance, null );
|
|
||||||
sendNotification("CMD manager", tbname, "dimming_profile_was_processed_for_node", {node: node}, profile, SEND_TO.tb, instance );
|
sendNotification("CMD manager", tbname, "dimming_profile_was_processed_for_node", {node: node}, profile, SEND_TO.tb, instance );
|
||||||
|
|
||||||
nodesData[node].processed = false;
|
nodesData[node].processed = false;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ exports.title = 'DIDO_Controller';
|
||||||
exports.version = '2.0.0';
|
exports.version = '2.0.0';
|
||||||
exports.group = 'Worksys';
|
exports.group = 'Worksys';
|
||||||
exports.color = '#2134B0';
|
exports.color = '#2134B0';
|
||||||
exports.input = 3;
|
exports.input = 2;
|
||||||
exports.output = ["red", "white", "yellow"];
|
exports.output = ["red", "white", "yellow"];
|
||||||
exports.click = false;
|
exports.click = false;
|
||||||
exports.icon = 'bolt';
|
exports.icon = 'bolt';
|
||||||
|
|
@ -59,7 +59,8 @@ state_of_contactor - podľa indexu stykača sa reportuje jeho stav, teda
|
||||||
|
|
||||||
//globals
|
//globals
|
||||||
//FIRMWARE version
|
//FIRMWARE version
|
||||||
FLOW.OMS_edge_fw_version = "2024-07-08";//rok-mesiac-den
|
//TODO remove FLOW.OMS_edgeName variable, as we have FLOW.OMS_rvo_tbname
|
||||||
|
FLOW.OMS_edge_fw_version = "2024-09-23";//rok-mesiac-den
|
||||||
FLOW.OMS_edgeName = "";
|
FLOW.OMS_edgeName = "";
|
||||||
FLOW.OMS_maintenance_mode = false;
|
FLOW.OMS_maintenance_mode = false;
|
||||||
|
|
||||||
|
|
@ -83,6 +84,9 @@ const SEND_TO = {
|
||||||
cmd_manager: 2
|
cmd_manager: 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TIME_AFTER_TEMPERATURE_NOK_STATUS = 3600; //seconds
|
||||||
|
const DIFFERENCE_TO_SEND_TEMPERATURE = 0.31;
|
||||||
|
|
||||||
var log4js = require("log4js");
|
var log4js = require("log4js");
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
|
|
@ -178,21 +182,20 @@ exports.install = function(instance) {
|
||||||
let statusData = null;
|
let statusData = null;
|
||||||
|
|
||||||
//status for calculating Statecodes
|
//status for calculating Statecodes
|
||||||
let deviceStatus = {};//key is device name: temperature,....
|
let deviceStatus = { //key is device name: temperature,....
|
||||||
deviceStatus["state_of_main_switch"] = "Off";//Hlavný istič
|
"state_of_main_switch": "Off", //Hlavný istič
|
||||||
deviceStatus["rotary_switch_state"] = "Off";//Prevádzkový mód
|
"rotary_switch_state": "Off", //Prevádzkový mód
|
||||||
deviceStatus["door_condition"] = "closed";//Dverový kontakt
|
"door_condition": "closed", //Dverový kontakt
|
||||||
deviceStatus["em"] = "OK";//elektromer rvo
|
"em": "OK", //elektromer rvo
|
||||||
deviceStatus["temperature"] = "OK";//templomer
|
"temperature": "OK", //templomer
|
||||||
deviceStatus["battery"] = "OK";//Batéria
|
"battery": "OK", //Batéria
|
||||||
deviceStatus["power_supply"] = "OK";//Zdroj
|
"power_supply": "OK", //Zdroj
|
||||||
deviceStatus["master_node"] = "OK";//MN - FLOW.OMS_masterNodeIsResponding
|
"master_node": "OK", //MN - FLOW.OMS_masterNodeIsResponding
|
||||||
deviceStatus["no_voltage"] = "OK";//FLOW.OMS_no_voltage - výpadok napätia na fáze
|
"no_voltage": "OK", //FLOW.OMS_no_voltage - výpadok napätia na fáze
|
||||||
|
"state_of_breaker": {}, //"Off",//Istič
|
||||||
deviceStatus["state_of_breaker"] = {};//"Off";//Istič
|
"state_of_contactor": {}, //"Off",//Stykač
|
||||||
deviceStatus["state_of_contactor"] = {};//"Off";//Stykač
|
"twilight_sensor": "OK" //lux sensor
|
||||||
deviceStatus["twilight_sensor"] = "OK"; //lux sensor
|
};
|
||||||
|
|
||||||
|
|
||||||
const SerialPort = require('serialport');
|
const SerialPort = require('serialport');
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
|
|
@ -230,9 +233,9 @@ exports.install = function(instance) {
|
||||||
relaysData = makeMapFromDbResult(responseRelays, "line");
|
relaysData = makeMapFromDbResult(responseRelays, "line");
|
||||||
|
|
||||||
let responseStatus = await promisifyBuilder(dbStatus.find());
|
let responseStatus = await promisifyBuilder(dbStatus.find());
|
||||||
statusData = responseStatus[0]; // {thermometer: '{"status":"OK","temperature":0}', em: 'OK', twilight_sensor: 'OK'}
|
statusData = responseStatus[0]; // {thermometer: 'OK', em: 'OK', twilight_sensor: 'OK'}
|
||||||
deviceStatus["temperature"] = statusData.thermometer;
|
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")
|
||||||
|
|
@ -290,7 +293,6 @@ exports.install = function(instance) {
|
||||||
let values = {};
|
let values = {};
|
||||||
values["edge_fw_version"] = FLOW.OMS_edge_fw_version;
|
values["edge_fw_version"] = FLOW.OMS_edge_fw_version;
|
||||||
values["maintenance_mode"] = FLOW.OMS_maintenance_mode;
|
values["maintenance_mode"] = FLOW.OMS_maintenance_mode;
|
||||||
values["status"] = "OK";
|
|
||||||
|
|
||||||
edgeName = relaysData[0].tbname;
|
edgeName = relaysData[0].tbname;
|
||||||
FLOW.OMS_edgeName = edgeName;
|
FLOW.OMS_edgeName = edgeName;
|
||||||
|
|
@ -455,7 +457,7 @@ exports.install = function(instance) {
|
||||||
// dev: 'input',
|
// dev: 'input',
|
||||||
// mode: 'Simple'
|
// mode: 'Simple'
|
||||||
// },
|
// },
|
||||||
ws.onmessage = function(data) {
|
ws.onmessage = async function(data) {
|
||||||
|
|
||||||
data = JSON.parse(data.data);
|
data = JSON.parse(data.data);
|
||||||
|
|
||||||
|
|
@ -463,18 +465,22 @@ exports.install = function(instance) {
|
||||||
if(isObject(data))
|
if(isObject(data))
|
||||||
{
|
{
|
||||||
let value = data['value'];
|
let value = data['value'];
|
||||||
|
const values = {};
|
||||||
previousValues["temperature"]["lastTimeTemperatureReceived"] = data['time'];
|
previousValues["temperature"]["lastTimeTemperatureReceived"] = data['time'];
|
||||||
|
|
||||||
|
// we received data from thermometer, but thermometer status is NOK:
|
||||||
if(deviceStatus["temperature"] === "NOK")
|
if(deviceStatus["temperature"] === "NOK")
|
||||||
{
|
{
|
||||||
writeThermometerStatusToDb("OK");
|
await writeThermometerStatusToDb("OK");
|
||||||
|
sendRvoStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
// 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
|
||||||
if(Math.abs(previousValues["temperature"]["value"] - value) > 0.21 )
|
if(Math.abs(previousValues["temperature"]["value"] - value) > DIFFERENCE_TO_SEND_TEMPERATURE)
|
||||||
{
|
{
|
||||||
previousValues["temperature"]["value"] = value;
|
previousValues["temperature"]["value"] = value;
|
||||||
sendTelemetry({temperature: value}, FLOW.OMS_rvo_tbname);
|
values['temperature'] = value;
|
||||||
|
sendTelemetry(values, FLOW.OMS_rvo_tbname);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -802,7 +808,6 @@ exports.install = function(instance) {
|
||||||
ws.send(JSON.stringify(cmd));
|
ws.send(JSON.stringify(cmd));
|
||||||
switchLogic(pin, 0)
|
switchLogic(pin, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -851,18 +856,13 @@ exports.install = function(instance) {
|
||||||
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"))
|
||||||
{
|
{
|
||||||
deviceStatus["em"] = "OK";
|
deviceStatus["em"] = "OK";
|
||||||
}
|
FLOW.OMS_no_voltage.size > 0 ? deviceStatus["no_voltage"] = "NOK": deviceStatus["no_voltage"] = "OK";
|
||||||
else
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateStatus = checkFinalRVOStatus();
|
|
||||||
if(updateStatus) values.status = "OK";
|
|
||||||
|
|
||||||
sendTelemetry(values, FLOW.OMS_rvo_tbname);
|
sendTelemetry(values, FLOW.OMS_rvo_tbname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendRvoStatus();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -903,11 +903,12 @@ exports.install = function(instance) {
|
||||||
let bits = [];
|
let bits = [];
|
||||||
|
|
||||||
//Hlavný istič - state_of_main_switch
|
//Hlavný istič - state_of_main_switch
|
||||||
if(deviceStatus["state_of_main_switch"] == "On")
|
//TODO state_of main_switch is door contact in senica rvo - values should be "open" and "closed"
|
||||||
|
if(deviceStatus["state_of_main_switch"] == "closed")
|
||||||
{
|
{
|
||||||
bits.push(0);
|
bits.push(0);
|
||||||
}
|
}
|
||||||
else if(deviceStatus["state_of_main_switch"] == "Off")
|
else
|
||||||
{
|
{
|
||||||
bits.push(1);
|
bits.push(1);
|
||||||
}
|
}
|
||||||
|
|
@ -1037,7 +1038,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function sendDeviceStatus() {
|
async function sendRvoStatus() {
|
||||||
|
|
||||||
const table = {
|
const table = {
|
||||||
"OK": 1,
|
"OK": 1,
|
||||||
|
|
@ -1054,124 +1055,57 @@ exports.install = function(instance) {
|
||||||
"master_node_status": table[deviceStatus["master_node"]]
|
"master_node_status": table[deviceStatus["master_node"]]
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const phase of FLOW.OMS_no_voltage) {
|
for (const phase of FLOW.OMS_no_voltage) dataToTb[`phase_${phase}_status`] = 0;
|
||||||
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
|
//thermometer did not send data for more than a hour. Time in seconds
|
||||||
if(deviceStatus["temperature"] === "OK")
|
if(deviceStatus["temperature"] === "OK")
|
||||||
{
|
{
|
||||||
if(previousValues["temperature"]["lastTimeTemperatureReceived"] + 3600 < Date.now() / 1000)
|
if(previousValues["temperature"]["lastTimeTemperatureReceived"] + TIME_AFTER_TEMPERATURE_NOK_STATUS < Date.now() / 1000)
|
||||||
{
|
{
|
||||||
writeThermometerStatusToDb("NOK");
|
// to be able to calculate proper RVO status, we need to await writeThermometerStatusToDb function
|
||||||
|
await writeThermometerStatusToDb("NOK");
|
||||||
dataToTb["thermometer_status"] = 0;
|
dataToTb["thermometer_status"] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dataToTb["status"] = checkRvoStatus();
|
||||||
|
dataToTb["statecode"] = calculateStateCode();
|
||||||
|
|
||||||
sendTelemetry(dataToTb, FLOW.OMS_rvo_tbname);
|
sendTelemetry(dataToTb, FLOW.OMS_rvo_tbname);
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(sendDeviceStatus, 150000);
|
|
||||||
|
|
||||||
|
function checkRvoStatus() {
|
||||||
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 it is opened 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(deviceStatus["em"] == "NOK")
|
for (const [key, value] of Object.entries(deviceStatus)) {
|
||||||
{
|
if(["em", "twilight_sensor", "temperature"].includes(key) && value == "NOK") status = "NOK";
|
||||||
let writeToFile = errorHandler.processMessage("checkFinalRVOStatus: EM status is NOK");
|
|
||||||
if(writeToFile) errLogger.error("checkFinalRVOStatus: EM status is NOK");
|
|
||||||
|
|
||||||
status = "NOK";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deviceStatus["twilight_sensor"] == "NOK")
|
|
||||||
{
|
|
||||||
let writeToFile = errorHandler.processMessage("checkFinalRVOStatus: twilight_sensor is NOK");
|
|
||||||
if(writeToFile) errLogger.error("checkFinalRVOStatus: twilight sensor is NOK");
|
|
||||||
|
|
||||||
status = "NOK";
|
|
||||||
}
|
|
||||||
|
|
||||||
//ak teplomer NOK, rvo nok
|
|
||||||
if(deviceStatus["temperature"] == "NOK")
|
|
||||||
{
|
|
||||||
|
|
||||||
let writeToFile = errorHandler.processMessage("checkFinalRVOStatus: temperature status is NOK");
|
|
||||||
if(writeToFile) errLogger.error("checkFinalRVOStatus: temperature status is NOK");
|
|
||||||
|
|
||||||
status = "NOK";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(status == "OK")
|
if(status == "OK")
|
||||||
{
|
{
|
||||||
let pinIndexes = [1, 4, 6];
|
let pinIndexes = [1, 4, 6];
|
||||||
if(controller_type == 'unipi') pinIndexes = ['input1_01', 'input1_04', 'input1_05'];
|
if(controller_type == 'unipi') pinIndexes = ['input1_01', 'input1_04', 'input1_05'];
|
||||||
|
|
||||||
//console.log('-------- previousValues', previousValues);
|
|
||||||
|
|
||||||
for (const pinIndex of pinIndexes) {
|
for (const pinIndex of pinIndexes) {
|
||||||
if (previousValues[pinIndex] === 0) {
|
if (previousValues[pinIndex] === 0) {
|
||||||
|
|
||||||
if ((pinIndex === 6 || pinIndex === 'input1_01' || pinIndex === 'input1_05') && FLOW.OMS_maintenance_mode) continue;
|
if ((pinIndex === 6 || pinIndex === 'input1_01' || pinIndex === 'input1_05') && FLOW.OMS_maintenance_mode) continue;
|
||||||
|
|
||||||
let writeToFile = errorHandler.processMessage("checkFinalRVOStatus: value is 0");
|
|
||||||
if(writeToFile) errLogger.error("checkFinalRVOStatus: value is 0", pinsData[pinIndex].type);
|
|
||||||
|
|
||||||
status = "NOK";
|
status = "NOK";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// battery status. If value is 1 - battery is NOK
|
// battery status. If value is 1 - battery is NOK
|
||||||
if (previousValues[5] === 1)
|
if (previousValues[5] === 1) status = "NOK";
|
||||||
{
|
if(!FLOW.OMS_masterNodeIsResponding) status = "NOK";
|
||||||
let writeToFile = errorHandler.processMessage("checkFinalRVOStatus: NOK status generated by battery");
|
if(FLOW.OMS_no_voltage.size > 0) status = "NOK";
|
||||||
if(writeToFile) errLogger.error("checkFinalRVOStatus: NOK status generated by battery");
|
|
||||||
|
|
||||||
status = "NOK";
|
return status;
|
||||||
}
|
|
||||||
|
|
||||||
//console.log("FLOW.OMS_masterNodeIsResponding", FLOW.OMS_masterNodeIsResponding);
|
|
||||||
|
|
||||||
if(!FLOW.OMS_masterNodeIsResponding)
|
|
||||||
{
|
|
||||||
//errLogger.error("Master node is not responding");
|
|
||||||
errorHandler.sendMessageToService("Master node is not responding");
|
|
||||||
status = "NOK";
|
|
||||||
|
|
||||||
deviceStatus["master_node"] = "NOK";
|
|
||||||
}
|
|
||||||
else deviceStatus["master_node"] = "OK";
|
|
||||||
|
|
||||||
//console.log("checkFinalRVOStatus", status);
|
|
||||||
if(FLOW.OMS_no_voltage.size > 0)
|
|
||||||
{
|
|
||||||
let writeToFile = errorHandler.processMessage("no voltage detected");
|
|
||||||
if(writeToFile) errLogger.error("no voltage detected", FLOW.OMS_no_voltage);
|
|
||||||
|
|
||||||
status = "NOK";
|
|
||||||
|
|
||||||
deviceStatus["no_voltage"] = "NOK";
|
|
||||||
}
|
|
||||||
else deviceStatus["no_voltage"] = "OK";
|
|
||||||
|
|
||||||
if(status == "NOK")
|
|
||||||
{
|
|
||||||
sendTelemetry({status: "NOK"}, FLOW.OMS_rvo_tbname);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1179,8 +1113,8 @@ exports.install = function(instance) {
|
||||||
// we pass two values in case of websocket ==> switchLogic("relay1_03",1) ==> ["relay1_03",1]
|
// we pass two values in case of websocket ==> switchLogic("relay1_03",1) ==> ["relay1_03",1]
|
||||||
const switchLogic = (...args) => {
|
const switchLogic = (...args) => {
|
||||||
|
|
||||||
let values = {status: "OK"};
|
let values = {};
|
||||||
let dataToTb, pinIndex, newPinValue, twilight;
|
let pinIndex, newPinValue, twilight;
|
||||||
|
|
||||||
//data from rsPort
|
//data from rsPort
|
||||||
if(args.length == 1)
|
if(args.length == 1)
|
||||||
|
|
@ -1201,6 +1135,7 @@ exports.install = function(instance) {
|
||||||
if(obj == undefined)
|
if(obj == undefined)
|
||||||
{
|
{
|
||||||
previousValues[pinIndex] = newPinValue;
|
previousValues[pinIndex] = newPinValue;
|
||||||
|
logger.debug("dido-switchLogic ==> no pinIndex", pinIndex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1216,22 +1151,22 @@ exports.install = function(instance) {
|
||||||
//Hlavný istič
|
//Hlavný istič
|
||||||
//! po novom uz 'state of main switch' nemame. Namiesto neho je 'door_condition', kedze mame dvoje dveri
|
//! po novom uz 'state of main switch' nemame. Namiesto neho je 'door_condition', kedze mame dvoje dveri
|
||||||
//! takze ked pride z evoku signal pre 'input1_05', handlujeme ho ako 'door_condition'
|
//! takze ked pride z evoku signal pre 'input1_05', handlujeme ho ako 'door_condition'
|
||||||
if(type === "!!!state_of_main_switch")
|
// if(type === "!!!state_of_main_switch")
|
||||||
{
|
// {
|
||||||
if (newPinValue === 0 && newPinValue !== previousValues[pinIndex])
|
// if (newPinValue === 0 && newPinValue !== previousValues[pinIndex])
|
||||||
{
|
// {
|
||||||
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";
|
||||||
|
|
||||||
deviceStatus["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");
|
||||||
|
|
||||||
deviceStatus["state_of_main_switch"] = "On";
|
// deviceStatus["state_of_main_switch"] = "On";
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
//Prevádzkový mód
|
//Prevádzkový mód
|
||||||
if(type == "rotary_switch_state")
|
if(type == "rotary_switch_state")
|
||||||
|
|
@ -1271,8 +1206,8 @@ exports.install = function(instance) {
|
||||||
//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
|
||||||
//ak nie je spracovany, iba profil zapisem
|
//ak nie je spracovany, iba profil zapisem
|
||||||
|
|
||||||
instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "rotary_switch_state", value: value});
|
if(pin2 != undefined && pin3 != undefined) instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "rotary_switch_state", value: value});
|
||||||
|
|
||||||
//console.log("rotary_switch_state pin", pin2, pin3, value);
|
//console.log("rotary_switch_state pin", pin2, pin3, value);
|
||||||
}
|
}
|
||||||
|
|
@ -1283,7 +1218,6 @@ exports.install = function(instance) {
|
||||||
{
|
{
|
||||||
//sendNotification("switchLogic", edgeName, ERRWEIGHT.ALERT, "Power supply is not OK", "", SEND_TO.tb, instance);
|
//sendNotification("switchLogic", edgeName, ERRWEIGHT.ALERT, "Power supply is not OK", "", SEND_TO.tb, 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";
|
|
||||||
|
|
||||||
deviceStatus["power_supply"] = "NOK";
|
deviceStatus["power_supply"] = "NOK";
|
||||||
}
|
}
|
||||||
|
|
@ -1302,7 +1236,6 @@ exports.install = function(instance) {
|
||||||
{
|
{
|
||||||
//sendNotification("switchLogic", edgeName, ERRWEIGHT.ERROR, "Battery is not OK", "", SEND_TO.tb, instance);
|
//sendNotification("switchLogic", edgeName, ERRWEIGHT.ERROR, "Battery is not OK", "", SEND_TO.tb, 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";
|
|
||||||
|
|
||||||
deviceStatus["battery"] = "NOK";
|
deviceStatus["battery"] = "NOK";
|
||||||
}
|
}
|
||||||
|
|
@ -1320,13 +1253,6 @@ exports.install = function(instance) {
|
||||||
else if(type == "door_condition" || type === "state_of_main_switch")
|
else if(type == "door_condition" || type === "state_of_main_switch")
|
||||||
{
|
{
|
||||||
newPinValue === 0 ? value = "open" : value = "closed";
|
newPinValue === 0 ? value = "open" : value = "closed";
|
||||||
|
|
||||||
if (newPinValue != previousValues[pinIndex])
|
|
||||||
{
|
|
||||||
//sendNotification("switchLogic", edgeName, ERRWEIGHT.NOTICE, `RVO door ${value}`, "", SEND_TO.tb, instance, "rvo_door");
|
|
||||||
//TODO ? sendNotification("switchLogic", edgeName, "door_value", {value: value}, "", SEND_TO.tb, instance, "rvo_door");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value === "open" && FLOW.OMS_maintenance_mode)
|
if (value === "open" && FLOW.OMS_maintenance_mode)
|
||||||
{
|
{
|
||||||
sendNotification("switchLogic", edgeName, "door_has_been_open", {}, "", SEND_TO.tb, instance, "rvo_door");
|
sendNotification("switchLogic", edgeName, "door_has_been_open", {}, "", SEND_TO.tb, instance, "rvo_door");
|
||||||
|
|
@ -1336,9 +1262,6 @@ exports.install = function(instance) {
|
||||||
{
|
{
|
||||||
//sendNotification("switchLogic", edgeName, ERRWEIGHT.WARNING, "RVO open door out of maintenance mode", "", SEND_TO.tb, instance);
|
//sendNotification("switchLogic", edgeName, ERRWEIGHT.WARNING, "RVO open door out of maintenance mode", "", SEND_TO.tb, instance);
|
||||||
sendNotification("switchLogic", edgeName, "door_has_been_open_without_permision_alarm_is_on", {}, "", SEND_TO.tb, instance, "rvo_door");
|
sendNotification("switchLogic", edgeName, "door_has_been_open_without_permision_alarm_is_on", {}, "", SEND_TO.tb, instance, "rvo_door");
|
||||||
values["status"] = "NOK";
|
|
||||||
|
|
||||||
//console.log(door_has_been_open_without_permision_alarm_is_on);
|
|
||||||
|
|
||||||
// zapneme sirenu
|
// zapneme sirenu
|
||||||
// ak sa otvoria dvere len na elektromeri (type === "state_of_main_switch") alarm sa nema spustit. alarm sa spusti len ked sa otvoria hlavne dvere (type === "door_condition")
|
// ak sa otvoria dvere len na elektromeri (type === "state_of_main_switch") alarm sa nema spustit. alarm sa spusti len ked sa otvoria hlavne dvere (type === "door_condition")
|
||||||
|
|
@ -1353,8 +1276,7 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceStatus["door_condition"] = value;
|
deviceStatus[type] = value;
|
||||||
|
|
||||||
}
|
}
|
||||||
//lux sensor
|
//lux sensor
|
||||||
else if(type == "twilight_sensor")
|
else if(type == "twilight_sensor")
|
||||||
|
|
@ -1362,7 +1284,6 @@ exports.install = function(instance) {
|
||||||
//! TODO - to show nok status, if lux value is not changing more then 10 times.
|
//! 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";
|
|
||||||
value = newPinValue;
|
value = newPinValue;
|
||||||
|
|
||||||
if(controller_type === 'lm')
|
if(controller_type === 'lm')
|
||||||
|
|
@ -1387,7 +1308,6 @@ exports.install = function(instance) {
|
||||||
if(set.size === 1 && !twilightError)
|
if(set.size === 1 && !twilightError)
|
||||||
{
|
{
|
||||||
twilightError = true;
|
twilightError = true;
|
||||||
values["status"] = "NOK";
|
|
||||||
let value = twilight_sensor_array.shift();
|
let value = twilight_sensor_array.shift();
|
||||||
//sendNotification("switchLogic", edgeName, ERRWEIGHT.ERROR, "Lux sensor error", {"Repeating value": value}, SEND_TO.tb, instance );
|
//sendNotification("switchLogic", edgeName, ERRWEIGHT.ERROR, "Lux sensor error", {"Repeating value": value}, SEND_TO.tb, instance );
|
||||||
newPinValue = 0;
|
newPinValue = 0;
|
||||||
|
|
@ -1401,13 +1321,11 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
else if (set.size === 1 && twilightError)
|
else if (set.size === 1 && twilightError)
|
||||||
{
|
{
|
||||||
values["status"] = "NOK";
|
|
||||||
twilight_sensor_array.shift();
|
twilight_sensor_array.shift();
|
||||||
newPinValue = 0;
|
newPinValue = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let diff = twilight_sensor[ twilight_sensor.length - 1 ].timestamp - twilight_sensor[0].timestamp;
|
let diff = twilight_sensor[ twilight_sensor.length - 1 ].timestamp - twilight_sensor[0].timestamp;
|
||||||
if(diff >= twilight_sensor_interval * 60 * 1000)
|
if(diff >= twilight_sensor_interval * 60 * 1000)
|
||||||
{
|
{
|
||||||
|
|
@ -1424,7 +1342,6 @@ exports.install = function(instance) {
|
||||||
else if(type == "state_of_contactor")
|
else if(type == "state_of_contactor")
|
||||||
{
|
{
|
||||||
//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(!(deviceStatus["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 );
|
||||||
|
|
@ -1465,8 +1382,7 @@ exports.install = function(instance) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else if(type === "state_of_breaker")
|
||||||
if(type === "state_of_breaker")
|
|
||||||
{
|
{
|
||||||
|
|
||||||
let valueChanged = false;
|
let valueChanged = false;
|
||||||
|
|
@ -1528,66 +1444,20 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
reportLineStatus(line);
|
reportLineStatus(line);
|
||||||
}
|
}
|
||||||
|
else return;
|
||||||
|
|
||||||
values[type] = value;
|
values[type] = value;
|
||||||
|
|
||||||
//if(FLOW.OMS_rvo_tbname == tbname) values["statecode"] = calculateStateCode();
|
|
||||||
|
|
||||||
if(pinsData.hasOwnProperty(pinIndex))
|
if(type == "rotary_switch_state")
|
||||||
{
|
{
|
||||||
let valueChanged = false;
|
if(FLOW.OMS_maintenance_mode) value = "maintenance";
|
||||||
if(newPinValue != previousValues[pinIndex])
|
value = value.toLowerCase();
|
||||||
{
|
values["power_mode"] = value;
|
||||||
valueChanged = true;
|
|
||||||
//pin was changed
|
|
||||||
previousValues[pinIndex] = newPinValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let result = checkFinalRVOStatus();
|
|
||||||
if(!result && line == 0)
|
|
||||||
{
|
|
||||||
values["status"] = "NOK";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(type == "state_of_contactor") valueChanged = true;
|
|
||||||
if(type == "rotary_switch_state") valueChanged = true;
|
|
||||||
if(type === "state_of_breaker")
|
|
||||||
{
|
|
||||||
//console.log(type, values, valueChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(FLOW.OMS_rvo_tbname == "")
|
|
||||||
{
|
|
||||||
console.log("FLOW.OMS_rvo_tbname is EMPTY");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(FLOW.OMS_rvo_tbname == tbname)
|
|
||||||
{
|
|
||||||
values["statecode"] = calculateStateCode();
|
|
||||||
//console.log('**********************', type, values, valueChanged, FLOW.OMS_rvo_tbname, tbname);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(valueChanged)
|
|
||||||
{
|
|
||||||
sendTelemetry(values, tbname);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(type == "rotary_switch_state")
|
|
||||||
{
|
|
||||||
if(FLOW.OMS_maintenance_mode) value = "maintenance";
|
|
||||||
value = value.toLowerCase();
|
|
||||||
|
|
||||||
let values = {};
|
|
||||||
values["power_mode"] = value;
|
|
||||||
|
|
||||||
sendTelemetry(values, tbname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.debug("no pinIndex", pinsData[pinIndex], pinsData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(newPinValue != previousValues[pinIndex]) previousValues[pinIndex] = newPinValue;
|
||||||
|
if(FLOW.OMS_rvo_tbname == tbname) sendRvoStatus();
|
||||||
|
if(Object.keys(values).length > 0 && tbname) sendTelemetry(values, tbname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1607,15 +1477,20 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
|
|
||||||
function writeThermometerStatusToDb(status) {
|
function writeThermometerStatusToDb(status) {
|
||||||
dbStatus.modify({ thermometer: status }).make(function(builder) {
|
return new Promise(function(resolve, reject) {
|
||||||
builder.callback(function(err, response) {
|
|
||||||
if(!err)
|
dbStatus.modify({ thermometer: status }).make(function(builder) {
|
||||||
{
|
builder.callback(function(err, response) {
|
||||||
deviceStatus["temperature"] = status;
|
if(!err)
|
||||||
console.log(`Wrote to db status: thermometer ${status}`);
|
{
|
||||||
}
|
deviceStatus["temperature"] = status;
|
||||||
});
|
console.log(`Wrote to db status: thermometer ${status}`);
|
||||||
});
|
resolve("ok")
|
||||||
|
}
|
||||||
|
reject("nok")
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1902,25 +1777,52 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
//! pins_data --> from UNIPI
|
//! pins_data --> from UNIPI
|
||||||
// {
|
// {
|
||||||
// '16': { pin: '16', type: 'twilight_sensor', line: 0 },
|
// input1_01: {
|
||||||
// al_mswitch: { pin: 'al_mswitch', type: 'state_of_main_switch', line: 0 },
|
// pin: 'input1_01',
|
||||||
// al_rswitch1: { pin: 'al_rswitch1', type: 'rotary_switch_state', line: 0 },
|
// type: 'door_condition',
|
||||||
// al_rswitch2: { pin: 'al_rswitch2', type: 'rotary_switch_state', line: 0 },
|
// line: 0,
|
||||||
// al_power: { pin: 'al_power', type: 'power_supply', line: 0 },
|
// tbname: 'PLBJzmK1r3Gynd6OW0gGYz0e5wV4vx9bDEqNgYR8'
|
||||||
// al_battery: { pin: 'al_battery', type: 'battery', line: 0 },
|
// },
|
||||||
// al_door: { pin: 'al_door', type: 'door_condition', line: 0 },
|
// input1_02: {
|
||||||
// al_breaker1: { pin: 'al_breaker1', type: 'state_of_breaker', line: 1 },
|
// pin: 'input1_02',
|
||||||
// al_breaker2: { pin: 'al_breaker2', type: 'state_of_breaker', line: 2 },
|
// type: 'rotary_switch_state',
|
||||||
// al_breaker3: { pin: 'al_breaker3', type: 'state_of_breaker', line: 3 },
|
// line: 0,
|
||||||
// al_breaker4: { pin: 'al_breaker4', type: 'state_of_breaker', line: 4 },
|
// tbname: 'PLBJzmK1r3Gynd6OW0gGYz0e5wV4vx9bDEqNgYR8'
|
||||||
// al_relay_1: { pin: 'al_relay_1', type: 'state_of_contactor', line: 1 },
|
// },
|
||||||
// al_relay_2: { pin: 'al_relay_2', type: 'state_of_contactor', line: 2 },
|
// input1_03: {
|
||||||
// al_relay_3: { pin: 'al_relay_3', type: 'state_of_contactor', line: 3 },
|
// pin: 'input1_03',
|
||||||
// al_relay_4: { pin: 'al_relay_4', type: 'state_of_contactor', line: 4 },
|
// type: 'rotary_switch_state',
|
||||||
// '28744F7791180257': { pin: '28744F7791180257', type: 'temperature', line: 0 }
|
// line: 0,
|
||||||
|
// tbname: 'PLBJzmK1r3Gynd6OW0gGYz0e5wV4vx9bDEqNgYR8'
|
||||||
|
// },
|
||||||
|
// input1_04: {
|
||||||
|
// pin: 'input1_04',
|
||||||
|
// type: 'power_supply',
|
||||||
|
// line: 0,
|
||||||
|
// tbname: 'PLBJzmK1r3Gynd6OW0gGYz0e5wV4vx9bDEqNgYR8'
|
||||||
|
// },
|
||||||
|
// input1_05: {
|
||||||
|
// pin: 'input1_05',
|
||||||
|
// type: 'state_of_main_switch',
|
||||||
|
// line: 0,
|
||||||
|
// tbname: 'PLBJzmK1r3Gynd6OW0gGYz0e5wV4vx9bDEqNgYR8'
|
||||||
|
// },
|
||||||
|
// input1_06: {
|
||||||
|
// pin: 'input1_06',
|
||||||
|
// type: 'state_of_breaker',
|
||||||
|
// line: 1,
|
||||||
|
// tbname: '52dD6ZlV1QaOpRBmbAqK8bkKnGzWMLj4eJq38Pgo'
|
||||||
|
// },
|
||||||
|
// relay1_02: {
|
||||||
|
// pin: 'relay1_02',
|
||||||
|
// type: 'state_of_contactor',
|
||||||
|
// line: 1,
|
||||||
|
// tbname: '52dD6ZlV1QaOpRBmbAqK8bkKnGzWMLj4eJq38Pgo'
|
||||||
|
// },
|
||||||
|
// '28F46E9D0E00008B': { pin: '28F46E9D0E00008B', type: 'temperature', line: 0 },
|
||||||
|
// twilight_sensor: { pin: 'twilight_sensor', type: 'twilight_sensor', line: 0 }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
//! relays_data
|
//! relays_data
|
||||||
// {
|
// {
|
||||||
// '0': {
|
// '0': {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class DataToTbHandler
|
class DataToTbHandler {
|
||||||
{
|
|
||||||
constructor(index) {
|
constructor(index) {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
|
|
||||||
|
|
@ -13,27 +13,24 @@ class DataToTbHandler
|
||||||
this.sender = "";
|
this.sender = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
dump()
|
dump() {
|
||||||
{
|
|
||||||
console.log("----------------------------");
|
console.log("----------------------------");
|
||||||
console.log("previousValues", this.previousValues);
|
console.log("previousValues", this.previousValues);
|
||||||
console.log("----------------------------");
|
console.log("----------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
setSender(sender)
|
setSender(sender) {
|
||||||
{
|
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
isEmptyObject( obj ) {
|
isEmptyObject(obj) {
|
||||||
for ( var name in obj ) {
|
for (var name in obj) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendToTb(dataToTb, instance)
|
sendToTb(dataToTb, instance) {
|
||||||
{
|
|
||||||
|
|
||||||
if(!FLOW.OMS_brokerready)
|
if(!FLOW.OMS_brokerready)
|
||||||
{
|
{
|
||||||
|
|
@ -44,11 +41,10 @@ class DataToTbHandler
|
||||||
|
|
||||||
if(keys.length == 0)
|
if(keys.length == 0)
|
||||||
{
|
{
|
||||||
if(this.debug) console.log("sendToTb received epty object", dataToTb);
|
if(this.debug) console.log("sendToTb received empty object", dataToTb);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let tbname = keys[0];
|
let tbname = keys[0];
|
||||||
let ts;
|
let ts;
|
||||||
|
|
||||||
|
|
@ -67,7 +63,7 @@ class DataToTbHandler
|
||||||
|
|
||||||
if(!this.isEmptyObject(values))
|
if(!this.isEmptyObject(values))
|
||||||
{
|
{
|
||||||
arrayOfValuesToSend.push({ts: ts, values: values});
|
arrayOfValuesToSend.push({ts: ts, values: values});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,15 +96,14 @@ class DataToTbHandler
|
||||||
instance.send(this.index, dataToTbModified);
|
instance.send(this.index, dataToTbModified);
|
||||||
}
|
}
|
||||||
|
|
||||||
getDiffTimestamp(key)
|
getDiffTimestamp(key) {
|
||||||
{
|
|
||||||
//TODO set different value for given key!!!
|
//TODO set different value for given key!!!
|
||||||
//if(key == "status") this.timeToHoldTbValue = 2*60*60;//2h
|
//if(key == "status") this.timeToHoldTbValue = 2*60*60;//2h
|
||||||
return this.timeToHoldTbValue * 1000;
|
return this.timeToHoldTbValue * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareValuesForTb(tbname, timestamp, values)
|
prepareValuesForTb(tbname, timestamp, values) {
|
||||||
{
|
|
||||||
let keys = Object.keys(values);
|
let keys = Object.keys(values);
|
||||||
if(!this.previousValues.hasOwnProperty(tbname))
|
if(!this.previousValues.hasOwnProperty(tbname))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -173,9 +173,9 @@ exports.install = function(instance) {
|
||||||
numberOfNotResponding[obj.device] += 1;
|
numberOfNotResponding[obj.device] += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error(require('util').inspect(arguments, {
|
// console.error(require('util').inspect(arguments, {
|
||||||
depth: null
|
// depth: null
|
||||||
}))
|
// }))
|
||||||
|
|
||||||
// if reading out of device's last register returns error, we send accumulated allValues to dido_controller (if allValues are not an empty object)
|
// if reading out of device's last register returns error, we send accumulated allValues to dido_controller (if allValues are not an empty object)
|
||||||
if(obj.index + 1 >= obj.lengthOfActualDeviceStream)
|
if(obj.index + 1 >= obj.lengthOfActualDeviceStream)
|
||||||
|
|
|
||||||
|
|
@ -213,12 +213,11 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
start();
|
start();
|
||||||
}, 15000);
|
}, 10000);
|
||||||
|
|
||||||
startRead = setInterval(start, timeoutMin * 1000 * 60);
|
startRead = setInterval(start, timeoutMin * 1000 * 60);
|
||||||
|
|
||||||
//testing
|
//testing
|
||||||
//setInterval(() => {instance.send(instanceSendTo.dido_controller, {status: "NOK-thermometer"})}, 180000);
|
//setInterval(() => {instance.send(instanceSendTo.dido_controller, {status: "NOK-thermometer"})}, 180000);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -327,7 +327,7 @@ exports.install = function(instance) {
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
if(logger) logger.debug("Broker unavailable. Data not sent !", data.data);
|
if(logger) logger.debug("Broker unavailable. Data not sent !", JSON.stringify(data.data));
|
||||||
instance.send(instanceSendTo.debug, {"message":"Broker unavailable. Data not sent !", "data": data.data });
|
instance.send(instanceSendTo.debug, {"message":"Broker unavailable. Data not sent !", "data": data.data });
|
||||||
|
|
||||||
if(saveTelemetryOnError)
|
if(saveTelemetryOnError)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue