Added MQTT

This commit is contained in:
Tim Windelschmidt 2016-11-28 11:15:23 +01:00
parent 0edaff16c8
commit ddf4b6e8bd
2 changed files with 20 additions and 0 deletions

View File

@ -12,6 +12,7 @@
"express": "4.13.3",
"jade": "1.11.0",
"moment": "2.11.0",
"mqtt": "2.1.3",
"net-snmp": "1.1.14",
"path": "0.12.7",
"redis": "2.4.2",

View File

@ -11,6 +11,7 @@ var IpPoll = require("./ip-poll");
var Flukso = require("./flukso");
var routes = require("./routes");
var path = require('path');
var mqttClient = require('mqtt');
var spaceanswer = {
api: "0.13",
@ -70,6 +71,8 @@ var usercountanswer = {at: 0, current_value: 0, datapoints: [
var snmpMac = new SnmpMac("juni.ctdo.de", "ctdo23");
var ippoll = new IpPoll("flipdot.raum.ctdo.de", "195.160.169.30-120");
var flukso = new Flukso("flukso.raum.ctdo.de", "/sensor/cf00e0b22230f4a8870af58f2b8719dd");
var mqtt = mqttClient.connect('mqtt://raum.ctdo.de');
var connected = false;
var port = '9911';
var address = 'localhost';
@ -103,9 +106,25 @@ flukso.on('failed', function (error) {
console.log("Flukso: " + error);
});
mqtt.on('connect', function() {
console.log("connected to mqtt");
mqtt.subscribe('raumstatus/simple');
});
mqtt.on('message', function (topic, message) {
if(topic === 'raumstatus/simple') {
connected = (message.toString() === 'true');
}
});
function sendSimple () {
mqtt.publish('raumstatus/simple', JSON.stringify(simpleanswer));
}
function work() {
snmpMac.poll();
ippoll.pollCount();
sendSimple();
}
setInterval(work, 60000);