Tidied version

This commit is contained in:
Martin Donnelly 2016-05-13 13:44:57 +01:00
parent d9ed1eaec9
commit b72834c59b
12 changed files with 339 additions and 267 deletions

18
app.js
View File

@ -81,6 +81,7 @@ projector_v1.use(mqttConnect);
busEmitter.on('lightingOn', lighting_v1.doLightsOn);
busEmitter.on('lightingOff', lighting_v1.doLightsOff);
// busEmitter.on('lightingCmd', lighting_v1.doLightsCmd);
busEmitter.on('heatingOn', mqttConnect.heatingOn);
busEmitter.on('heatingOff', mqttConnect.heatingOff);
@ -93,23 +94,23 @@ cal.startController(busEmitter);
app.get('/stop', function(request, response) {
cal.stopController();
response.sendStatus(200);
});
app.get('/start', function(request, response) {
cal.startController();
response.sendStatus(200);
});
app.get('/api/calendar', function(req, res) {
var calJson = cal.returnCalendar();
console.log(calJson);
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(calJson));
res.json(calJson);
});
app.post('/api/calendar/extend', function(req, res) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({}));
res.json({});
});
@ -167,14 +168,14 @@ wsServer.on('request', function(request) {
console.log((new Date()) + ' Connection accepted.');
var sendSocketHandler = (obj) => {
//Logger.info('sendSocket: ' , JSON.stringify(obj));
// Logger.info('sendSocket: ' , JSON.stringify(obj));
try {
connection.sendUTF(JSON.stringify(obj));
}
catch (err) {
logger.error(err);
logger.warn('Offending object: ', obj);
//logger.warn(util.inspect(obj));
// logger.warn(util.inspect(obj));
}
@ -202,12 +203,9 @@ mqttConnect.connectWS(function() {
console.log('Ready to plug in sockets...');
});
/*App.get('/', function( req, res) {
res.render('index');
});*/
app.post('/api/v1/lighting/off', lighting_v1.turnoff);
app.post('/api/v1/lighting/on', lighting_v1.turnon);
app.post('/api/v1/lighting/cmd', lighting_v1.command);
app.post('/api/v1/heating/off', heating_v1.turnoff);
app.post('/api/v1/heating/on', heating_v1.turnon);

View File

@ -92,14 +92,10 @@
</div>
<div class="mui-row">
<div class="mui-col-xs-12 mui--text-center">
<button id="extend05" class="mui-btn mui-btn--fab" style="display: ;">5
</button>
<button id="extend10" class="mui-btn mui-btn--fab" style="display: ;">10
</button>
<button id="extend15" class="mui-btn mui-btn--fab" style="display: ;">15
</button>
<button id="extend30" class="mui-btn mui-btn--fab" style="display: ;">30
</button>
<button id="extend05" class="mui-btn mui-btn--fab" >5</button>
<button id="extend10" class="mui-btn mui-btn--fab" >10</button>
<button id="extend15" class="mui-btn mui-btn--fab" >15</button>
<button id="extend30" class="mui-btn mui-btn--fab" >30</button>
</div>
</div>
</div>
@ -137,6 +133,19 @@
</button>
</div>
</div>
<div class="mui-col-xs-4 mui--text-center" id="auxFront"
style="display:none;">
<div>
<button class="mui-btn mui-btn--small mui-btn--primary"
id="frontUp">BRIGHTER
</button>
</div>
<div>
<button class="mui-btn mui-btn--small mui-btn--primary"
id="frontDown">DARKER
</button>
</div>
</div>
</div>
</div>
<!--<div class="mui-panel" id="middle-light">
@ -177,6 +186,19 @@
</button>
</div>
</div>
<div class="mui-col-xs-4 mui--text-center" id="auxBack"
style="display: none;">
<div>
<button class="mui-btn mui-btn--small mui-btn--primary"
id="backUp">BRIGHTER
</button>
</div>
<div>
<button class="mui-btn mui-btn--small mui-btn--primary"
id="backDown">DARKER
</button>
</div>
</div>
</div>
</div>
<div class="mui-panel" id="heating-panel" style="display: none;">

View File

@ -9,7 +9,7 @@ var SOController = (function() {
var path;
var wsUrl;
var local = false;
var local = true;
var bus = {};
var prevDate;
var prevTime;
@ -25,7 +25,7 @@ var SOController = (function() {
var extendTimer;
var lightsList = {
off: ['frontLightOff', 'backLightOff'], on: ['frontLightOn', 'backLightOn']
off: ['frontLightOff', 'backLightOff'], on: ['frontLightOn', 'backLightOn'], aux : ['auxFront','auxBack']
};
console.log('Localmode',local);
@ -116,7 +116,7 @@ var SOController = (function() {
var timerDistance = actualEnd.rewind({ minutes: 5 }).getTime() - now.getTime();
if ((timerDistance > 5000) && (timerDistance < 300000)) {
extendTimer = setTimeout(function() {$('#extender:hidden').slideDown();}.bind(this),timerDistance);
extendTimer = setTimeout(function() {$('#extender:hidden').slideDown();},timerDistance);
} else if (timerDistance <= 5000) {
$('#extender:hidden').slideDown();
} else if (timerDistance > 300000) {
@ -150,6 +150,11 @@ var SOController = (function() {
}
}
function lightCommand(id) {
console.log('lightCommand',path + 'api/v1/lighting/cmd');
$.post(path + 'api/v1/lighting/cmd', {id: id}, function() {});
}
function turnOnLights(id) {
console.log('turnonlights',path + 'api/v1/lighting/on');
$.post(path + 'api/v1/lighting/on', {light: id}, function() {});
@ -187,7 +192,6 @@ var SOController = (function() {
}
function attachClicks() {
var self = this;
$('#projectorOn').on('click', function() {
turnOnProjector();
});
@ -233,8 +237,8 @@ var SOController = (function() {
$('#extend05').on('click', function() {
extendMeetingBy.call(this,5);
}.bind(this));
extendMeetingBy(5);
});
$('#extend10').on('click', function() {
extendMeetingBy(10);
@ -248,11 +252,43 @@ var SOController = (function() {
extendMeetingBy(30);
});
$('#frontUp').on('click', function(event) {
var target = $(event.target);
lightCommand('9');
delayButton(target);
});
$('#frontDown').on('click', function(event) {
var target = $(event.target);
lightCommand('1');
delayButton(target);
});
$('#backUp').on('click', function(event) {
var target = $(event.target);
lightCommand('8');
delayButton(target);
});
$('#backDown').on('click', function(event) {
var target = $(event.target);
lightCommand('2');
delayButton(target);
});
}
function delayButton($button) {
$button.attr('disabled', true);//.removeAttr("disabled");
setTimeout(function() {
$button.prop('disabled', false);
},3000);
}
function clock() {
updateDateTime();
var now = new Date;
@ -347,7 +383,6 @@ var SOController = (function() {
});
notification.onclick = function() {
//window.open("http://stackoverflow.com/a/13328397/1269037");
console.log('click');
};

View File

@ -51,19 +51,24 @@ var SOWEBSOCKET = function(newController) {
var _on = ['o', 'n'];
var $show;
var $hide;
var $aux;
_id = _off.indexOf(id);
// console.log(id,_id);
if (_id > -1) {
// Lights are being turnd off
$hide = ['#', controller.lights.off[_id]].join('');
$show = ['#', controller.lights.on[_id]].join('');
$aux = ['#', controller.lights.aux[_id]].join('');
$($aux).fadeOut();
} else {
_id = _on.indexOf(id);
$show = ['#', controller.lights.off[_id]].join('');
$hide = ['#', controller.lights.on[_id]].join('');
$aux = ['#', controller.lights.aux[_id]].join('');
$($aux).fadeIn(500);
}
$($show).show();
$($hide).hide();

View File

@ -17,6 +17,7 @@ var htmlreplace = require('gulp-html-replace');
var googleWebFonts = require('gulp-google-webfonts');
var stripDebug = require('gulp-strip-debug');
var size = require('gulp-size');
var debug = require('gulp-debug');
@ -26,11 +27,12 @@ var filePath = {
gulp.task('scripts', function() {
return gulp.src(['app/js/sowebsocket.js','app/js/colours.js','app/js/appv2.js'])
.pipe(stripDebug())
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(concat('app.js'))
.pipe(stripDebug())
.pipe(jsmin())
.pipe(size({title: 'Scripts'}))
.pipe(gulp.dest('dist/js'));
});
@ -43,6 +45,7 @@ gulp.task('vendor', function() {
'app/lib/microevent.js'])
.pipe(concat('vendor.js'))
.pipe(uglify({mangle: false}))
.pipe(size({title: 'Vendor'}))
.pipe(gulp.dest('dist/js'));
});
@ -54,6 +57,7 @@ gulp.task('styles', function() {
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(cssnano())
.pipe(concat('app.css'))
.pipe(size({title: 'Styles'}))
.pipe(gulp.dest('dist/css'));
});
@ -62,13 +66,14 @@ gulp.task('partials', function() {
// Gulp.src(['app/partials/**/*']).pipe(gulp.dest('dist/partials'));
// gulp.src(['app/libs/ejs_production.js']).pipe(gulp.dest('dist/libs'));
// gulp.src(['app/libs/microevent.js']).pipe(gulp.dest('dist/libs'));
gulp.src(['app/fav/**/*']).pipe(gulp.dest('dist/fav'));
gulp.src(['app/fav/**/*']).pipe(size({title: 'Partials'})).pipe(gulp.dest('dist/fav'));
// Gulp.src(['app/gfx/**/*']).pipe(gulp.dest('dist/gfx'));
});
gulp.task('migrate', function() {
return gulp.src(['dist/**/*'])
.pipe(debug({title: 'migrate:'}))
.pipe(size({title: 'Migrate'}))
.pipe(gulp.dest('/Users/martin/newdev/SODashApp/www'));
});
@ -83,6 +88,7 @@ gulp.task('index', function() {
fonts: 'fonts/fonts.css'
}))
.pipe(htmlmin({removeComments: true, collapseWhitespace: true, keepClosingSlash: true}))
.pipe(size({title: 'Index'}))
.pipe(gulp.dest('dist/'));
});
@ -91,6 +97,7 @@ var options = { };
gulp.task('fonts', function() {
return gulp.src('./fonts.list')
.pipe(googleWebFonts(options))
.pipe(size({title: 'Fonts'}))
.pipe(gulp.dest('dist/fonts'))
;
});

View File

@ -153,6 +153,18 @@ module.exports = {
this.emitter.emit('sendSocket', packet);
this.updateStatus(this.lightList[id], packet);
},
lightingCommand: function(id, callback) {
var packet;
var _callback = callback || null;
if (!this.client) {
return -1;
}
var destinationName = mqttConfig.prefix + this.lighting + '/cmd/' + id + '/fmt/json';
this.client.publish(destinationName, 'cmd', _callback);
// packet = {id: this.lighting, device: id, status: false};
// this.emitter.emit('sendSocket', packet);
//this.updateStatus(this.lightList[id], packet);
},
setupEvents: function() {

View File

@ -1,6 +1,6 @@
'use strict';
var request = require('request');
var cheerio = require('cheerio');
var t = require('./getTimeAndDate');
var log4js = require('log4js');
var logger = log4js.getLogger();
var STRING = require('string');
@ -9,29 +9,21 @@ var Elapsed = require('elapsed');
var clone = require('clone');
require('sugar-date');
var meetingStates = {
STARTING: 0,
INPROGRESS: 1,
NONE: 2,
FINISHED: 3
};
var calendarInterface = function() {
this.jsonBlock = [];
this.cachedStatus = {};
this.setJson = function(j) {
'use strict';
this.jsonBlock = j;
};
this.getJson = function() {
'use strict';
return this.jsonBlock;
};
//Console.log('Calendar synchronisation service Started.');
};
function processICAL(ical) {
'use strict';
var lines, l, counter;
var subcounter, subBlock;
logger.info('+ processICAL');
var workingBlock = [];
var segments = {
@ -46,6 +38,7 @@ function processICAL(ical) {
};
function processBlock(block) {
var alarmFlag, ws, blockStep;
var workBlock = {
summary: '',
dtstart: null,
@ -58,9 +51,8 @@ function processICAL(ical) {
combined: '',
uid: ''
};
var alarmFlag = false, ws, blockStep;
alarmFlag = false;
for (var step = 0; step < block.length; step++) {
// Logger.info(block[step]);
blockStep = block[step];
if (blockStep.indexOf(segments.summaryID) >= 0) {
workBlock.summary = STRING(block[step].split(segments.summaryID)[1]).collapseWhitespace().s;
@ -82,16 +74,12 @@ function processICAL(ical) {
ws = STRING(block[step].split(segments.meetingEndAlt)[1]).collapseWhitespace().s;
workBlock.dtend = Date.create(ws);
}
if (blockStep.indexOf(segments.meetingDescID) >= 0) {
if (!alarmFlag) {
workBlock.description = STRING(block[step].split(segments.meetingDescID)[1]).collapseWhitespace().s;
}
if (blockStep.indexOf(segments.meetingDescID) >= 0 && !alarmFlag) {
workBlock.description = STRING(block[step].split(segments.meetingDescID)[1]).collapseWhitespace().s;
}
if (blockStep.indexOf(segments.uid) >= 0) {
if (!alarmFlag) {
workBlock.uid = STRING(block[step].split(segments.uid)[1]).collapseWhitespace().s;
}
if (blockStep.indexOf(segments.uid) >= 0 && !alarmFlag) {
workBlock.uid = STRING(block[step].split(segments.uid)[1]).collapseWhitespace().s;
}
if (blockStep.indexOf(segments.beginAlarm) >= 0) {
@ -102,7 +90,6 @@ function processICAL(ical) {
if (workBlock.dtstart !== null) {
workBlock.timeStart = workBlock.dtstart.format('{24hr}:{mm}:{ss} {tt}');
workBlock.cronStart = workBlock.dtstart.format('{m} {H} * * *');
// WorkBlock.combined = '<em>' + workBlock.timeStart + '</em> - ';
workBlock.combined = workBlock.timeStart + ' - ';
}
workBlock.combined = workBlock.combined + workBlock.summary;
@ -112,9 +99,7 @@ function processICAL(ical) {
workBlock.timeEnd = workBlock.actualEnd.format('{24hr}:{mm}:{ss} {tt}');
workBlock.cronStop = workBlock.actualEnd.format('{m} {H} * * *');
fiveMins = Date.create( workBlock.actualEnd).addMinutes('-5');
// fiveMins = Date.create(new Date()).addMinutes('5');
fiveMins = Date.create(workBlock.actualEnd).addMinutes('-5');
workBlock.cronAlert = fiveMins.format('{m} {H} * * *');
}
@ -127,13 +112,16 @@ function processICAL(ical) {
return workBlock;
}
var lines = ical.split('\r\n'), l = lines.length, counter = 0;
lines = ical.split('\r\n');
l = lines.length;
counter = 0;
while (counter < l) {
if (lines[counter].indexOf(segments.begin) < 0) {
counter++;
} else {
var subcounter = 0, subBlock = [];
subcounter = 0;
subBlock = [];
while (subcounter < 75) {
if (lines[counter + subcounter].indexOf(segments.end) < 0) {
subBlock.push(lines[counter + subcounter]);
@ -152,7 +140,6 @@ function processICAL(ical) {
}
calendarInterface.prototype.getTodaysMeetings = function() {
'use strict';
logger.info('+ getTodaysMeetings');
var today = {
previous: [], upcoming: [], current: {}
@ -183,26 +170,21 @@ calendarInterface.prototype.getTodaysMeetings = function() {
}
}
// Logger.debug(today);
logger.info('- getTodaysMeetings');
return today;
};
calendarInterface.prototype.getCachedStatus = function() {
'use strict';
return this.cachedStatus;
};
calendarInterface.prototype.getRoomStatusV2 = function(cb) {
'use strict';
var self = this;
// Var calJson = [];
request('http://crmplace.com/censis/ical_server.php?type=ics&key=largemeetingroom&email=largemeetingroom@censis.org.uk', function(err, res, body) {
if (err) {
logger.error('Get remote Calendar Request failed');
// Callback.call(null, new Error('Request failed'));
return;
}
@ -213,108 +195,6 @@ calendarInterface.prototype.getRoomStatusV2 = function(cb) {
cb(processedList);
}
});
};
calendarInterface.prototype.getRoomStatus = function() {
var timeAndDate = new t.getTimeAndDate;
request('http://crmplace.com/censis/ical_server.php?type=ics&key=largemeetingroom&email=largemeetingroom@censis.org.uk', function(err, res, body) {
if (err) {
callback.call(null, new Error('Request failed'));
return;
}
var $ = cheerio.load(body);
var text = $('#element').text();
meetingInfo = $.html();
//Find today's date and time and convert to meeting info format
timeNow = timeAndDate.time;
dateToday = timeAndDate.date;
//Define meeting start and end identifying string
var meetingStartID = 'DTSTART;TZID=Europe/London:';
var meetingEndID = 'DTEND;TZID=Europe/London:';
var meetingDescID = 'DESCRIPTION:';
//Look for meetings taking place today
var meetingStart = new Array;
var meetingEnd = new Array;
var meetingDesc = new Array;
// Break up the file into lines.
var lines = meetingInfo.split('\n');
var meetingNum = 0;
for (i = 0; i < lines.length; i++) {
var n = lines[i].indexOf(meetingStartID);
if (n == -1) {
} else {
var meetingStartStr = lines[i];
var meetingDate = meetingStartStr.substring(meetingStartID.length, meetingStartID.length + 8);
if (meetingDate == dateToday.toString()) {
meetingStart[meetingNum] = lines[i];
meetingEnd[meetingNum] = lines[i + 1];
meetingDesc[meetingNum] = lines[i + 3];
meetingNum += 1;
}
}
}
if (meetingNum == 0) {
console.log('There are no meetings scheduled for today.')
} else {
console.log('Number of meetings today: ' + meetingNum);
var projectorStatus = 0;
//Is there a meeting on now
for (m = 0; m < meetingStart.length; m++) {
if (parseInt(timeNow) == parseInt(meetingStart[m].substring(36, 40))) {
var currentMeeting = m;
} else if ((parseInt(timeNow) <= parseInt(meetingEnd[m].substring(34, 38))) && (parseInt(timeNow) > parseInt(meetingStart[m].substring(36, 40)))) {
var currentMeeting = m;
} else {
var currentMeeting = 'None';
}
}
//If there is a meeting on now, define projector status
if (currentMeeting == 'None') {
console.log('Time now: ' + timeNow);
console.log('No meeting just now.');
} else {
console.log('Current meeting is: ' + meetingDesc[currentMeeting].substring(12, meetingDesc[currentMeeting].length));
if (parseInt(timeNow) == parseInt(meetingStart[currentMeeting].substring(36, 40))) {
return meetingStates.STARTING;
} else if ((parseInt(timeNow) <= parseInt(meetingEnd[currentMeeting].substring(34, 38))) && (parseInt(timeNow) > parseInt(meetingStart[currentMeeting].substring(36, 40)))) {
return meetingStates.INPROGRESS;
} else if (parseInt(timeNow) > parseInt(meetingEnd[currentMeeting].substring(34, 38))) {
return meetingStates.NONE;
}
console.log('Time now: ' + timeNow);
console.log('Meeting start time: ' + meetingStart[currentMeeting].substring(36, 40));
console.log('Meeting end time: ' + meetingEnd[currentMeeting].substring(34, 38));
console.log('Projector Status: ' + projectorStatus);
console.log('');
//Return projectorStatus;
//module.exports.pStatus = projectorStatus;
}
}
});
};
module.exports.calendarInterface = calendarInterface;

View File

@ -0,0 +1,111 @@
//Var t = require('./getTimeAndDate');
var meetingStates = {
STARTING: 0,
INPROGRESS: 1,
NONE: 2,
FINISHED: 3
};
calendarInterface.prototype.getRoomStatus = function() {
var timeAndDate = new t.getTimeAndDate;
request('http://crmplace.com/censis/ical_server.php?type=ics&key=largemeetingroom&email=largemeetingroom@censis.org.uk', function(err, res, body) {
if (err) {
callback.call(null, new Error('Request failed'));
return;
}
var $ = cheerio.load(body);
var text = $('#element').text();
meetingInfo = $.html();
// Find today's date and time and convert to meeting info format
timeNow = timeAndDate.time;
dateToday = timeAndDate.date;
// Define meeting start and end identifying string
var meetingStartID = 'DTSTART;TZID=Europe/London:';
var meetingEndID = 'DTEND;TZID=Europe/London:';
var meetingDescID = 'DESCRIPTION:';
// Look for meetings taking place today
var meetingStart = new Array;
var meetingEnd = new Array;
var meetingDesc = new Array;
// Break up the file into lines.
var lines = meetingInfo.split('\n');
var meetingNum = 0;
for (i = 0; i < lines.length; i++) {
var n = lines[i].indexOf(meetingStartID);
if (n == -1) {
} else {
var meetingStartStr = lines[i];
var meetingDate = meetingStartStr.substring(meetingStartID.length, meetingStartID.length + 8);
if (meetingDate == dateToday.toString()) {
meetingStart[meetingNum] = lines[i];
meetingEnd[meetingNum] = lines[i + 1];
meetingDesc[meetingNum] = lines[i + 3];
meetingNum += 1;
}
}
}
if (meetingNum == 0) {
console.log('There are no meetings scheduled for today.')
} else {
console.log('Number of meetings today: ' + meetingNum);
var projectorStatus = 0;
// Is there a meeting on now
for (m = 0; m < meetingStart.length; m++) {
if (parseInt(timeNow) == parseInt(meetingStart[m].substring(36, 40))) {
var currentMeeting = m;
} else if ((parseInt(timeNow) <= parseInt(meetingEnd[m].substring(34, 38))) && (parseInt(timeNow) > parseInt(meetingStart[m].substring(36, 40)))) {
var currentMeeting = m;
} else {
var currentMeeting = 'None';
}
}
// If there is a meeting on now, define projector status
if (currentMeeting == 'None') {
console.log('Time now: ' + timeNow);
console.log('No meeting just now.');
} else {
console.log('Current meeting is: ' + meetingDesc[currentMeeting].substring(12, meetingDesc[currentMeeting].length));
if (parseInt(timeNow) == parseInt(meetingStart[currentMeeting].substring(36, 40))) {
return meetingStates.STARTING;
} else if ((parseInt(timeNow) <= parseInt(meetingEnd[currentMeeting].substring(34, 38))) && (parseInt(timeNow) > parseInt(meetingStart[currentMeeting].substring(36, 40)))) {
return meetingStates.INPROGRESS;
} else if (parseInt(timeNow) > parseInt(meetingEnd[currentMeeting].substring(34, 38))) {
return meetingStates.NONE;
}
console.log('Time now: ' + timeNow);
console.log('Meeting start time: ' + meetingStart[currentMeeting].substring(36, 40));
console.log('Meeting end time: ' + meetingEnd[currentMeeting].substring(34, 38));
console.log('Projector Status: ' + projectorStatus);
console.log('');
// Return projectorStatus;
// module.exports.pStatus = projectorStatus;
}
}
});
};

View File

@ -37,6 +37,7 @@
"gulp-autoprefixer": "^3.1.0",
"gulp-cache": "^0.4.2",
"gulp-concat": "^2.6.0",
"gulp-cssmin": "^0.1.7",
"gulp-cssnano": "^2.1.2",
"gulp-debug": "^2.1.2",
"gulp-google-webfonts": "0.0.12",
@ -48,6 +49,7 @@
"gulp-livereload": "^3.8.1",
"gulp-notify": "^2.2.0",
"gulp-rename": "^1.2.2",
"gulp-size": "^2.1.0",
"gulp-strip-debug": "^1.1.0",
"gulp-uglify": "^1.5.3",
"jshint": "^2.9.2",

View File

@ -1,4 +1,4 @@
"use strict";
'use strict';
/**
* Created by Martin on 09/02/2016.
*/
@ -10,50 +10,43 @@ var mqttConnect;
function doHeatingOn() {
mqttConnect.doConnection().heatingOn();
mqttConnect.doConnection().heatingOn();
}
function doHeatingOff() {
mqttConnect.doConnection().heatingOff();
mqttConnect.doConnection().heatingOff();
}
function setUseRef(ref) {
mqttConnect = ref;
mqttConnect = ref;
}
function getStatus() {
logger.debug(mqttConnect.socketSet.getClientStatus());
logger.debug(mqttConnect.socketSet.getClientStatus());
}
module.exports = {
mqttConnect:null,
socket:null,
use: function (ref) {
mqttConnect: null,
socket: null,
use: function(ref) {
setUseRef(ref);
},
turnoff: function (req, res) {
},
turnoff: function(req, res) {
doHeatingOff();
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({}));
},
turnon: function (req, res) {
res.json({});
},
turnon: function(req, res) {
doHeatingOn();
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({}));
},
setsocket: function (socket) {
res.json({});
},
setsocket: function(socket) {
this.socket = socket;
return this;
},
subscribe: function (socket) {
},
subscribe: function(socket) {
this.socket.subscribe('Heating','HeatingDataReceived');
}
};
}
};

View File

@ -4,13 +4,10 @@
*/
/*Var mqttConnect = require("../lib/mqtt/mqttConnect");
mqttConnect.doConnection();*/
mqttConnect.doConnection();*/
var mqttConnect;
function doLightsOn(id) {
mqttConnect.doConnection().lightingOn(id);
}
@ -19,62 +16,80 @@ function doLightsOff(id) {
mqttConnect.doConnection().lightingOff(id);
}
function doLightsCommand(id) {
console.log('doLightsCommand', id);
mqttConnect.doConnection().lightingCommand(id);
}
function setUseRef(ref) {
mqttConnect = ref;
}
module.exports = {
mqttConnect: null,
socket: null,
use: function(ref) {
setUseRef(ref);
},
turnoff: function(req, res) {
if (!req.body.light) {
res.status(400).send({ status: 'error', error: 'missing required parameter' });
return;
}
mqttConnect: null, socket: null, use: function(ref) {
setUseRef(ref);
}, turnoff: function(req, res) {
if (!req.body.light) {
res.status(400).send({
status: 'error',
error: 'missing required parameter'
});
return;
}
console.log(req.body.light);
console.log(req.body.light);
if (req.body.hasOwnProperty('light')) {
var light = req.body.light;
doLightsOff(light);
}
if (req.body.hasOwnProperty('light')) {
var light = req.body.light;
doLightsOff(light);
}
res.json({});
}, turnon: function(req, res) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({}));
},
turnon: function(req, res) {
if (!req.body.light) {
res.status(400).send({
status: 'error',
error: 'missing required parameter'
});
return;
}
if (!req.body.light) {
res.status(400).send({ status: 'error', error: 'missing required parameter' });
return;
}
console.log(req.body.light);
console.log(req.body.light);
if (req.body.hasOwnProperty('light')) {
var light = req.body.light;
doLightsOn(light);
}
if (req.body.hasOwnProperty('light')) {
var light = req.body.light;
doLightsOn(light);
}
res.json({});
}, command: function(req, res) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({}));
},
setsocket: function(socket) {
this.socket = socket;
return this;
if (!req.body.id) {
res.status(400).send({
status: 'error',
error: 'missing required parameter'
});
return;
}
},
subscribe: function(socket) {
console.log(req.body.id);
this.socket.subscribe('Lighting','LightingDataReceived');
},
doLightsOn: function(id) {
doLightsOn(id);
},
doLightsOff: function(id) {
doLightsOff(id);
}
};
if (req.body.hasOwnProperty('id')) {
var id = req.body.id;
doLightsCommand(id);
}
res.json({});
}, setsocket: function(socket) {
this.socket = socket;
return this;
}, subscribe: function(socket) {
this.socket.subscribe('Lighting', 'LightingDataReceived');
}, doLightsOn: function(id) {
doLightsOn(id);
}, doLightsOff: function(id) {
doLightsOff(id);
}
};

View File

@ -1,7 +1,7 @@
/**
* Created by Martin on 10/02/2016.
*/
"use strict";
'use strict';
/**
* Created by Martin on 09/02/2016.
*/
@ -9,45 +9,37 @@
var mqttConnect;
function doProjectorOn() {
mqttConnect.doConnection().projectorOn();
mqttConnect.doConnection().projectorOn();
}
function doProjectorOff() {
mqttConnect.doConnection().projectorOff();
mqttConnect.doConnection().projectorOff();
}
function setUseRef(ref) {
mqttConnect = ref;
mqttConnect = ref;
}
module.exports = {
mqttConnect:null,
socket:null,
use: function (ref) {
mqttConnect: null,
socket: null,
use: function(ref) {
setUseRef(ref);
},
turnoff: function (req, res) {
},
turnoff: function(req, res) {
doProjectorOff();
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({}));
},
turnon: function (req, res) {
res.json({});
},
turnon: function(req, res) {
doProjectorOn();
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({}));
},
setsocket: function (socket) {
res.json({});
},
setsocket: function(socket) {
this.socket = socket;
return this;
},
subscribe: function (socket) {
},
subscribe: function(socket) {
this.socket.subscribe('Projector','ProjectorDataReceived');
}
};
}
};