mirror of
https://gitlab.silvrtree.co.uk/martind2000/SODashServer.git
synced 2025-02-14 05:09:15 +00:00
Tidied version
This commit is contained in:
parent
d9ed1eaec9
commit
b72834c59b
18
app.js
18
app.js
@ -81,6 +81,7 @@ projector_v1.use(mqttConnect);
|
|||||||
|
|
||||||
busEmitter.on('lightingOn', lighting_v1.doLightsOn);
|
busEmitter.on('lightingOn', lighting_v1.doLightsOn);
|
||||||
busEmitter.on('lightingOff', lighting_v1.doLightsOff);
|
busEmitter.on('lightingOff', lighting_v1.doLightsOff);
|
||||||
|
// busEmitter.on('lightingCmd', lighting_v1.doLightsCmd);
|
||||||
|
|
||||||
busEmitter.on('heatingOn', mqttConnect.heatingOn);
|
busEmitter.on('heatingOn', mqttConnect.heatingOn);
|
||||||
busEmitter.on('heatingOff', mqttConnect.heatingOff);
|
busEmitter.on('heatingOff', mqttConnect.heatingOff);
|
||||||
@ -93,23 +94,23 @@ cal.startController(busEmitter);
|
|||||||
|
|
||||||
app.get('/stop', function(request, response) {
|
app.get('/stop', function(request, response) {
|
||||||
cal.stopController();
|
cal.stopController();
|
||||||
|
response.sendStatus(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/start', function(request, response) {
|
app.get('/start', function(request, response) {
|
||||||
|
|
||||||
cal.startController();
|
cal.startController();
|
||||||
|
response.sendStatus(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/calendar', function(req, res) {
|
app.get('/api/calendar', function(req, res) {
|
||||||
var calJson = cal.returnCalendar();
|
var calJson = cal.returnCalendar();
|
||||||
console.log(calJson);
|
console.log(calJson);
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.json(calJson);
|
||||||
res.end(JSON.stringify(calJson));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/api/calendar/extend', function(req, res) {
|
app.post('/api/calendar/extend', function(req, res) {
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.json({});
|
||||||
res.end(JSON.stringify({}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -167,14 +168,14 @@ wsServer.on('request', function(request) {
|
|||||||
console.log((new Date()) + ' Connection accepted.');
|
console.log((new Date()) + ' Connection accepted.');
|
||||||
|
|
||||||
var sendSocketHandler = (obj) => {
|
var sendSocketHandler = (obj) => {
|
||||||
//Logger.info('sendSocket: ' , JSON.stringify(obj));
|
// Logger.info('sendSocket: ' , JSON.stringify(obj));
|
||||||
try {
|
try {
|
||||||
connection.sendUTF(JSON.stringify(obj));
|
connection.sendUTF(JSON.stringify(obj));
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
logger.warn('Offending object: ', obj);
|
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...');
|
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/off', lighting_v1.turnoff);
|
||||||
app.post('/api/v1/lighting/on', lighting_v1.turnon);
|
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/off', heating_v1.turnoff);
|
||||||
app.post('/api/v1/heating/on', heating_v1.turnon);
|
app.post('/api/v1/heating/on', heating_v1.turnon);
|
||||||
|
@ -92,14 +92,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="mui-row">
|
<div class="mui-row">
|
||||||
<div class="mui-col-xs-12 mui--text-center">
|
<div class="mui-col-xs-12 mui--text-center">
|
||||||
<button id="extend05" class="mui-btn mui-btn--fab" style="display: ;">5
|
<button id="extend05" class="mui-btn mui-btn--fab" >5</button>
|
||||||
</button>
|
<button id="extend10" class="mui-btn mui-btn--fab" >10</button>
|
||||||
<button id="extend10" class="mui-btn mui-btn--fab" style="display: ;">10
|
<button id="extend15" class="mui-btn mui-btn--fab" >15</button>
|
||||||
</button>
|
<button id="extend30" class="mui-btn mui-btn--fab" >30</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>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -137,6 +133,19 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
<!--<div class="mui-panel" id="middle-light">
|
<!--<div class="mui-panel" id="middle-light">
|
||||||
@ -177,6 +186,19 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
<div class="mui-panel" id="heating-panel" style="display: none;">
|
<div class="mui-panel" id="heating-panel" style="display: none;">
|
||||||
|
@ -9,7 +9,7 @@ var SOController = (function() {
|
|||||||
|
|
||||||
var path;
|
var path;
|
||||||
var wsUrl;
|
var wsUrl;
|
||||||
var local = false;
|
var local = true;
|
||||||
var bus = {};
|
var bus = {};
|
||||||
var prevDate;
|
var prevDate;
|
||||||
var prevTime;
|
var prevTime;
|
||||||
@ -25,7 +25,7 @@ var SOController = (function() {
|
|||||||
var extendTimer;
|
var extendTimer;
|
||||||
|
|
||||||
var lightsList = {
|
var lightsList = {
|
||||||
off: ['frontLightOff', 'backLightOff'], on: ['frontLightOn', 'backLightOn']
|
off: ['frontLightOff', 'backLightOff'], on: ['frontLightOn', 'backLightOn'], aux : ['auxFront','auxBack']
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('Localmode',local);
|
console.log('Localmode',local);
|
||||||
@ -116,7 +116,7 @@ var SOController = (function() {
|
|||||||
var timerDistance = actualEnd.rewind({ minutes: 5 }).getTime() - now.getTime();
|
var timerDistance = actualEnd.rewind({ minutes: 5 }).getTime() - now.getTime();
|
||||||
|
|
||||||
if ((timerDistance > 5000) && (timerDistance < 300000)) {
|
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) {
|
} else if (timerDistance <= 5000) {
|
||||||
$('#extender:hidden').slideDown();
|
$('#extender:hidden').slideDown();
|
||||||
} else if (timerDistance > 300000) {
|
} 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) {
|
function turnOnLights(id) {
|
||||||
console.log('turnonlights',path + 'api/v1/lighting/on');
|
console.log('turnonlights',path + 'api/v1/lighting/on');
|
||||||
$.post(path + 'api/v1/lighting/on', {light: id}, function() {});
|
$.post(path + 'api/v1/lighting/on', {light: id}, function() {});
|
||||||
@ -187,7 +192,6 @@ var SOController = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function attachClicks() {
|
function attachClicks() {
|
||||||
var self = this;
|
|
||||||
$('#projectorOn').on('click', function() {
|
$('#projectorOn').on('click', function() {
|
||||||
turnOnProjector();
|
turnOnProjector();
|
||||||
});
|
});
|
||||||
@ -233,8 +237,8 @@ var SOController = (function() {
|
|||||||
|
|
||||||
|
|
||||||
$('#extend05').on('click', function() {
|
$('#extend05').on('click', function() {
|
||||||
extendMeetingBy.call(this,5);
|
extendMeetingBy(5);
|
||||||
}.bind(this));
|
});
|
||||||
|
|
||||||
$('#extend10').on('click', function() {
|
$('#extend10').on('click', function() {
|
||||||
extendMeetingBy(10);
|
extendMeetingBy(10);
|
||||||
@ -248,11 +252,43 @@ var SOController = (function() {
|
|||||||
extendMeetingBy(30);
|
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() {
|
function clock() {
|
||||||
updateDateTime();
|
updateDateTime();
|
||||||
var now = new Date;
|
var now = new Date;
|
||||||
@ -347,7 +383,6 @@ var SOController = (function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
notification.onclick = function() {
|
notification.onclick = function() {
|
||||||
//window.open("http://stackoverflow.com/a/13328397/1269037");
|
|
||||||
console.log('click');
|
console.log('click');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,19 +51,24 @@ var SOWEBSOCKET = function(newController) {
|
|||||||
var _on = ['o', 'n'];
|
var _on = ['o', 'n'];
|
||||||
var $show;
|
var $show;
|
||||||
var $hide;
|
var $hide;
|
||||||
|
var $aux;
|
||||||
|
|
||||||
_id = _off.indexOf(id);
|
_id = _off.indexOf(id);
|
||||||
|
|
||||||
// console.log(id,_id);
|
// console.log(id,_id);
|
||||||
|
|
||||||
if (_id > -1) {
|
if (_id > -1) {
|
||||||
// Lights are being turnd off
|
// Lights are being turnd off
|
||||||
|
|
||||||
$hide = ['#', controller.lights.off[_id]].join('');
|
$hide = ['#', controller.lights.off[_id]].join('');
|
||||||
$show = ['#', controller.lights.on[_id]].join('');
|
$show = ['#', controller.lights.on[_id]].join('');
|
||||||
|
$aux = ['#', controller.lights.aux[_id]].join('');
|
||||||
|
$($aux).fadeOut();
|
||||||
} else {
|
} else {
|
||||||
_id = _on.indexOf(id);
|
_id = _on.indexOf(id);
|
||||||
$show = ['#', controller.lights.off[_id]].join('');
|
$show = ['#', controller.lights.off[_id]].join('');
|
||||||
$hide = ['#', controller.lights.on[_id]].join('');
|
$hide = ['#', controller.lights.on[_id]].join('');
|
||||||
|
$aux = ['#', controller.lights.aux[_id]].join('');
|
||||||
|
$($aux).fadeIn(500);
|
||||||
}
|
}
|
||||||
$($show).show();
|
$($show).show();
|
||||||
$($hide).hide();
|
$($hide).hide();
|
||||||
|
11
gulpfile.js
11
gulpfile.js
@ -17,6 +17,7 @@ var htmlreplace = require('gulp-html-replace');
|
|||||||
var googleWebFonts = require('gulp-google-webfonts');
|
var googleWebFonts = require('gulp-google-webfonts');
|
||||||
|
|
||||||
var stripDebug = require('gulp-strip-debug');
|
var stripDebug = require('gulp-strip-debug');
|
||||||
|
var size = require('gulp-size');
|
||||||
|
|
||||||
var debug = require('gulp-debug');
|
var debug = require('gulp-debug');
|
||||||
|
|
||||||
@ -26,11 +27,12 @@ var filePath = {
|
|||||||
|
|
||||||
gulp.task('scripts', function() {
|
gulp.task('scripts', function() {
|
||||||
return gulp.src(['app/js/sowebsocket.js','app/js/colours.js','app/js/appv2.js'])
|
return gulp.src(['app/js/sowebsocket.js','app/js/colours.js','app/js/appv2.js'])
|
||||||
.pipe(stripDebug())
|
|
||||||
.pipe(jshint('.jshintrc'))
|
.pipe(jshint('.jshintrc'))
|
||||||
.pipe(jshint.reporter('default'))
|
.pipe(jshint.reporter('default'))
|
||||||
.pipe(concat('app.js'))
|
.pipe(concat('app.js'))
|
||||||
|
.pipe(stripDebug())
|
||||||
.pipe(jsmin())
|
.pipe(jsmin())
|
||||||
|
.pipe(size({title: 'Scripts'}))
|
||||||
.pipe(gulp.dest('dist/js'));
|
.pipe(gulp.dest('dist/js'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -43,6 +45,7 @@ gulp.task('vendor', function() {
|
|||||||
'app/lib/microevent.js'])
|
'app/lib/microevent.js'])
|
||||||
.pipe(concat('vendor.js'))
|
.pipe(concat('vendor.js'))
|
||||||
.pipe(uglify({mangle: false}))
|
.pipe(uglify({mangle: false}))
|
||||||
|
.pipe(size({title: 'Vendor'}))
|
||||||
.pipe(gulp.dest('dist/js'));
|
.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(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
|
||||||
.pipe(cssnano())
|
.pipe(cssnano())
|
||||||
.pipe(concat('app.css'))
|
.pipe(concat('app.css'))
|
||||||
|
.pipe(size({title: 'Styles'}))
|
||||||
.pipe(gulp.dest('dist/css'));
|
.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/partials/**/*']).pipe(gulp.dest('dist/partials'));
|
||||||
// gulp.src(['app/libs/ejs_production.js']).pipe(gulp.dest('dist/libs'));
|
// 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/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.src(['app/gfx/**/*']).pipe(gulp.dest('dist/gfx'));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('migrate', function() {
|
gulp.task('migrate', function() {
|
||||||
return gulp.src(['dist/**/*'])
|
return gulp.src(['dist/**/*'])
|
||||||
.pipe(debug({title: 'migrate:'}))
|
.pipe(debug({title: 'migrate:'}))
|
||||||
|
.pipe(size({title: 'Migrate'}))
|
||||||
.pipe(gulp.dest('/Users/martin/newdev/SODashApp/www'));
|
.pipe(gulp.dest('/Users/martin/newdev/SODashApp/www'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -83,6 +88,7 @@ gulp.task('index', function() {
|
|||||||
fonts: 'fonts/fonts.css'
|
fonts: 'fonts/fonts.css'
|
||||||
}))
|
}))
|
||||||
.pipe(htmlmin({removeComments: true, collapseWhitespace: true, keepClosingSlash: true}))
|
.pipe(htmlmin({removeComments: true, collapseWhitespace: true, keepClosingSlash: true}))
|
||||||
|
.pipe(size({title: 'Index'}))
|
||||||
.pipe(gulp.dest('dist/'));
|
.pipe(gulp.dest('dist/'));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -91,6 +97,7 @@ var options = { };
|
|||||||
gulp.task('fonts', function() {
|
gulp.task('fonts', function() {
|
||||||
return gulp.src('./fonts.list')
|
return gulp.src('./fonts.list')
|
||||||
.pipe(googleWebFonts(options))
|
.pipe(googleWebFonts(options))
|
||||||
|
.pipe(size({title: 'Fonts'}))
|
||||||
.pipe(gulp.dest('dist/fonts'))
|
.pipe(gulp.dest('dist/fonts'))
|
||||||
;
|
;
|
||||||
});
|
});
|
||||||
|
@ -153,6 +153,18 @@ module.exports = {
|
|||||||
this.emitter.emit('sendSocket', packet);
|
this.emitter.emit('sendSocket', packet);
|
||||||
this.updateStatus(this.lightList[id], 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() {
|
setupEvents: function() {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
'use strict';
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
var cheerio = require('cheerio');
|
var cheerio = require('cheerio');
|
||||||
var t = require('./getTimeAndDate');
|
|
||||||
var log4js = require('log4js');
|
var log4js = require('log4js');
|
||||||
var logger = log4js.getLogger();
|
var logger = log4js.getLogger();
|
||||||
var STRING = require('string');
|
var STRING = require('string');
|
||||||
@ -9,29 +9,21 @@ var Elapsed = require('elapsed');
|
|||||||
var clone = require('clone');
|
var clone = require('clone');
|
||||||
require('sugar-date');
|
require('sugar-date');
|
||||||
|
|
||||||
var meetingStates = {
|
|
||||||
STARTING: 0,
|
|
||||||
INPROGRESS: 1,
|
|
||||||
NONE: 2,
|
|
||||||
FINISHED: 3
|
|
||||||
};
|
|
||||||
var calendarInterface = function() {
|
var calendarInterface = function() {
|
||||||
this.jsonBlock = [];
|
this.jsonBlock = [];
|
||||||
this.cachedStatus = {};
|
this.cachedStatus = {};
|
||||||
|
|
||||||
this.setJson = function(j) {
|
this.setJson = function(j) {
|
||||||
'use strict';
|
|
||||||
this.jsonBlock = j;
|
this.jsonBlock = j;
|
||||||
};
|
};
|
||||||
this.getJson = function() {
|
this.getJson = function() {
|
||||||
'use strict';
|
|
||||||
return this.jsonBlock;
|
return this.jsonBlock;
|
||||||
};
|
};
|
||||||
//Console.log('Calendar synchronisation service Started.');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function processICAL(ical) {
|
function processICAL(ical) {
|
||||||
'use strict';
|
var lines, l, counter;
|
||||||
|
var subcounter, subBlock;
|
||||||
logger.info('+ processICAL');
|
logger.info('+ processICAL');
|
||||||
var workingBlock = [];
|
var workingBlock = [];
|
||||||
var segments = {
|
var segments = {
|
||||||
@ -46,6 +38,7 @@ function processICAL(ical) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function processBlock(block) {
|
function processBlock(block) {
|
||||||
|
var alarmFlag, ws, blockStep;
|
||||||
var workBlock = {
|
var workBlock = {
|
||||||
summary: '',
|
summary: '',
|
||||||
dtstart: null,
|
dtstart: null,
|
||||||
@ -58,9 +51,8 @@ function processICAL(ical) {
|
|||||||
combined: '',
|
combined: '',
|
||||||
uid: ''
|
uid: ''
|
||||||
};
|
};
|
||||||
var alarmFlag = false, ws, blockStep;
|
alarmFlag = false;
|
||||||
for (var step = 0; step < block.length; step++) {
|
for (var step = 0; step < block.length; step++) {
|
||||||
// Logger.info(block[step]);
|
|
||||||
blockStep = block[step];
|
blockStep = block[step];
|
||||||
if (blockStep.indexOf(segments.summaryID) >= 0) {
|
if (blockStep.indexOf(segments.summaryID) >= 0) {
|
||||||
workBlock.summary = STRING(block[step].split(segments.summaryID)[1]).collapseWhitespace().s;
|
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;
|
ws = STRING(block[step].split(segments.meetingEndAlt)[1]).collapseWhitespace().s;
|
||||||
workBlock.dtend = Date.create(ws);
|
workBlock.dtend = Date.create(ws);
|
||||||
}
|
}
|
||||||
if (blockStep.indexOf(segments.meetingDescID) >= 0) {
|
if (blockStep.indexOf(segments.meetingDescID) >= 0 && !alarmFlag) {
|
||||||
if (!alarmFlag) {
|
workBlock.description = STRING(block[step].split(segments.meetingDescID)[1]).collapseWhitespace().s;
|
||||||
workBlock.description = STRING(block[step].split(segments.meetingDescID)[1]).collapseWhitespace().s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockStep.indexOf(segments.uid) >= 0) {
|
if (blockStep.indexOf(segments.uid) >= 0 && !alarmFlag) {
|
||||||
if (!alarmFlag) {
|
workBlock.uid = STRING(block[step].split(segments.uid)[1]).collapseWhitespace().s;
|
||||||
workBlock.uid = STRING(block[step].split(segments.uid)[1]).collapseWhitespace().s;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockStep.indexOf(segments.beginAlarm) >= 0) {
|
if (blockStep.indexOf(segments.beginAlarm) >= 0) {
|
||||||
@ -102,7 +90,6 @@ function processICAL(ical) {
|
|||||||
if (workBlock.dtstart !== null) {
|
if (workBlock.dtstart !== null) {
|
||||||
workBlock.timeStart = workBlock.dtstart.format('{24hr}:{mm}:{ss} {tt}');
|
workBlock.timeStart = workBlock.dtstart.format('{24hr}:{mm}:{ss} {tt}');
|
||||||
workBlock.cronStart = workBlock.dtstart.format('{m} {H} * * *');
|
workBlock.cronStart = workBlock.dtstart.format('{m} {H} * * *');
|
||||||
// WorkBlock.combined = '<em>' + workBlock.timeStart + '</em> - ';
|
|
||||||
workBlock.combined = workBlock.timeStart + ' - ';
|
workBlock.combined = workBlock.timeStart + ' - ';
|
||||||
}
|
}
|
||||||
workBlock.combined = workBlock.combined + workBlock.summary;
|
workBlock.combined = workBlock.combined + workBlock.summary;
|
||||||
@ -112,9 +99,7 @@ function processICAL(ical) {
|
|||||||
workBlock.timeEnd = workBlock.actualEnd.format('{24hr}:{mm}:{ss} {tt}');
|
workBlock.timeEnd = workBlock.actualEnd.format('{24hr}:{mm}:{ss} {tt}');
|
||||||
workBlock.cronStop = workBlock.actualEnd.format('{m} {H} * * *');
|
workBlock.cronStop = workBlock.actualEnd.format('{m} {H} * * *');
|
||||||
|
|
||||||
fiveMins = Date.create( workBlock.actualEnd).addMinutes('-5');
|
fiveMins = Date.create(workBlock.actualEnd).addMinutes('-5');
|
||||||
|
|
||||||
// fiveMins = Date.create(new Date()).addMinutes('5');
|
|
||||||
workBlock.cronAlert = fiveMins.format('{m} {H} * * *');
|
workBlock.cronAlert = fiveMins.format('{m} {H} * * *');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,13 +112,16 @@ function processICAL(ical) {
|
|||||||
return workBlock;
|
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) {
|
while (counter < l) {
|
||||||
if (lines[counter].indexOf(segments.begin) < 0) {
|
if (lines[counter].indexOf(segments.begin) < 0) {
|
||||||
counter++;
|
counter++;
|
||||||
} else {
|
} else {
|
||||||
var subcounter = 0, subBlock = [];
|
subcounter = 0;
|
||||||
|
subBlock = [];
|
||||||
while (subcounter < 75) {
|
while (subcounter < 75) {
|
||||||
if (lines[counter + subcounter].indexOf(segments.end) < 0) {
|
if (lines[counter + subcounter].indexOf(segments.end) < 0) {
|
||||||
subBlock.push(lines[counter + subcounter]);
|
subBlock.push(lines[counter + subcounter]);
|
||||||
@ -152,7 +140,6 @@ function processICAL(ical) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
calendarInterface.prototype.getTodaysMeetings = function() {
|
calendarInterface.prototype.getTodaysMeetings = function() {
|
||||||
'use strict';
|
|
||||||
logger.info('+ getTodaysMeetings');
|
logger.info('+ getTodaysMeetings');
|
||||||
var today = {
|
var today = {
|
||||||
previous: [], upcoming: [], current: {}
|
previous: [], upcoming: [], current: {}
|
||||||
@ -183,26 +170,21 @@ calendarInterface.prototype.getTodaysMeetings = function() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Logger.debug(today);
|
|
||||||
logger.info('- getTodaysMeetings');
|
logger.info('- getTodaysMeetings');
|
||||||
return today;
|
return today;
|
||||||
};
|
};
|
||||||
|
|
||||||
calendarInterface.prototype.getCachedStatus = function() {
|
calendarInterface.prototype.getCachedStatus = function() {
|
||||||
'use strict';
|
|
||||||
return this.cachedStatus;
|
return this.cachedStatus;
|
||||||
};
|
};
|
||||||
|
|
||||||
calendarInterface.prototype.getRoomStatusV2 = function(cb) {
|
calendarInterface.prototype.getRoomStatusV2 = function(cb) {
|
||||||
'use strict';
|
|
||||||
var self = this;
|
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) {
|
request('http://crmplace.com/censis/ical_server.php?type=ics&key=largemeetingroom&email=largemeetingroom@censis.org.uk', function(err, res, body) {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error('Get remote Calendar Request failed');
|
logger.error('Get remote Calendar Request failed');
|
||||||
// Callback.call(null, new Error('Request failed'));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,108 +195,6 @@ calendarInterface.prototype.getRoomStatusV2 = function(cb) {
|
|||||||
cb(processedList);
|
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;
|
module.exports.calendarInterface = calendarInterface;
|
||||||
|
111
lib/office/old/calendarInterface.js
Normal file
111
lib/office/old/calendarInterface.js
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
@ -37,6 +37,7 @@
|
|||||||
"gulp-autoprefixer": "^3.1.0",
|
"gulp-autoprefixer": "^3.1.0",
|
||||||
"gulp-cache": "^0.4.2",
|
"gulp-cache": "^0.4.2",
|
||||||
"gulp-concat": "^2.6.0",
|
"gulp-concat": "^2.6.0",
|
||||||
|
"gulp-cssmin": "^0.1.7",
|
||||||
"gulp-cssnano": "^2.1.2",
|
"gulp-cssnano": "^2.1.2",
|
||||||
"gulp-debug": "^2.1.2",
|
"gulp-debug": "^2.1.2",
|
||||||
"gulp-google-webfonts": "0.0.12",
|
"gulp-google-webfonts": "0.0.12",
|
||||||
@ -48,6 +49,7 @@
|
|||||||
"gulp-livereload": "^3.8.1",
|
"gulp-livereload": "^3.8.1",
|
||||||
"gulp-notify": "^2.2.0",
|
"gulp-notify": "^2.2.0",
|
||||||
"gulp-rename": "^1.2.2",
|
"gulp-rename": "^1.2.2",
|
||||||
|
"gulp-size": "^2.1.0",
|
||||||
"gulp-strip-debug": "^1.1.0",
|
"gulp-strip-debug": "^1.1.0",
|
||||||
"gulp-uglify": "^1.5.3",
|
"gulp-uglify": "^1.5.3",
|
||||||
"jshint": "^2.9.2",
|
"jshint": "^2.9.2",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
"use strict";
|
'use strict';
|
||||||
/**
|
/**
|
||||||
* Created by Martin on 09/02/2016.
|
* Created by Martin on 09/02/2016.
|
||||||
*/
|
*/
|
||||||
@ -10,50 +10,43 @@ var mqttConnect;
|
|||||||
|
|
||||||
function doHeatingOn() {
|
function doHeatingOn() {
|
||||||
|
|
||||||
mqttConnect.doConnection().heatingOn();
|
mqttConnect.doConnection().heatingOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
function doHeatingOff() {
|
function doHeatingOff() {
|
||||||
|
|
||||||
mqttConnect.doConnection().heatingOff();
|
mqttConnect.doConnection().heatingOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUseRef(ref) {
|
function setUseRef(ref) {
|
||||||
mqttConnect = ref;
|
mqttConnect = ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStatus() {
|
function getStatus() {
|
||||||
logger.debug(mqttConnect.socketSet.getClientStatus());
|
logger.debug(mqttConnect.socketSet.getClientStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mqttConnect:null,
|
mqttConnect: null,
|
||||||
socket:null,
|
socket: null,
|
||||||
use: function (ref) {
|
use: function(ref) {
|
||||||
setUseRef(ref);
|
setUseRef(ref);
|
||||||
},
|
},
|
||||||
turnoff: function (req, res) {
|
turnoff: function(req, res) {
|
||||||
doHeatingOff();
|
doHeatingOff();
|
||||||
|
res.json({});
|
||||||
res.setHeader('Content-Type', 'application/json');
|
},
|
||||||
res.end(JSON.stringify({}));
|
turnon: function(req, res) {
|
||||||
},
|
|
||||||
turnon: function (req, res) {
|
|
||||||
|
|
||||||
doHeatingOn();
|
doHeatingOn();
|
||||||
|
res.json({});
|
||||||
res.setHeader('Content-Type', 'application/json');
|
},
|
||||||
res.end(JSON.stringify({}));
|
setsocket: function(socket) {
|
||||||
},
|
|
||||||
setsocket: function (socket) {
|
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
return this;
|
return this;
|
||||||
|
},
|
||||||
},
|
subscribe: function(socket) {
|
||||||
subscribe: function (socket) {
|
|
||||||
|
|
||||||
this.socket.subscribe('Heating','HeatingDataReceived');
|
this.socket.subscribe('Heating','HeatingDataReceived');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,13 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*Var mqttConnect = require("../lib/mqtt/mqttConnect");
|
/*Var mqttConnect = require("../lib/mqtt/mqttConnect");
|
||||||
mqttConnect.doConnection();*/
|
mqttConnect.doConnection();*/
|
||||||
|
|
||||||
var mqttConnect;
|
var mqttConnect;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function doLightsOn(id) {
|
function doLightsOn(id) {
|
||||||
mqttConnect.doConnection().lightingOn(id);
|
mqttConnect.doConnection().lightingOn(id);
|
||||||
}
|
}
|
||||||
@ -19,62 +16,80 @@ function doLightsOff(id) {
|
|||||||
mqttConnect.doConnection().lightingOff(id);
|
mqttConnect.doConnection().lightingOff(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function doLightsCommand(id) {
|
||||||
|
console.log('doLightsCommand', id);
|
||||||
|
mqttConnect.doConnection().lightingCommand(id);
|
||||||
|
}
|
||||||
|
|
||||||
function setUseRef(ref) {
|
function setUseRef(ref) {
|
||||||
mqttConnect = ref;
|
mqttConnect = ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mqttConnect: null,
|
mqttConnect: null, socket: null, use: function(ref) {
|
||||||
socket: null,
|
setUseRef(ref);
|
||||||
use: function(ref) {
|
}, turnoff: function(req, res) {
|
||||||
setUseRef(ref);
|
if (!req.body.light) {
|
||||||
},
|
res.status(400).send({
|
||||||
turnoff: function(req, res) {
|
status: 'error',
|
||||||
if (!req.body.light) {
|
error: 'missing required parameter'
|
||||||
res.status(400).send({ status: 'error', error: 'missing required parameter' });
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(req.body.light);
|
console.log(req.body.light);
|
||||||
|
|
||||||
if (req.body.hasOwnProperty('light')) {
|
if (req.body.hasOwnProperty('light')) {
|
||||||
var light = req.body.light;
|
var light = req.body.light;
|
||||||
doLightsOff(light);
|
doLightsOff(light);
|
||||||
}
|
}
|
||||||
|
res.json({});
|
||||||
|
}, turnon: function(req, res) {
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'application/json');
|
if (!req.body.light) {
|
||||||
res.end(JSON.stringify({}));
|
res.status(400).send({
|
||||||
},
|
status: 'error',
|
||||||
turnon: function(req, res) {
|
error: 'missing required parameter'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!req.body.light) {
|
console.log(req.body.light);
|
||||||
res.status(400).send({ status: 'error', error: 'missing required parameter' });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(req.body.light);
|
if (req.body.hasOwnProperty('light')) {
|
||||||
|
var light = req.body.light;
|
||||||
|
doLightsOn(light);
|
||||||
|
}
|
||||||
|
|
||||||
if (req.body.hasOwnProperty('light')) {
|
res.json({});
|
||||||
var light = req.body.light;
|
}, command: function(req, res) {
|
||||||
doLightsOn(light);
|
|
||||||
}
|
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'application/json');
|
if (!req.body.id) {
|
||||||
res.end(JSON.stringify({}));
|
res.status(400).send({
|
||||||
},
|
status: 'error',
|
||||||
setsocket: function(socket) {
|
error: 'missing required parameter'
|
||||||
this.socket = socket;
|
});
|
||||||
return this;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
},
|
console.log(req.body.id);
|
||||||
subscribe: function(socket) {
|
|
||||||
|
|
||||||
this.socket.subscribe('Lighting','LightingDataReceived');
|
if (req.body.hasOwnProperty('id')) {
|
||||||
},
|
var id = req.body.id;
|
||||||
doLightsOn: function(id) {
|
doLightsCommand(id);
|
||||||
doLightsOn(id);
|
}
|
||||||
},
|
|
||||||
doLightsOff: function(id) {
|
res.json({});
|
||||||
doLightsOff(id);
|
}, 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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Created by Martin on 10/02/2016.
|
* Created by Martin on 10/02/2016.
|
||||||
*/
|
*/
|
||||||
"use strict";
|
'use strict';
|
||||||
/**
|
/**
|
||||||
* Created by Martin on 09/02/2016.
|
* Created by Martin on 09/02/2016.
|
||||||
*/
|
*/
|
||||||
@ -9,45 +9,37 @@
|
|||||||
var mqttConnect;
|
var mqttConnect;
|
||||||
|
|
||||||
function doProjectorOn() {
|
function doProjectorOn() {
|
||||||
|
mqttConnect.doConnection().projectorOn();
|
||||||
mqttConnect.doConnection().projectorOn();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function doProjectorOff() {
|
function doProjectorOff() {
|
||||||
|
mqttConnect.doConnection().projectorOff();
|
||||||
mqttConnect.doConnection().projectorOff();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUseRef(ref) {
|
function setUseRef(ref) {
|
||||||
mqttConnect = ref;
|
mqttConnect = ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mqttConnect:null,
|
mqttConnect: null,
|
||||||
socket:null,
|
socket: null,
|
||||||
use: function (ref) {
|
use: function(ref) {
|
||||||
setUseRef(ref);
|
setUseRef(ref);
|
||||||
},
|
},
|
||||||
turnoff: function (req, res) {
|
turnoff: function(req, res) {
|
||||||
doProjectorOff();
|
doProjectorOff();
|
||||||
|
res.json({});
|
||||||
res.setHeader('Content-Type', 'application/json');
|
},
|
||||||
res.end(JSON.stringify({}));
|
turnon: function(req, res) {
|
||||||
},
|
|
||||||
turnon: function (req, res) {
|
|
||||||
doProjectorOn();
|
doProjectorOn();
|
||||||
|
res.json({});
|
||||||
res.setHeader('Content-Type', 'application/json');
|
},
|
||||||
res.end(JSON.stringify({}));
|
setsocket: function(socket) {
|
||||||
},
|
|
||||||
setsocket: function (socket) {
|
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
return this;
|
return this;
|
||||||
|
},
|
||||||
},
|
subscribe: function(socket) {
|
||||||
subscribe: function (socket) {
|
|
||||||
|
|
||||||
this.socket.subscribe('Projector','ProjectorDataReceived');
|
this.socket.subscribe('Projector','ProjectorDataReceived');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user