No turnOff on startup; reportOfflineNodeStatus function fix

This commit is contained in:
rasta5man 2025-01-15 22:17:14 +01:00
parent 75bb2794d2
commit fad53c9c01
3 changed files with 49 additions and 68 deletions

View file

@ -34,23 +34,17 @@ Currently we are interested in pins no. 1,2,3,6,8,9,10,16
pins number 11, 12, 13 (we receive 10,11,12 in rsPortReceivedData) are "stykace"
When port receives data, it must be exactly 4 bytes long. Second byte is pin, that changed its value, fourth byte is value itself.
After that, we set this value to "previousValues[allPins[whichpin]]" variable
*/
/*
RVO objekt:
state_of_main_switch - reportovať stav hlavného ističa : 0-> off 1-> on
rotary_switch_state - sem by sa mal reportovať stav vstupov manual a auto podľa nasledovnej logiky:
Manual = 1 a Auto = 0 -> vyreportuje Manual
Manual = 0 a Auto = 0 -> vyreportuje Off
Manual = 0 a Auto = 1 -> vyreportuje Automatic
rotary_switch_state - sem by sa mal reportovať stav vstupov manual a auto podľa nasledovnej logiky: Manual = 1 a Auto = 0 -> Manual,
Manual = 0 a Auto = 0 -> Off, Manual = 0 a Auto = 1 -> Automatic
door_condition - pin 6, dverový kontakt -> 1 -> vyreportuje Closed, 0 -> vyreportuje Open
twilight_sensor - hodnotu, ktorú vracia ten analógový vstup (17) treba poslať sem ako float number. Zrejme tu potom pridáme nejaký koeficient prevodu na luxy
door_condition - pin 6, dverový kontakt -> 1 -> vyreportuje Closed, 0 -> vyreportuje Open
twilight_sensor - hodnotu, ktorú vracia ten analógový vstup (17) treba poslať sem ako float number. Zrejme tu potom pridáme nejaký koeficient prevodu na luxy
Na každú líniu:
state_of_breaker - podľa indexu ističa sa reportuje jeho stav, teda istič 1 na líniu 1: 0-> off 1-> on
state_of_contactor - podľa indexu stykača sa reportuje jeho stav, teda stykač 1 na líniu 1: 0-> off 1-> on
state_of_breaker - podľa indexu ističa sa reportuje jeho stav, teda istič 1 na líniu 1: 0-> off, 1-> on
state_of_contactor - podľa indexu stykača sa reportuje jeho stav, teda stykač 1 na líniu 1: 0-> off, 1-> on
*/
const { errLogger, logger, monitor } = require('./helper/logger');
@ -77,6 +71,7 @@ let rvoTbName;
let GLOBALS; //FLOW global GLOBALS
let SETTINGS; // GLOBALS.settings
let controller_type;
let contactorSwitchCounter = 0; //how many times line contactor switched ?
let alarmStatus = "OFF";
@ -104,7 +99,7 @@ exports.install = function(instance) {
let previousValues = {};
let rsPortReceivedData = [];
//to be able to get proper twilight values, when
//to be able to get proper twilight values
let twilight_sensor_interval = 5;//minutes
let twilight_sensor = [];
const twilight_sensor_array = [];
@ -198,10 +193,6 @@ exports.install = function(instance) {
if (pinsData[key].type == "state_of_contactor") {
let pin = key - 1;
if (controller_type === "unipi") pin = key;
//this will modify database
let forceTurnOff = true;
turnLine("off", line, pin, forceTurnOff, "turn off on startup");
}
}
@ -317,7 +308,6 @@ exports.install = function(instance) {
turnAlarm("off");
initialSetting();
ws.send(JSON.stringify({ "cmd": "all" }));
// we request dev info about neuron device from evok to keep websocket connection alive
// for some reason this request returns no data, but connection keeps alive
@ -528,7 +518,6 @@ exports.install = function(instance) {
monitor.info(`turnLine ${onOrOff} - (line, pin, force)`, line, pin, force, info);
let cmd = { "cmd": "set", "dev": "relay", "circuit": pin.slice(5), "value": value };
ws.send(JSON.stringify(cmd));
switchLogic(pin, value)
}
//if rvo is 24/7, it has just one switching profile point at 13:00. we do not want to send notification as it repeats every day.
@ -585,6 +574,8 @@ exports.install = function(instance) {
sendRvoStatus();
})
// we expect array as flowdata.data
instance.on("1", flowdata => {
@ -597,22 +588,15 @@ exports.install = function(instance) {
let line = obj.line;
let force = obj.force;
let info = obj.info;
//how many times did the lines switched ? if all lines (except line 0) has switched, we request data from evok:
contactorSwitchCounter++;
if(contactorSwitchCounter == Object.keys(relaysData).length-1 && ws) setTimeout(function(){ws.send(JSON.stringify({cmd:"all"}))},5000);
if (obj.command == "on") turnLine("on", line, undefined, force, info);
else if (obj.command == "off") turnLine("off", line, undefined, force, info);
else if (obj.command == "turnOnAlarm") turnAlarm("on");
else if (obj.command == "turnOffAlarm") turnAlarm("off");
//! ake data prichadzaju z cmd_manager.js ???
//TODO transform to websocket
if (Array.isArray(obj)) {
rsPort.write(Buffer.from(obj), function(err) {
switchLogic(obj);
instance.send(SEND_TO.debug, { "WRITE": obj });
});
}
})