diff --git a/lib/mqtt/mqttClient.js b/lib/mqtt/mqttClient.js index 454d19b..868db0a 100644 --- a/lib/mqtt/mqttClient.js +++ b/lib/mqtt/mqttClient.js @@ -15,15 +15,20 @@ var busEmitter = new EventEmitter(); var db_name = 'mqtt'; //var dbCouch = nano.use(db_name); +var globalMode = 'FanOff'; busEmitter.on('send', function (mode) { var url = ['https://maker.ifttt.com/trigger/', mode, '/with/key/cWvECkeiyAPwmiOPBkXL2D'].join(''); +if (globalMode !== mode) +{ +globalMode = mode; request(url, function (error, response, body) { if (!error && response.statusCode === 200) { console.log(body); } }); +} }); var mqttClient = function () { @@ -36,7 +41,7 @@ var mqttClient = function () { temp: 0, last: 0 }; - var mode = 'FanOff'; + var mode = 'FanOff'; var d = new Date(); @@ -49,7 +54,7 @@ var mqttClient = function () { // var - if (mode === 'FanOff') { + if (globalMode === 'FanOff') { console.log('Fans off, temp should be <= 19.5'); mode = (parseFloat(this.livingRoom.temp) <= 19.5) ? 'FanOn' : 'FanOff'; } else { @@ -101,9 +106,11 @@ var mqttClient = function () { logger.debug(json); logger.debug(json.temp); +logger.debug('GlobalMode',globalMode); this.livingRoom.temp = parseFloat(json.temp); - if (this.livingRoom.temp >= 23) { + console.log('lr:',this.livingRoom.temp, this.livingRoom.temp >= 22.6); + if (this.livingRoom.temp >= 22.6) { console.log('Max temp reached, turn off' ); busEmitter.emit('send', 'FanOff'); }