Fake accelerometer and handle hasMainSwitch

This commit is contained in:
rasta5man 2025-05-06 11:58:26 +02:00
parent 5233aa38af
commit d97d90cf95
11 changed files with 3692 additions and 549 deletions

36
addSwitch.py Normal file
View file

@ -0,0 +1,36 @@
import os
def process_set_file():
"""
Checks if /root/flowserver exists, reads set.txt, and modifies the second line.
"""
default_folder = "/root/flowserver" if os.path.exists("/root/flowserver") else "/home/unipi/flowserver"
flag = 1 if default_folder == "/root/flowserver" else 0
try:
with open("/home/unipi/flowserver/databases/settings.table", "r") as f:
lines = f.readlines()
if len(lines) >= 2:
lines[0] = lines[0].rstrip('\n') + "|has_main_switch:boolean\n"
second_line = lines[1].strip() # remove trailing newline
last_pipe_index = second_line.rfind("|")
if last_pipe_index != -1:
modified_line = second_line[:last_pipe_index + 1] + str(flag) + "|" + second_line[last_pipe_index + 1:]
lines[1] = modified_line
else:
print("Warning: No '|' character found in the second line of set.txt")
with open("/home/unipi/flowserver/databases/settings.table", "w") as f:
f.writelines(lines)
else:
print("Warning: settings.table has less than two lines.")
except FileNotFoundError:
print("Error: settings.table not found.")
except Exception as e:
print(e)
# if __name__ == "__main__":
process_set_file()

2
config
View file

@ -7,6 +7,6 @@ package#flow (Object) : { url: '/' }
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.settings : rvo_name:string|lang:string|temperature_address:string|latitude:number|longitude:number|mqtt_host:string|mqtt_clientid:string|mqtt_username:string|mqtt_port:number|maintanace_mode:boolean|project_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|phases:number|cloud_topic:string
table.settings : rvo_name:string|lang:string|temperature_address:string|latitude:number|longitude:number|mqtt_host:string|mqtt_clientid:string|mqtt_username:string|mqtt_port:number|maintanace_mode:boolean|project_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|phases:number|cloud_topic:string|has_main_switch:boolean
table.pins : pin:string|type:string|line:number
table.notifications : key:string|weight:string|sk:string|en:string

File diff suppressed because it is too large Load diff

View file

@ -1,2 +1,2 @@
rvo_name:string|lang:string|temperature_address:string|latitude:number|longitude:number|mqtt_host:string|mqtt_clientid:string|mqtt_username:string|mqtt_port:number|maintanace_mode:boolean|project_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|phases:number|cloud_topic:string
+|rvo_senica_22_ip10.0.0.109|en|28.F46E9D0E0000|48.70826502|17.28455203|192.168.252.1|rvo_senica_22_ip10.0.0.109|9excvr7yBcF3gl3kYZGY|1883|0|48|unipi|ttyUSB0|1|20|5|6|3|u109|...........................................
rvo_name:string|lang:string|temperature_address:string|latitude:number|longitude:number|mqtt_host:string|mqtt_clientid:string|mqtt_username:string|mqtt_port:number|maintanace_mode:boolean|project_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|phases:number|cloud_topic:string|has_main_switch:boolean
+|rvo_senica_22_ip10.0.0.109|en|28.F46E9D0E0000|48.70826502|17.28455203|192.168.252.1|rvo_senica_22_ip10.0.0.109|9excvr7yBcF3gl3kYZGY|1883|0|48|unipi|ttyUSB0|1|20|5|6|3|u109|0|...........................................

View file

