Removing duplicate
This commit is contained in:
parent
8929cc3a53
commit
7e20c7d3f0
1 changed files with 0 additions and 218 deletions
|
|
@ -1,218 +0,0 @@
|
||||||
exports.id = 'thermometer';
|
|
||||||
exports.title = 'Thermometer';
|
|
||||||
exports.group = 'Worksys';
|
|
||||||
exports.color = '#5CB36D';
|
|
||||||
exports.version = '1.0.3';
|
|
||||||
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`;
|
|
||||||
|
|
||||||
const instanceSendTo = {
|
|
||||||
debug: 0,
|
|
||||||
tb: 1,
|
|
||||||
dido_controller: 2
|
|
||||||
}
|
|
||||||
|
|
||||||
//read temperature - frequency
|
|
||||||
let timeoutMin = 5;//minutes
|
|
||||||
|
|
||||||
var path = require('path');
|
|
||||||
var log4js = require("log4js");
|
|
||||||
|
|
||||||
log4js.configure({
|
|
||||||
appenders: {
|
|
||||||
errLogs: { type: 'file', filename: path.join(__dirname + "/../", 'err.txt') },
|
|
||||||
monitorLogs: { type: 'file', compress:true, daysToKeep: 2, maxLogSize: 1048576, backups: 1, keepFileExt: true, filename: path.join(__dirname + "/../", 'monitor.txt') },
|
|
||||||
console: { type: 'console' }
|
|
||||||
},
|
|
||||||
categories: {
|
|
||||||
errLogs: { appenders: ['console', 'errLogs'], level: 'error' },
|
|
||||||
monitorLogs: { appenders: ['console', 'monitorLogs'], level: 'trace' },
|
|
||||||
//another: { appenders: ['console'], level: 'trace' },
|
|
||||||
default: { appenders: ['console'], level: 'trace' }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const errLogger = log4js.getLogger("errLogs");
|
|
||||||
const logger = log4js.getLogger();
|
|
||||||
const monitor = log4js.getLogger("monitorLogs");
|
|
||||||
|
|
||||||
//logger.debug("text")
|
|
||||||
//monitor.info('info');
|
|
||||||
//errLogger.error("some error");
|
|
||||||
|
|
||||||
const { promisifyBuilder } = require('./helper/db_helper');
|
|
||||||
const dbSettings = TABLE("settings");
|
|
||||||
let temperatureAddress = "";
|
|
||||||
|
|
||||||
async function loadSettings()
|
|
||||||
{
|
|
||||||
//todo global FLOW.OMS_edgeName is making problem, so we load it here as well, it should not be
|
|
||||||
let responseSettings = await promisifyBuilder(dbSettings.find());
|
|
||||||
temperatureAddress = responseSettings[0]["temperature_adress"];
|
|
||||||
}
|
|
||||||
|
|
||||||
loadSettings();
|
|
||||||
|
|
||||||
|
|
||||||
exports.install = function(instance) {
|
|
||||||
|
|
||||||
const { exec } = require('child_process');
|
|
||||||
const { sendNotification, ERRWEIGHT } = require('./helper/notification_reporter');
|
|
||||||
|
|
||||||
let startRead;
|
|
||||||
let dataToTb;
|
|
||||||
let counter = 0;
|
|
||||||
|
|
||||||
let edgeName = "";
|
|
||||||
|
|
||||||
|
|
||||||
logger.debug(exports.title, "installed");
|
|
||||||
|
|
||||||
instance.on("close", function(){
|
|
||||||
clearInterval(startRead);
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
const start = function() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
if(FLOW.OMS_controller_type === "unipi")
|
|
||||||
{
|
|
||||||
clearInterval(startRead);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(temperatureAddress === "") throw "gettemperature: temperatureAddress is not defined";
|
|
||||||
|
|
||||||
logger.debug("FLOW.OMS_temperature_adress", FLOW.OMS_temperature_adress);
|
|
||||||
|
|
||||||
exec(`owread -C ${temperatureAddress}/temperature`, (error, stdout, stderr) => {
|
|
||||||
|
|
||||||
edgeName = FLOW.OMS_edgeName;
|
|
||||||
|
|
||||||
if(edgeName !== "")
|
|
||||||
{
|
|
||||||
if(error)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(FLOW.OMS_brokerready == undefined)
|
|
||||||
{
|
|
||||||
logger.debug("gettemparature - FLOW.OMS_brokerready is undefined");
|
|
||||||
|
|
||||||
setTimeout(function(){
|
|
||||||
start();
|
|
||||||
}, 3000);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(FLOW.OMS_brokerready)
|
|
||||||
{
|
|
||||||
//sendNotification("start", edgeName, ERRWEIGHT.WARNING, "Thermometer is not responding", {"Error": error}, instanceSendTo.tb, instance, "thermometer");
|
|
||||||
sendNotification("start", edgeName, "thermometer_is_not_responding", {}, {"Error": error}, instanceSendTo.tb, instance, "thermometer");
|
|
||||||
}
|
|
||||||
|
|
||||||
let status = "NOK";
|
|
||||||
dataToTb = {
|
|
||||||
[edgeName]: [
|
|
||||||
{
|
|
||||||
"ts": Date.now(),
|
|
||||||
"values": {
|
|
||||||
"status": status
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
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"});
|
|
||||||
}
|
|
||||||
else parseData(stdout);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
monitor.info("gettemperature: edgeName is not defined", FLOW.OMS_edgeName);
|
|
||||||
|
|
||||||
setTimeout(function(){
|
|
||||||
start();
|
|
||||||
}, 3000);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//instance.send({"Temp":stdout,"stderr":stderr,"err":error});
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
errLogger.error(exports.title, err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const parseData = function(data) {
|
|
||||||
|
|
||||||
data = parseFloat(data);
|
|
||||||
|
|
||||||
logger.debug("gettemperature", data);
|
|
||||||
|
|
||||||
if(!isNaN(data)) {
|
|
||||||
|
|
||||||
if(counter > 290)
|
|
||||||
{
|
|
||||||
instance.send(instanceSendTo.debug, "[Get temperature component] - temperature data are comming again from RVO after more than 1 day break");
|
|
||||||
|
|
||||||
//sendNotification("parseData", edgeName, ERRWEIGHT.NOTICE, "Thermometer is working again", "", instanceSendTo.tb, instance, "thermometer");
|
|
||||||
if(FLOW.OMS_brokerready) sendNotification("parseData", edgeName, "thermometer_is_responding_again", {}, "", instanceSendTo.tb, instance, "thermometer");
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug("gettemperature", data);
|
|
||||||
const values = {
|
|
||||||
"temperature": Number(data.toFixed(2)),
|
|
||||||
"status": "OK"
|
|
||||||
}
|
|
||||||
|
|
||||||
dataToTb = {
|
|
||||||
[edgeName]: [
|
|
||||||
{
|
|
||||||
"ts": Date.now(),
|
|
||||||
"values":values
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.send(instanceSendTo.tb, dataToTb);
|
|
||||||
instance.send(instanceSendTo.dido_controller, values);
|
|
||||||
|
|
||||||
counter = 0;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
counter++;
|
|
||||||
monitor.info("gettemperature err", counter, data);
|
|
||||||
|
|
||||||
//ked je problem 1 den
|
|
||||||
let day = 24 * 60 / timeoutMin;
|
|
||||||
if ( counter > day && counter < day + 2 ) {
|
|
||||||
//sendNotification("parseData", edgeName, ERRWEIGHT.WARNING, "Thermometer receives invalid data", "", instanceSendTo.tb, instance, "thermometer");
|
|
||||||
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"});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(function(){
|
|
||||||
start();
|
|
||||||
}, 3000);
|
|
||||||
|
|
||||||
startRead = setInterval(start, timeoutMin * 1000 * 60);
|
|
||||||
};
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue