diff --git a/node/package.json b/node/package.json index 6e7df62..908c690 100644 --- a/node/package.json +++ b/node/package.json @@ -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", diff --git a/node/statusbot.js b/node/statusbot.js index 75c844a..d344d68 100755 --- a/node/statusbot.js +++ b/node/statusbot.js @@ -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);