Testpanel with new thermometer komponent
This commit is contained in:
parent
31b5dbba5c
commit
ba4a11a99a
39 changed files with 6415 additions and 2952 deletions
151
flow/gettemperature.txt
Normal file
151
flow/gettemperature.txt
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
exports.id = 'gettemperature';
|
||||
exports.title = 'Thermometer';
|
||||
exports.group = 'Worksys';
|
||||
exports.color = '#5CB36D';
|
||||
exports.version = '1.0.2';
|
||||
exports.input = 1;
|
||||
exports.output = ["red", "white", "blue"];
|
||||
exports.author = 'Rastislav Kovac';
|
||||
exports.icon = 'thermometer-three-quarters';
|
||||
|
||||
exports.readme = `# Getting temperature values from RVO`;
|
||||
|
||||
const { errLogger, logger, monitor } = require('./helper/logger');
|
||||
|
||||
const SEND_TO = {
|
||||
debug: 0,
|
||||
tb: 1,
|
||||
di_do_controller: 2
|
||||
}
|
||||
|
||||
//read temperature - frequency
|
||||
let timeoutMin = 5;//minutes
|
||||
|
||||
|
||||
exports.install = function(instance) {
|
||||
|
||||
const { exec } = require('child_process');
|
||||
const { sendNotification } = require('./helper/notification_reporter.js');
|
||||
|
||||
let startRead;
|
||||
let dataToTb;
|
||||
let counter = 0;
|
||||
|
||||
let SETTINGS;
|
||||
let temperatureAddress = "";
|
||||
let rvoTbName = "";
|
||||
|
||||
|
||||
logger.debug(exports.title, "installed");
|
||||
|
||||
instance.on("close", function(){
|
||||
clearInterval(startRead);
|
||||
})
|
||||
|
||||
|
||||
const main = function(){
|
||||
|
||||
try {
|
||||
|
||||
if(SETTINGS.controller_type === "unipi")
|
||||
{
|
||||
clearInterval(startRead);
|
||||
return;
|
||||
}
|
||||
|
||||
if(temperatureAddress === "") throw "gettemperature: temperatureAddress is not defined";
|
||||
|
||||
exec(`owread -C ${temperatureAddress}/temperature`, (error, stdout, stderr) => {
|
||||
|
||||
if(!error)
|
||||
{
|
||||
parseData(stdout)
|
||||
return;
|
||||
}
|
||||
|
||||
sendNotification("main", rvoTbName, "thermometer_is_not_responding", {}, {"Error": error}, SEND_TO.tb, instance, "thermometer");
|
||||
logger.debug("gettemparature", error);
|
||||
monitor.info("Thermometer is not responding", error);
|
||||
|
||||
dataToTb = {
|
||||
[rvoTbName]: [
|
||||
{
|
||||
"ts": Date.now(),
|
||||
"values": {
|
||||
"status": "NOK"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
instance.send(SEND_TO.tb, dataToTb);
|
||||
instance.send(SEND_TO.di_do_controller, {sender: "gettemperature", status: "NOK"});
|
||||
});
|
||||
|
||||
}
|
||||
catch(err) {
|
||||
errLogger.error(exports.title, err);
|
||||
clearInterval(startRead);
|
||||
}
|
||||
}
|
||||
|
||||
const parseData = function(data) {
|
||||
|
||||
data = parseFloat(data);
|
||||
logger.debug("gettemperature", data);
|
||||
|
||||
if (!isNaN(data)){
|
||||
|
||||
|
||||
if(counter > 290)
|
||||
{
|
||||
instance.send(SEND_TO.debug, "[Get temperature component] - temperature data are comming again from RVO after more than 1 day break");
|
||||
sendNotification("parseData", rvoTbName, "thermometer_is_responding_again", {}, "", SEND_TO.tb, instance, "thermometer");
|
||||
}
|
||||
|
||||
logger.debug("gettemperature", data);
|
||||
|
||||
dataToTb = {
|
||||
[rvoTbName]: [
|
||||
{
|
||||
"ts": Date.now(),
|
||||
"values": {
|
||||
"temperature": Number(data.toFixed(2)),
|
||||
"status": "OK"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
instance.send(SEND_TO.tb, dataToTb);
|
||||
instance.send(SEND_TO.di_do_controller, {sender: "gettemperature", status: "OK"});
|
||||
|
||||
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", rvoTbName, "thermometer_sends_invalid_data", {}, "", SEND_TO.tb, instance, "thermometer");
|
||||
|
||||
instance.send(SEND_TO.debug, "[Get temperature component] - no temperature data from RVO for more than 1 day");
|
||||
instance.send(SEND_TO.di_do_controller, {sender: "gettemperature", status: "NOK"});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
instance.on("data", _ => {
|
||||
SETTINGS = FLOW.GLOBALS.settings;
|
||||
temperatureAddress = SETTINGS.temperature_address;
|
||||
rvoTbName = SETTINGS.rvoTbName;
|
||||
startRead = setInterval(main, timeoutMin * 1000 * 60);
|
||||
main();
|
||||
})
|
||||
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue