Skip to content
Permalink
Browse files
minor chnages
  • Loading branch information
kailad committed Oct 30, 2019
1 parent 43c2e46 commit 66009468df1146c3e395047fcd16550b88642d32
Showing 1 changed file with 10 additions and 12 deletions.
@@ -11,8 +11,8 @@ const router = Router();
const port = 9001


var LightOnOff = 'false';
var LightConnected = 'false';
var LightOnOff = false;
var LightConnected = false;

render(app, {
root: path.join(__dirname, 'views'),
@@ -44,15 +44,14 @@ const wss = new WebSocket.Server({
// should not be compressed.
}
});
const connection = new WebSocket('ws://localhost:3000')

router.post('/ExteriorLightOnOff', onoff);

router.get('/Lights', async ctx =>{
await ctx.render('lights');
if (LightConnected == "false"){
lightConnected = 'true';
const connection = new WebSocket('ws://localhost:3000')
if (LightConnected == false){
LightConnected = true;
const connection = new WebSocket('ws://localhost:3000')
wss.on('connection', function connection(ws) {
const client = mqtt.connect('mqtt.coventry.ac.uk', {
host: 'mqtt.coventry.ac.uk',
@@ -76,6 +75,7 @@ await ctx.render('lights');
})

async function onoff(ctx) {
const connection = new WebSocket('ws://localhost:3000')
wss.on('connection', function connection(ws) {
const client = mqtt.connect('mqtt.coventry.ac.uk', {
host: 'mqtt.coventry.ac.uk',
@@ -85,24 +85,22 @@ async function onoff(ctx) {
port: 8883,
})

if (LightOnOff == 'false'){
if (LightOnOff == false){
client.on('connect', function () {
client.subscribe('302CEM/Team2/kailad', function (err) {
if (!err){
LightOnOff = 'true';
LightOnOff = true;
client.publish('302CEM/Team2/kailad', 'Turn on the Exterior Light')
client.end()
}
})
})
}
else if (LightOnOff == 'true'){
else if (LightOnOff == true){
client.on('connect', function () {
client.subscribe('302CEM/Team2/kailad', function (err) {
if (!err){
LightOnOff = 'false';
LightOnOff = false;
client.publish('302CEM/Team2/kailad', 'Turn off the Exterior Light')
client.end()
}
})
})

0 comments on commit 6600946

Please sign in to comment.