Now controls the fan
This commit is contained in:
parent
14b32f2819
commit
da39b810b6
@ -1,12 +1,38 @@
|
|||||||
var mqtt = require('mqtt');
|
var mqtt = require('mqtt');
|
||||||
|
var request = require('request');
|
||||||
|
|
||||||
var mqttClient = function() {
|
var mqttClient = function() {
|
||||||
|
|
||||||
var orgId = '';
|
var orgId = '';
|
||||||
var userName = '';
|
var userName = '';
|
||||||
var appKey = 'bob';
|
var appKey = 'bob';
|
||||||
|
this.livingRoom = {
|
||||||
|
temp: 0,
|
||||||
|
last: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.fanTimer = function() {
|
||||||
|
'use strict';
|
||||||
|
var now = new Date;
|
||||||
|
var mod = 300000 - (now.getTime() % 300000);
|
||||||
|
|
||||||
|
var mode = (this.livingRoom.temp > 22.0) ? 'FanOn' : 'FanOff';
|
||||||
|
var url = ['https://maker.ifttt.com/trigger/',mode,'/with/key/cWvECkeiyAPwmiOPBkXL2D'].join('');
|
||||||
|
|
||||||
|
|
||||||
|
console.log('LR temp:', this.livingRoom.temp);
|
||||||
|
|
||||||
|
request(url, function(error, response, body) {
|
||||||
|
if (!error && response.statusCode === 200) {
|
||||||
|
console.log(body);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setTimeout(this.fanTimer.bind(this),mod + 10);
|
||||||
|
};
|
||||||
|
|
||||||
this.lighting = 'lights';
|
this.lighting = 'lights';
|
||||||
|
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
@ -24,16 +50,25 @@ var mqttClient = function() {
|
|||||||
this.client.on('connect', function() {
|
this.client.on('connect', function() {
|
||||||
connected = true;
|
connected = true;
|
||||||
console.log('Connected to SIlvr Broker');
|
console.log('Connected to SIlvr Broker');
|
||||||
});
|
this.fanTimer();
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
this.client.subscribe('lightsOut');
|
this.client.subscribe('livingroomTemp');
|
||||||
this.client.on('message', function(topic, message) {
|
this.client.on('message', function(topic, message) {
|
||||||
console.log(message);
|
|
||||||
});
|
var json = JSON.parse(message.toString());
|
||||||
|
console.log(json);
|
||||||
|
console.log(json.temp);
|
||||||
|
|
||||||
|
this.livingRoom.temp = json.temp;
|
||||||
|
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
this.isConnected = function() {
|
this.isConnected = function() {
|
||||||
return this.connected;
|
return this.connected;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user