Actual code running on CEZ rvo

This commit is contained in:
rasta5man 2024-04-13 21:46:15 +02:00
parent 86619fbcff
commit a30a8588a7
12 changed files with 2841 additions and 1828 deletions

View file

@ -1,18 +1,18 @@
exports.id = 'thermometer';
exports.id = 'gettemperature';
exports.title = 'Thermometer';
exports.group = 'Worksys';
exports.color = '#5CB36D';
exports.version = '1.0.3';
exports.version = '1.0.2';
exports.output = ["red", "white", "blue"];
exports.author = 'Rastislav Kovac';
exports.icon = 'thermometer-three-quarters';
exports.readme = `# Getting temperature values for RVO. In case of LM, you need device address. In case of unipi, evok sends values, in case thermometer is installed`;
exports.readme = `# Getting temperature values from RVO`;
const instanceSendTo = {
debug: 0,
tb: 1,
dido_controller: 2
di_do_controller: 2
}
//read temperature - frequency
@ -43,7 +43,7 @@ const monitor = log4js.getLogger("monitorLogs");
//monitor.info('info');
//errLogger.error("some error");
const { promisifyBuilder } = require('./helper/db_helper');
const { promisifyBuilder, makeMapFromDbResult } = require('./helper/db_helper.js');
const dbSettings = TABLE("settings");
let temperatureAddress = "";
@ -60,7 +60,7 @@ loadSettings();
exports.install = function(instance) {
const { exec } = require('child_process');
const { sendNotification, ERRWEIGHT } = require('./helper/notification_reporter');
const { sendNotification, ERRWEIGHT } = require('./helper/notification_reporter.js');
let startRead;
let dataToTb;
@ -76,9 +76,9 @@ exports.install = function(instance) {
})
const start = function() {
const start = function(){
try {
try{
if(FLOW.OMS_controller_type === "unipi")
{
@ -130,8 +130,8 @@ exports.install = function(instance) {
monitor.info("Thermometer is not responding", error, FLOW.OMS_brokerready);
// instance.send(instanceSendTo.tb, dataToTb); // poslat stav nok do tb, ak to handluje dido_controller ??
instance.send(instanceSendTo.dido_controller, {status: "NOK-thermometer"});
instance.send(instanceSendTo.tb, dataToTb);
instance.send(instanceSendTo.di_do_controller, {sender: "gettemperature", status: status});
}
else parseData(stdout);
}
@ -162,9 +162,10 @@ exports.install = function(instance) {
logger.debug("gettemperature", data);
if(!isNaN(data)) {
if (!isNaN(data)){
if(counter > 290)
//if ( counter > 290 )
{
instance.send(instanceSendTo.debug, "[Get temperature component] - temperature data are comming again from RVO after more than 1 day break");
@ -173,22 +174,21 @@ exports.install = function(instance) {
}
logger.debug("gettemperature", data);
const values = {
"temperature": Number(data.toFixed(2)),
"status": "OK"
}
dataToTb = {
[edgeName]: [
{
"ts": Date.now(),
"values":values
"values": {
"temperature": Number(data.toFixed(2)),
"status": "OK"
}
}
]
}
instance.send(instanceSendTo.tb, dataToTb);
instance.send(instanceSendTo.dido_controller, values);
instance.send(instanceSendTo.di_do_controller, {sender: "gettemperature", status: "OK"});
counter = 0;
@ -204,8 +204,9 @@ exports.install = function(instance) {
sendNotification("parseData", edgeName, "thermometer_sends_invalid_data", {}, "", instanceSendTo.tb, instance, "thermometer");
instance.send(instanceSendTo.debug, "[Get temperature component] - no temperature data from RVO for more than 1 day");
instance.send(instanceSendTo.dido_controller, {status: "NOK-thermometer"});
instance.send(instanceSendTo.di_do_controller, {sender: "gettemperature", status: "NOK"});
}
}
}
@ -215,4 +216,5 @@ exports.install = function(instance) {
}, 3000);
startRead = setInterval(start, timeoutMin * 1000 * 60);
};