going direct to socket
This commit is contained in:
parent
a00d110f51
commit
7f37f2f19d
@ -4,7 +4,7 @@ const request = require('request');
|
||||
let util = require('util');
|
||||
const logger = require('log4js').getLogger();
|
||||
|
||||
// var db = require('../server/db-connector').dbConnection;
|
||||
// Var db = require('../server/db-connector').dbConnection;
|
||||
|
||||
// var nano = require('nano')('http://martind2000:1V3D4m526i@localhost:5984');
|
||||
// var nano = require('nano')('http://localhost:5984');
|
||||
@ -44,9 +44,11 @@ const mqttClient = function (events) {
|
||||
if (mode !== globalMode) {
|
||||
logger.info('Sending..');
|
||||
globalMode = mode;
|
||||
request(url, function (error, response, body) {
|
||||
/* Request(url, function (error, response, body) {
|
||||
logger.debug(response, body);
|
||||
});
|
||||
}); */
|
||||
|
||||
events.emit('changeState', mode === 'FanOn' ? 1:0);
|
||||
|
||||
d = new Date();
|
||||
lastDispatch = d.getTime();
|
||||
|
35
server.js
35
server.js
@ -15,7 +15,7 @@ const errorhandler = require('errorhandler');
|
||||
const log4js = require('log4js');
|
||||
const logger = log4js.getLogger();
|
||||
let authentication = require('basic-authentication');
|
||||
|
||||
const Wemo = require('wemo-client');
|
||||
const Events = require('events');
|
||||
const busEmitter = new Events.EventEmitter();
|
||||
|
||||
@ -28,12 +28,37 @@ let webSocket = new SocketHandler(busEmitter, wss);
|
||||
|
||||
|
||||
let mqttClient = require('./lib/mqtt/mqttClient');
|
||||
//var mqttConnect = require('./lib/mqtt/mqttConnect');
|
||||
//Var mqttConnect = require('./lib/mqtt/mqttConnect');
|
||||
|
||||
let wemoClient = null;
|
||||
|
||||
|
||||
let wemo = new Wemo();
|
||||
|
||||
wemo.discover(function(deviceInfo) {
|
||||
logger.info('Wemo Device Found: %j', deviceInfo);
|
||||
|
||||
// Get the client for the found device
|
||||
wemoClient = wemo.client(deviceInfo);
|
||||
|
||||
// Handle BinaryState events
|
||||
wemoClient.on('binaryState', function(value) {
|
||||
logger.debug('Binary State changed to: %s', value);
|
||||
});
|
||||
|
||||
// Turn the switch on
|
||||
wemoClient.setBinaryState(0);
|
||||
});
|
||||
|
||||
busEmitter.on('changeState', function(mode) {
|
||||
logger.info('Changing state..');
|
||||
|
||||
wemoClient.setBinaryState(0);
|
||||
});
|
||||
|
||||
|
||||
let mqtt = new mqttClient.mqttClient(busEmitter);
|
||||
|
||||
|
||||
|
||||
require('sugar-date');
|
||||
|
||||
let isProduction = false;
|
||||
@ -92,7 +117,7 @@ app.set('views', __dirname + '/views');
|
||||
app.set('view engine', 'ejs');
|
||||
app.use(morgan('combined'));
|
||||
app.use(cookieparser('your secret here'));
|
||||
/*app.use(session({
|
||||
/*App.use(session({
|
||||
secret: '1234567890QWERTY', resave: false, saveUninitialized: false
|
||||
}));*/
|
||||
app.use(sessionLW());
|
||||
|
Loading…
Reference in New Issue
Block a user