mirror of
https://gitlab.silvrtree.co.uk/martind2000/SODashServer.git
synced 2025-01-25 19:46:16 +00:00
76 lines
1.6 KiB
JavaScript
76 lines
1.6 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by Martin on 09/02/2016.
|
|
*/
|
|
|
|
/*var mqttConnect = require("../lib/mqtt/mqttConnect");
|
|
mqttConnect.doConnection();*/
|
|
|
|
var mqttConnect;
|
|
|
|
function doLightsOn(id) {
|
|
|
|
mqttConnect.doConnection().lightingOn(id);
|
|
}
|
|
|
|
function doLightsOff(id) {
|
|
|
|
mqttConnect.doConnection().lightingOff(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;
|
|
}
|
|
|
|
console.log(req.body.light);
|
|
|
|
if (req.body.hasOwnProperty('light'))
|
|
{
|
|
var light = req.body.light;
|
|
doLightsOff(light);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
console.log(req.body.light);
|
|
|
|
if (req.body.hasOwnProperty('light'))
|
|
{
|
|
var light = req.body.light;
|
|
doLightsOn(light);
|
|
}
|
|
|
|
res.setHeader('Content-Type', 'application/json');
|
|
res.end(JSON.stringify({}));
|
|
},
|
|
setsocket: function (socket) {
|
|
this.socket = socket;
|
|
return this;
|
|
|
|
},
|
|
subscribe: function (socket) {
|
|
|
|
this.socket.subscribe('LightingISP15','LightingDataReceived');
|
|
}
|
|
};
|