2016-04-25 09:35:39 +00:00
|
|
|
'use strict';
|
2016-04-13 09:01:28 +00:00
|
|
|
/**
|
|
|
|
* Created by Martin on 09/02/2016.
|
|
|
|
*/
|
|
|
|
|
2016-04-25 09:35:39 +00:00
|
|
|
/*Var mqttConnect = require("../lib/mqtt/mqttConnect");
|
2016-04-13 09:01:28 +00:00
|
|
|
mqttConnect.doConnection();*/
|
|
|
|
|
|
|
|
var mqttConnect;
|
|
|
|
|
2016-04-25 09:35:39 +00:00
|
|
|
|
2016-04-13 09:01:28 +00:00
|
|
|
|
2016-04-27 10:17:11 +00:00
|
|
|
|
|
|
|
function doLightsOn(id) {
|
2016-04-25 09:35:39 +00:00
|
|
|
mqttConnect.doConnection().lightingOn(id);
|
2016-04-13 09:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function doLightsOff(id) {
|
2016-04-25 09:35:39 +00:00
|
|
|
mqttConnect.doConnection().lightingOff(id);
|
2016-04-13 09:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setUseRef(ref) {
|
2016-04-25 09:35:39 +00:00
|
|
|
mqttConnect = ref;
|
2016-04-13 09:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2016-04-25 09:35:39 +00:00
|
|
|
mqttConnect: null,
|
|
|
|
socket: null,
|
|
|
|
use: function(ref) {
|
2016-04-13 09:01:28 +00:00
|
|
|
setUseRef(ref);
|
2016-04-25 09:35:39 +00:00
|
|
|
},
|
|
|
|
turnoff: function(req, res) {
|
2016-04-13 09:01:28 +00:00
|
|
|
if (!req.body.light) {
|
2016-04-25 09:35:39 +00:00
|
|
|
res.status(400).send({ status: 'error', error: 'missing required parameter' });
|
|
|
|
return;
|
2016-04-13 09:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log(req.body.light);
|
|
|
|
|
2016-04-25 09:35:39 +00:00
|
|
|
if (req.body.hasOwnProperty('light')) {
|
|
|
|
var light = req.body.light;
|
|
|
|
doLightsOff(light);
|
2016-04-13 09:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res.setHeader('Content-Type', 'application/json');
|
|
|
|
res.end(JSON.stringify({}));
|
2016-04-25 09:35:39 +00:00
|
|
|
},
|
|
|
|
turnon: function(req, res) {
|
2016-04-13 09:01:28 +00:00
|
|
|
|
|
|
|
if (!req.body.light) {
|
2016-04-25 09:35:39 +00:00
|
|
|
res.status(400).send({ status: 'error', error: 'missing required parameter' });
|
|
|
|
return;
|
2016-04-13 09:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log(req.body.light);
|
|
|
|
|
2016-04-25 09:35:39 +00:00
|
|
|
if (req.body.hasOwnProperty('light')) {
|
|
|
|
var light = req.body.light;
|
|
|
|
doLightsOn(light);
|
2016-04-13 09:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res.setHeader('Content-Type', 'application/json');
|
|
|
|
res.end(JSON.stringify({}));
|
2016-04-25 09:35:39 +00:00
|
|
|
},
|
|
|
|
setsocket: function(socket) {
|
2016-04-13 09:01:28 +00:00
|
|
|
this.socket = socket;
|
|
|
|
return this;
|
|
|
|
|
2016-04-25 09:35:39 +00:00
|
|
|
},
|
|
|
|
subscribe: function(socket) {
|
2016-04-13 09:01:28 +00:00
|
|
|
|
2016-04-25 09:35:39 +00:00
|
|
|
this.socket.subscribe('Lighting','LightingDataReceived');
|
|
|
|
},
|
|
|
|
doLightsOn: function(id) {
|
|
|
|
doLightsOn(id);
|
|
|
|
},
|
2016-04-27 10:17:11 +00:00
|
|
|
doLightsOff: function(id) {
|
|
|
|
doLightsOff(id);
|
|
|
|
}
|
2016-04-25 09:35:39 +00:00
|
|
|
};
|