bus system proper

This commit is contained in:
Martin Donnelly 2016-11-13 22:33:03 +00:00
parent 81f0222ff6
commit a8b3f4da6c

View File

@ -4,6 +4,7 @@ var util = require('util');
var logger = require('log4js').getLogger(); var logger = require('log4js').getLogger();
var EventEmitter = require('events'); var EventEmitter = require('events');
var Minibus = require('minibus');
// var db = require('../server/db-connector').dbConnection; // var db = require('../server/db-connector').dbConnection;
@ -14,9 +15,8 @@ var busEmitter = new EventEmitter();
var db_name = 'mqtt'; var db_name = 'mqtt';
//var dbCouch = nano.use(db_name); //var dbCouch = nano.use(db_name);
var bus = Minibus.create();
bus.on('send', function (mode) { busEmitter.on('send', function (mode) {
var url = ['https://maker.ifttt.com/trigger/', mode, '/with/key/cWvECkeiyAPwmiOPBkXL2D'].join(''); var url = ['https://maker.ifttt.com/trigger/', mode, '/with/key/cWvECkeiyAPwmiOPBkXL2D'].join('');
request(url, function (error, response, body) { request(url, function (error, response, body) {
@ -68,7 +68,7 @@ var mqttClient = function () {
logger.info('LR temp:', this.livingRoom.temp); logger.info('LR temp:', this.livingRoom.temp);
bus.emit('send', mode); busEmitter.emit('send', mode);
setTimeout(this.fanTimer.bind(this), mod + 10); setTimeout(this.fanTimer.bind(this), mod + 10);
}; };
@ -104,7 +104,7 @@ var mqttClient = function () {
this.livingRoom.temp = parseFloat(json.temp); this.livingRoom.temp = parseFloat(json.temp);
if (this.livingRoom.temp >= 23) { if (this.livingRoom.temp >= 23) {
bus.emit('send', 'FanOff'); busEmitter.emit('send', 'FanOff');
} }
var d = new Date(); var d = new Date();
this.lastMsg = d.getTime(); this.lastMsg = d.getTime();