revert from es6
This commit is contained in:
parent
65bc6987d4
commit
59fb466313
@ -1,4 +1,7 @@
|
||||
import mqtt from 'mqtt';
|
||||
'use strict';
|
||||
const mqtt = require('mqtt');
|
||||
const request = require('request');
|
||||
let util = require('util');
|
||||
const logger = require('log4js').getLogger();
|
||||
|
||||
// Var db = require('../server/db-connector').dbConnection;
|
||||
@ -34,7 +37,7 @@ const mqttClient = function(events) {
|
||||
const d = new Date();
|
||||
this.lastMsg = d.getTime();
|
||||
|
||||
events.on('sendIFTTT', mode => {
|
||||
events.on('sendIFTTT', function(mode) {
|
||||
let d;
|
||||
const url = ['https://maker.ifttt.com/trigger/', mode, '/with/key/cWvECkeiyAPwmiOPBkXL2D'].join('');
|
||||
|
||||
@ -135,24 +138,24 @@ const mqttClient = function(events) {
|
||||
|
||||
const options = {
|
||||
keepalive: 3600,
|
||||
clientId: `a:${orgId}:${Date.now()}`,
|
||||
clientId: 'a:' + orgId + ':' + Date.now(),
|
||||
username: userName,
|
||||
password: new Buffer(appKey)
|
||||
|
||||
};
|
||||
|
||||
this.client = mqtt.connect(`mqtt://${orgId}silvrtree.co.uk`, options);
|
||||
this.client = mqtt.connect('mqtt://' + orgId + 'silvrtree.co.uk', options);
|
||||
|
||||
this.client.on('connect', () => {
|
||||
this.client.on('connect', function() {
|
||||
this.connected = true;
|
||||
logger.info('Connected to Silvr Broker');
|
||||
this.fanTimer();
|
||||
this.logTemp();
|
||||
});
|
||||
}.bind(this));
|
||||
|
||||
this.client.subscribe('livingroomTemp');
|
||||
|
||||
this.client.on('message', (topic, message) => {
|
||||
this.client.on('message', function(topic, message) {
|
||||
|
||||
const json = JSON.parse(message.toString());
|
||||
logger.debug(json);
|
||||
@ -171,7 +174,7 @@ const mqttClient = function(events) {
|
||||
const data = {id: 'temperature', data: {mode: globalMode, temp: this.livingRoom.temp}};
|
||||
events.emit('sendSocket', data);
|
||||
|
||||
});
|
||||
}.bind(this));
|
||||
|
||||
this.isConnected = function() {
|
||||
return this.connected;
|
||||
@ -179,4 +182,4 @@ const mqttClient = function(events) {
|
||||
|
||||
};
|
||||
|
||||
export {mqttClient};
|
||||
module.exports.mqttClient = mqttClient;
|
||||
|
Loading…
Reference in New Issue
Block a user