exports.id = 'gettemperature'; exports.title = 'Get RVO temperature'; exports.group = 'Worksys'; exports.color = '#5CB36D'; exports.version = '1.0.2'; exports.output = ["red", "white"]; exports.author = 'Rastislav Kovac'; exports.icon = 'thermometer-three-quarters'; exports.readme = `# Getting temperature values from RVO`; exports.install = function(instance) { const { exec } = require('child_process'); let startRead; let dataToTb; let counter; instance.on("close", function(){ clearInterval(startRead); }) const start = function(){ //console.log("start function called"); exec("owread -C 28.427B45920702/temperature", (error, stdout, stderr) => { parseData(stdout); //instance.send({"Temp":stdout,"stderr":stderr,"err":error}); }); } const parseData = function(data) { data = parseFloat(data); if (!isNaN(data)){ if ( counter > 290 ) { instance.send(0, "[Get temperature component] - temperature data are comming again from RVO after more than 1 day break"); } dataToTb = { "KjbN4q7JPZmexgdnz2yKQ98YAWwO0Q3BMX6ERLoV": [ { "ts": Date.now(), "values": { "temperature": data.toFixed(2) } } ] } instance.send(1, dataToTb); counter = 0; } else { counter++; if ( counter > 288 && counter < 290 ) { instance.send(0, "[Get temperature component] - no temperature data from RVO for more than 1 day"); } } } start(); startRead = setInterval(start, 300000); };