From 0a56812189ace8eefb828ed76e8ece696ec3a54f Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Tue, 28 Feb 2017 22:31:04 +0000 Subject: [PATCH] some changes to global mode --- lib/mqtt/mqttClient.js | 6 +++++- server.js | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/mqtt/mqttClient.js b/lib/mqtt/mqttClient.js index 9c57a2c..749da95 100644 --- a/lib/mqtt/mqttClient.js +++ b/lib/mqtt/mqttClient.js @@ -47,7 +47,7 @@ const mqttClient = function(events) { if (mode !== globalMode) { logger.info('Go for change state'); - globalMode = mode; + // globalMode = mode; logger.debug('Global Mode now A:', globalMode); /* Request(url, function (error, response, body) { logger.debug(response, body); @@ -159,6 +159,10 @@ const mqttClient = function(events) { this.client.subscribe('livingroomTemp'); + this.client.on('updateState', function(newStatus) { + globalMode = (newStatus === 0) ? 'FanOff' : 'FanOn'; + }); + this.client.on('message', function(topic, message) { const now = new Date; const nowMS = (now.getHours() * 3600000) + (now.getMinutes() * 60000); diff --git a/server.js b/server.js index 6a95440..818aea8 100644 --- a/server.js +++ b/server.js @@ -55,12 +55,20 @@ busEmitter.on('changeState', function(mode) { if (wemoClient !== null) { wemoClient.setBinaryState(mode); + let newState = wemoClient.getBinaryState(); + busEmitter.emit('updateState', newState); } else { console.error('No wemoClient'); } }); +setInterval(function() { + let newState = wemoClient.getBinaryState(); + busEmitter.emit('updateState', newState); + + }, 30000); + let mqtt = new mqttClient.mqttClient(busEmitter);