@ -44,6 +44,9 @@ exports.install = function(instance) {
const process = require('process');
const { errLogger, logger, monitor } = require('./helper/logger');
//for accelerometer purposes
const { naklony } = require("../databases/accelerometer_db");
const dbNodes = TABLE("nodes");
const dbRelays = TABLE("relays");
@ -111,7 +114,7 @@ exports.install = function(instance) {
priorities["77"] = minutes;
priorities["78"] = minutes;
priorities["79"] = minutes;
priorities["84"] = minutes;
//priorities["84"] = minutes;
minutes = 10;
priorities["87"] = minutes;
@ -122,7 +125,7 @@ exports.install = function(instance) {
priorities["89"] = minutes;
//prikazy kt sa budu spustat na dany node - see config.js in terminal-oms.app. (1 - dimming)
let listOfCommands = [0, 1, 6, 7, 8, 74, 75, 76, 77, 78, 79, 80, 84, 87, 89];
let listOfCommands = [0, 1, 6, 7, 8, 74, 75, 76, 77, 78, 79, 80, 87, 89];
const errorHandler = new ErrorToServiceHandler();
@ -143,6 +146,10 @@ exports.install = function(instance) {
//if sending of profile to node fails, we send notification and push node into set, so we do not send notification twice
const nodeProfileSendFail = new Set();
//we expect to get current temperature in Senica from senica-prod01
let temperatureInSenica = null;
let accelerometerInterval = null;
//END OF VARIABLE SETTINGS
//--------------------------------
@ -184,6 +191,7 @@ exports.install = function(instance) {
setCorrectPlcTimeOnceADay();
sendNodeReadout = setInterval(sendNodesData, 150000);
accelerometerInterval = setInterval(accelerometerData, 60000 * 30); //30 min
}
@ -763,6 +771,10 @@ exports.install = function(instance) {
let tbname = nodesData[node].tbname;
let nodeStatus = nodesData[node].status;
//in case we have reported offline node status, we return (continue with next node)
if (nodeStatus === "OFFLINE") return;
nodesData[node].node_status_before_offline = nodeStatus === true ? true : false;
nodesData[node].status = "OFFLINE";
nodesData[node].readout = {};
@ -1666,7 +1678,7 @@ exports.install = function(instance) {
}
}).catch(function(reason) {
console.log("writeData catch exception", reason);
//console.log("writeData catch exception", reason);
instance.send(SEND_TO.debug, reason);
terminalCommandResponse(params, "FAILURE", null, reason);
@ -1904,6 +1916,7 @@ exports.install = function(instance) {
clearInterval(customTasksInterval);
clearInterval(setCorrectTime);
clearInterval(sendNodeReadout);
clearInterval(accelerometerInterval);
rsPort.close();
});
@ -2071,7 +2084,16 @@ exports.install = function(instance) {
if (flowdata.data.hasOwnProperty("topic")) {
let data = getNested(flowdata.data, "content", "data");
if (data == undefined) {
//if we get temperature in senica from senica-prod01
let temperature = getNested(flowdata.data, "content", "senica_temperature");
if (temperature !== undefined) {
temperatureInSenica = temperature;
return;
}
if (data === undefined) {
console.log("Invalid rpc command came from platform");
return;
}
@ -2682,49 +2704,21 @@ exports.install = function(instance) {
values["time_schedule_settings"] = time_schedule_settings;
}
//naklon
//naklon - nateraz sa z nodu nevycitava! kvoli problemom s accelerometrom a vracanymi hodnotami, posielame temp a x y z vo funkcii accelerometerData()
if (register == 84) {
let temp;
if (byte3 >= 128) {
temp = (byte3 - 128) * (-1);
}
else {
temp = byte3;
}
const temp = byte3 >= 128 ? (byte3 - 128) * (-1) : byte3;
const inclination_x = byte2 >= 128 ? (byte2 - 128) * (-1) : byte2;
const inclination_y = byte1 >= 128 ? (byte1 - 128) * (-1) : byte1;
const inclination_z = byte0 >= 128 ? (byte0 - 128) * (-1) : byte0;
let inclination_x;
if (byte2 >= 128) {
inclination_x = (byte2 - 128) * (-1);
}
else {
inclination_x = byte2;
}
let inclination_y;
if (byte1 >= 128) {
inclination_y = (byte1 - 128) * (-1);
}
else {
inclination_y = byte1;
}
let inclination_z;
if (byte0 >= 128) {
inclination_z = (byte0 - 128) * (-1);
}
else {
inclination_z = byte0;
}
if (temp === undefined) temp = 999;
if (inclination_x === undefined) inclination_x = 999;
if (inclination_y === undefined) inclination_y = 999;
if (inclination_z === undefined) inclination_z = 999;
values["temperature"] = temp;
//náklon x
values["inclination_x"] = inclination_x;
//náklon y
values["inclination_y"] = inclination_y;
//náklon z
values["inclination_z"] = inclination_z;
}
@ -2850,5 +2844,44 @@ exports.install = function(instance) {
return (typeof item === "object" && !Array.isArray(item) && item !== null);
}
// we fake data, that should be received from accelerometer, as they are a bit unreliable. (temperature, x,y,z)
function accelerometerData() {
if (temperatureInSenica === null) return;
for (const key in relaysData) {
const lineData = relaysData[key];
const lineNumber = lineData.line;
const contactor = lineData.contactor;
if (lineNumber === 0) continue;
if (contactor === 1) {
let date = Date.now();
Object.keys(nodesData).forEach((node, index) => {
setTimeout(function() {
if (nodesData[node].line === lineNumber) {
let x = null;
if (naklony.hasOwnProperty(node)) x = naklony[node].naklon;
if (x === null) x = 0;
sendTelemetry({ temperature: Math.round(temperatureInSenica + 10 + Math.floor(Math.random() * 3)), inclination_x: x, inclination_y: 0, inclination_z: 0 }, nodesData[node].tbname, date);
}
}, (index + 1) * 500);
})
}
}
}
} // end of instance.export

View file

@ -65,7 +65,7 @@ exports.install = async function(instance) {
Object.keys(dbs.nodesData).forEach(node => dbs.nodesData[node].readout = {})
dbs.settings = {
edge_fw_version: "2025-01-30", //rok-mesiac-den
edge_fw_version: "2025-04-24", //rok-mesiac-den
language: responseSettings[0]["lang"],
rvo_name: responseSettings[0]["rvo_name"],
project_id: responseSettings[0]["project_id"],
@ -86,6 +86,7 @@ exports.install = async function(instance) {
mqtt_port: responseSettings[0]["mqtt_port"],
phases: responseSettings[0]["phases"],
cloud_topic: responseSettings[0]["cloud_topic"],
has_main_switch: responseSettings[0]["has_main_switch"],
//dynamic values
masterNodeIsResponding: true, //cmd_manager

File diff suppressed because it is too large Load diff

View file

@ -35,16 +35,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
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 -> Manual,
state_of_main_switch - reportovat stav hlaveho istica : 0-> off 1-> on
rotary_switch_state - sem by sa mal reportovat stav vstupov manual a auto pola nasledovnej logiky: Manual = 1 a Auto = 0 -> Manu
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 Ope
twilight_sensor - hodnotu, ktoru vracia ten analogovy vstup (17) treba poslat sem ako float number. Zrejme tu potom pridame nejaky 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 niu 1: 0-> off, 1-> on
state_of_contactor - podľa indexu stykača sa reportuje jeho stav, teda stykač 1 na niu 1: 0-> off, 1-> on
Na kazdu liniu
state_of_breaker - podla indexu istica sa reportuje jeho stav, teda istic na liniu 1: 0-> off, 1-> on
state_of_contactor - podla indexu stkaca sa reportuje jeho stav, teda stykac 1 na liniu 1: 0-> off, 1-> on
*/
const { errLogger, logger, monitor } = require('./helper/logger');
@ -70,6 +70,7 @@ let rvoTbName;
let GLOBALS; //FLOW global GLOBALS
let SETTINGS; // GLOBALS.settings
let controller_type;
let hasMainSwitch;
let alarmStatus = "OFF";
@ -126,17 +127,17 @@ exports.install = function(instance) {
//status for calculating Statecodes
let deviceStatus = { //key is device name: temperature,....
"state_of_main_switch": "Off", //Hlavný istič (po novom druhy dverovy kontakt)
"rotary_switch_state": "Off", //Prevádzkový mód
"state_of_main_switch": "Off", //Hlavny istic (alebo druhy dverovy kontakt)
"rotary_switch_state": "Off", //Prevadzkovy
"door_condition": "closed", //Dverový kontakt
"em": "OK", //elektromer rvo
"temperature": "OK", //templomer
"battery": "OK", //Batéria
"battery": "OK", //Bateria
"power_supply": "OK", //Zdroj
"master_node": "OK", //MN - GLOBALS.settings.masterNodeIsResponding
"no_voltage": "OK", //GLOBALS.settings.no_voltage - výpadok napätia na fáze
"state_of_breaker": {}, //"Off",//Istič
"state_of_contactor": {}, //"Off",//Stykač
"no_voltage": "OK", //GLOBALS.settings.no_voltage - vypadok napatia na faze
"state_of_breaker": {}, //"Off",//Istic
"state_of_contactor": {}, //"Off",//Stykac
"twilight_sensor": "OK" //lux sensor
};
@ -149,10 +150,12 @@ exports.install = function(instance) {
pinsData = GLOBALS.pinsData;
relaysData = GLOBALS.relaysData;
tbHandler = new DataToTbHandler(SEND_TO.tb)
tbHandler = new DataToTbHandler(SEND_TO.tb);
tbHandler.setSender(exports.title);
controller_type = SETTINGS.controller_type //"lm" or "unipi" //logicMachine
controller_type = SETTINGS.controller_type; //"lm" or "unipi"
hasMainSwitch = SETTINGS.has_main_switch;
if (controller_type == "") controller_type = "lm";
console.log(exports.title, "controller type: ", controller_type);
@ -596,27 +599,27 @@ exports.install = function(instance) {
let bits = [];
//Hlavný istič - state_of_main_switch => v rvo senica je to druhy door pre silovu cast (EM)
if (deviceStatus["state_of_main_switch"] == "closed") {
//Hlavny istic - state_of_main_switch => v rvo senica je to druhy door pre silovu cast (EM)
if (deviceStatus["state_of_main_switch"] === "closed" || deviceStatus["state_of_main_switch"] === "Off") {
bits.push(0);
}
else {
bits.push(1);
}
//Prevádzkový mód - Manual, Off, Automatic, maintenance_mode = true/false // DAVA 2 BITY
//Prevadzkovy mod - Manual, Off, Automatic, maintenance_mode = true/false // DAVA 2 BITY
if (!SETTINGS.maintenance_mode) {
if (deviceStatus["rotary_switch_state"] == "Manual") {
if (deviceStatus["rotary_switch_state"] === "Manual") {
bits.push(0);
bits.push(1);
}
if (deviceStatus["rotary_switch_state"] == "Automatic") {
if (deviceStatus["rotary_switch_state"] === "Automatic") {
bits.push(0);
bits.push(0);
}
if (deviceStatus["rotary_switch_state"] == "Off") {
if (deviceStatus["rotary_switch_state"] === "Off") {
bits.push(1);
bits.push(0);
}
@ -626,8 +629,8 @@ exports.install = function(instance) {
bits.push(1);
}
//Dverový kontakt
if (deviceStatus["door_condition"] == "closed") {
//Dverovy kontakt
if (deviceStatus["door_condition"] === "closed") {
bits.push(0);
}
else {
@ -635,7 +638,7 @@ exports.install = function(instance) {
}
//EM
if (deviceStatus["em"] == "NOK") {
if (deviceStatus["em"] === "NOK") {
bits.push(1);
}
else {
@ -643,7 +646,7 @@ exports.install = function(instance) {
}
//Teplomer
if (deviceStatus["temperature"] == "NOK") {
if (deviceStatus["temperature"] === "NOK") {
bits.push(1);
}
else {
@ -651,7 +654,7 @@ exports.install = function(instance) {
}
//Batéria
if (deviceStatus["battery"] == "NOK") {
if (deviceStatus["battery"] === "NOK") {
bits.push(1);
}
else {
@ -659,7 +662,7 @@ exports.install = function(instance) {
}
//Zdroj
if (deviceStatus["power_supply"] == "NOK") {
if (deviceStatus["power_supply"] === "NOK") {
bits.push(1);
}
else {
@ -667,7 +670,7 @@ exports.install = function(instance) {
}
//MN
if (deviceStatus["master_node"] == "NOK") {
if (deviceStatus["master_node"] === "NOK") {
bits.push(1);
}
else {
@ -675,14 +678,14 @@ exports.install = function(instance) {
}
//výpadok napätia na fáze
if (deviceStatus["no_voltage"] == "NOK") {
if (deviceStatus["no_voltage"] === "NOK") {
bits.push(1);
}
else {
bits.push(0);
}
if (deviceStatus["twilight_sensor"] == "NOK") {
if (deviceStatus["twilight_sensor"] === "NOK") {
bits.push(1);
}
else {
@ -738,6 +741,26 @@ exports.install = function(instance) {
}
function getPins(controllerType, hasMainSwitch) {
let pins = [];
if (controllerType === "lm") {
pins = [1, 4, 6];
if (hasMainSwitch === 1) {
pins = [4, 6];
}
} else if (controllerType === "unipi") {
pins = ["input1_01", "input1_04", "input1_05"];
if (hasMainSwitch === 1) {
pins = ["input1_01", "input1_04"];
}
}
return pins;
}
function checkRvoStatus() {
// we check if any of these pins values are 0 --> it means status RVO is "NOK"
@ -746,12 +769,12 @@ exports.install = function(instance) {
let status = "OK";
for (const [key, value] of Object.entries(deviceStatus)) {
if (["em", "twilight_sensor", "temperature", "master_node"].includes(key) && value == "NOK") status = "NOK";
if (["em", "twilight_sensor", "temperature", "master_node"].includes(key) && value === "NOK") status = "NOK";
}
if (status == "OK") {
let pinIndexes = [1, 4, 6];
if (controller_type == 'unipi') pinIndexes = ['input1_01', 'input1_04', 'input1_05'];
if (status === "OK") {
let pinIndexes = getPins(controller_type, hasMainSwitch);
for (const pinIndex of pinIndexes) {
if (previousValues[pinIndex] === 0) {
@ -807,8 +830,20 @@ exports.install = function(instance) {
let value = "On";
if (newPinValue === 0) value = "Off";
//Prevádzkový mód
if (type == "rotary_switch_state") {
//Hlavny istic
if (type === "state_of_main_switch" && hasMainSwitch) {
if (newPinValue === 0 && newPinValue !== previousValues[pinIndex]) {
sendNotification("switchLogic", rvoTbName, "main_switch_has_been_turned_off", {}, "", SEND_TO.tb, instance, "state_of_main_switch");
deviceStatus["state_of_main_switch"] = "Off";
}
else if (newPinValue === 1 && newPinValue !== previousValues[pinIndex]) {
sendNotification("switchLogic", rvoTbName, "main_switch_has_been_turned_on", {}, "", SEND_TO.tb, instance, "state_of_main_switch");
deviceStatus["state_of_main_switch"] = "On";
}
}
//Prevadzkovy mod
else if (type == "rotary_switch_state") {
// combination of these two pins required to get result
let pin2, pin3;
if (pinIndex == 2 || pinIndex == "input1_02") {
@ -860,7 +895,7 @@ exports.install = function(instance) {
}
}
//Batéria - pin 5
//Bateria - pin 5
else if (type === "battery") {
if (newPinValue === 1 && newPinValue !== previousValues[pinIndex]) {
sendNotification("switchLogic", rvoTbName, "battery_level_is_low", {}, "", SEND_TO.tb, instance, "battery_level");
@ -874,9 +909,8 @@ exports.install = function(instance) {
}
}
//Dverový kontakt - pin 6
//! Po novom mame dva dverove kontakty, nie jeden. Druhy je teraz tam, kde bol digital input "state_of_main_switch"
//! preto ked pride z evoku signal z input1_05, co bol predytm "main switch" handlujeme ho teraz ako 'door_condition'
//Dverovy kontakt - pin 6
//! Ak je rvo s dvoma dverovymi kontaktami, ked pride z evoku signal z input1_05, co bol predytm "state_of_main switch" handlujeme ho teraz ako 'door_condition'
else if (type == "door_condition" || type === "state_of_main_switch") {
newPinValue === 0 ? value = "open" : value = "closed";

View file

@ -81,8 +81,7 @@ exports.install = function(instance) {
})
// we create a client for every deviceAddress ( = address) in list and push them into dictionary
for( let i = 0; i < deviceConfig.length; i++)
{
for (let i = 0; i < deviceConfig.length; i++) {
this.clients[deviceConfig[i].deviceAddress] = new modbus.client.RTU(this.socket, deviceConfig[i].deviceAddress, 2000); // 2000 is timeout in register request, default is 5000, which is too long
}
@ -136,15 +135,12 @@ exports.install = function(instance) {
// console.log(deviceAddress, register, tbAttribute, resp);
//device is responding again after NOK status
if(numberOfNotResponding.hasOwnProperty(obj.device))
{
if (numberOfNotResponding.hasOwnProperty(obj.device)) {
let message = "";
if(obj.device == "em340")
{
if (obj.device == "em340") {
message = "electrometer_ok";
}
else if(obj.device == "twilight_sensor")
{
else if (obj.device == "twilight_sensor") {
message = "twilight_sensor_ok";
}
message && sendNotification("modbus_reader: readRegisters", tbName, message, {}, "", SEND_TO.tb, instance);
@ -162,20 +158,16 @@ exports.install = function(instance) {
//console.log("errors pri citani modbus registra", register, obj.indexInDeviceConfig, tbName, tbAttribute);
obj.errors++;
if(obj.errors == obj.lengthOfActualDeviceStream)
{
if (obj.errors == obj.lengthOfActualDeviceStream) {
instance.send(SEND_TO.dido_controller, { status: "NOK-" + obj.device }); // NOK-em340, NOK-em111, NOK-twilight_sensor, NOK-thermometer
//todo - neposlalo notification, ked sme vypojili twilight a neposle to do tb, ale do dido ??
if(!numberOfNotResponding.hasOwnProperty(obj.device))
{
if (!numberOfNotResponding.hasOwnProperty(obj.device)) {
let message = "";
if(obj.device == "twilight_sensor")
{
if (obj.device == "twilight_sensor") {
message = "twilight_sensor_nok";
}
else if(obj.device == "em340")
{
else if (obj.device == "em340") {
message = "electrometer_nok";
}
message && sendNotification("modbus_reader: readingTimeouted", tbName, message, {}, "", SEND_TO.tb, instance);
@ -191,8 +183,7 @@ exports.install = function(instance) {
// }))
// 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) {
if (!isObjectEmpty(obj.allValues)) instance.send(SEND_TO.dido_controller, { values: obj.allValues });
obj.allValues = {};
}
@ -212,8 +203,7 @@ exports.install = function(instance) {
for (let i = 0; i < this.lengthOfActualDeviceStream; i++) {
let a = this.stream[i];
if (a.register === register)
{
if (a.register === register) {
let tbAttribute = a.tbAttribute;
let multiplier = a.multiplier;
@ -222,8 +212,7 @@ exports.install = function(instance) {
// if(tbName == undefined) return;
if(this.index + 1 < this.lengthOfActualDeviceStream)
{
if (this.index + 1 < this.lengthOfActualDeviceStream) {
this.allValues[tbAttribute] = value;
return;
}
@ -244,16 +233,12 @@ exports.install = function(instance) {
}
}
setNewStream = () =>
{
if(this.lengthOfActualDeviceStream == this.index)
{
if(this.indexInDeviceConfig + 1 == deviceConfig.length)
{
setNewStream = () => {
if (this.lengthOfActualDeviceStream == this.index) {
if (this.indexInDeviceConfig + 1 == deviceConfig.length) {
this.indexInDeviceConfig = 0;
}
else
{
else {
this.indexInDeviceConfig += 1;
}
@ -261,13 +246,11 @@ exports.install = function(instance) {
}
}
calculateValue = (response, multiplier) =>
{
calculateValue = (response, multiplier) => {
let value = 0;
let l = response.length;
if (l === 2)
{
if (l === 2) {
value = (response[1] * (2 ** 16) + response[0]);
if (value >= (2 ** 31)) // ak je MSB bit nastavený, eventuálne sa dá použiť aj (value & 0x80000000), ak vieš robiť logický súčin
@ -275,8 +258,7 @@ exports.install = function(instance) {
value = value - "0xFFFFFFFF" + 1;
}
}
else if (l === 1)
{
else if (l === 1) {
value = response[0];
if (value >= (2 ** 15)) // ak je MSB bit nastavený, eventuálne sa dá použiť aj (value & 0x8000), ak vieš robiť logický súčin
@ -293,21 +275,18 @@ exports.install = function(instance) {
if (!(values.hasOwnProperty("Phase_1_voltage") || values.hasOwnProperty("Phase_2_voltage") || values.hasOwnProperty("Phase_3_voltage"))) return;
Object.keys(values).map(singleValue => {
if (this.phases.includes(singleValue))
{
if (this.phases.includes(singleValue)) {
let l = singleValue.split("_");
let phase = parseInt(l[1]);
// console.log(values[singleValue], tbName);
if(values[singleValue] == 0)
{
if (values[singleValue] == 0) {
noVoltage.add(phase);
sendNotification("modbus_reader: checkNullVoltage", tbName, "no_voltage_on_phase", { phase: phase }, "", SEND_TO.tb, instance, "voltage" + phase);
// console.log('no voltage')
}
else
{
else {
noVoltage.delete(phase);
// console.log('voltage detected')
sendNotification("modbus_reader: checkNullVoltage", tbName, "voltage_on_phase_restored", { phase: phase }, "", SEND_TO.tb, instance, "voltage" + phase);
@ -328,14 +307,12 @@ exports.install = function(instance) {
const numberOfNodes = Object.keys(FLOW.GLOBALS.nodesData).length;
if (numberOfNodes == 0) numberOfNodes = 20; // to make sure, we send notification if totalPower is more than 300
if(actualTotalPower > numberOfNodes * 15 && this.onNotificationSent == false)
{
if (actualTotalPower > numberOfNodes * 15 && this.onNotificationSent == false) {
sendNotification("modbus_reader: lampSwitchNotification", tbName, "lamps_have_turned_on", {}, "", SEND_TO.tb, instance);
this.onNotificationSent = true;
this.offNotificationSent = false;
}
else if(actualTotalPower <= numberOfNodes * 15 && this.offNotificationSent == false)
{
else if (actualTotalPower <= numberOfNodes * 15 && this.offNotificationSent == false) {
sendNotification("modbus_reader: lampSwitchNotification", tbName, "lamps_have_turned_off", {}, "", SEND_TO.tb, instance);
this.onNotificationSent = false;
this.offNotificationSent = true;
@ -355,6 +332,8 @@ exports.install = function(instance) {
noVoltage = FLOW.GLOBALS.settings.no_voltage;
mainSocket = new SocketWithClients();
console.log("novoltage: ", noVoltage, typeof noVoltage);
// this notification is to show, that flow (unipi) has been restarted
sendNotification("modbus_reader", tbName, "flow_restart", {}, "", SEND_TO.slack, instance);
}

View file

@ -46,15 +46,16 @@ exports.install = function(instance) {
exec(`owread -C ${temperatureAddress}/temperature`, (error, stdout, stderr) => {
if(!error)
{
if (!error) {
parseData(stdout)
return;
}
counter++;
if(counter == NUMBER_OF_FAILURES_TO_SEND_ERROR) sendNotification("Thermometer_main", rvoTbName, "thermometer_is_not_responding", {}, {"Error": error}, SEND_TO.tb, instance, "thermometer");
if (counter == NUMBER_OF_FAILURES_TO_SEND_ERROR) {
sendNotification("Thermometer_main", rvoTbName, "thermometer_is_not_responding", {}, { "Error": error }, SEND_TO.tb, instance, "thermometer");
monitor.info("Thermometer is not responding", error);
}
instance.send(SEND_TO.dido_controller, { status: "NOK-thermometer" });
});