Compare commits
No commits in common. "ddadd0e4e6a81ac43e32de36a9a90aa7ad2d341b" and "f6610cf7a2b6a48378b1b716044353b1d4cd4c3d" have entirely different histories.
ddadd0e4e6
...
f6610cf7a2
|
@ -0,0 +1,22 @@
|
||||||
|
var util = require('util');
|
||||||
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
var request = require('request');
|
||||||
|
|
||||||
|
var CTDOApi= function(url) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
this.poll = function() {
|
||||||
|
request({url: "https://" + url}, function(error, res, response) {
|
||||||
|
if (error) {
|
||||||
|
self.emit('failed', error)
|
||||||
|
} else {
|
||||||
|
var parsedResponse = JSON.parse(response);
|
||||||
|
|
||||||
|
self.emit('done', parsedResponse);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
util.inherits(CTDOApi, EventEmitter);
|
||||||
|
module.exports = CTDOApi;
|
36
statusbot.js
36
statusbot.js
|
@ -8,6 +8,7 @@ var cookieSession = require('cookie-session');
|
||||||
var flash = require('connect-flash');
|
var flash = require('connect-flash');
|
||||||
var Flukso = require("./flukso");
|
var Flukso = require("./flukso");
|
||||||
var IpPoll = require("./ip-poll");
|
var IpPoll = require("./ip-poll");
|
||||||
|
var CTDOApi = require("./ctdo-api");
|
||||||
var routes = require("./routes");
|
var routes = require("./routes");
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var mqttClient = require('mqtt');
|
var mqttClient = require('mqtt');
|
||||||
|
@ -60,13 +61,20 @@ var spaceanswer = {
|
||||||
description: "overall power consumption from our space",
|
description: "overall power consumption from our space",
|
||||||
location: "basement",
|
location: "basement",
|
||||||
value: 0
|
value: 0
|
||||||
}]
|
}],
|
||||||
|
people_now_present: [{
|
||||||
|
value: 0,
|
||||||
|
names: []
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var simpleanswer = {state: "unknown", lastchange: 0, power: 0};
|
var simpleanswer = {state: "unknown", count: 0, names: [], lastchange: 0, power: 0};
|
||||||
|
var usercountanswer = {
|
||||||
|
at: 0, current_value: 0, datapoints: []
|
||||||
|
};
|
||||||
|
|
||||||
var ippoll = new IpPoll("rpi3.raum.ctdo.de");
|
var ippoll = new IpPoll("rpi3.raum.ctdo.de");
|
||||||
|
var ctdoapi = new CTDOApi("api.ctdo.de/names.php");
|
||||||
var flukso = new Flukso("flukso.raum.ctdo.de", "/sensor/cf00e0b22230f4a8870af58f2b8719dd");
|
var flukso = new Flukso("flukso.raum.ctdo.de", "/sensor/cf00e0b22230f4a8870af58f2b8719dd");
|
||||||
var mqtt = mqttClient.connect('mqtt://raum.ctdo.de');
|
var mqtt = mqttClient.connect('mqtt://raum.ctdo.de');
|
||||||
var connected = false;
|
var connected = false;
|
||||||
|
@ -74,6 +82,19 @@ var connected = false;
|
||||||
var port = '9911';
|
var port = '9911';
|
||||||
var address = 'localhost';
|
var address = 'localhost';
|
||||||
|
|
||||||
|
ctdoapi.on('done', function (answer) {
|
||||||
|
simpleanswer.count = answer.count;
|
||||||
|
simpleanswer.names = answer.names;
|
||||||
|
|
||||||
|
spaceanswer.sensors.people_now_present[0].value = answer.count;
|
||||||
|
spaceanswer.sensors.people_now_present[0].names = answer.names;
|
||||||
|
|
||||||
|
if (usercountanswer.datapoints.length > 20) {
|
||||||
|
usercountanswer.datapoints.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
usercountanswer.datapoints.push({at: new Date().getTime(), value: simpleanswer.count});
|
||||||
|
});
|
||||||
|
|
||||||
ippoll.on('doneState', function (state) {
|
ippoll.on('doneState', function (state) {
|
||||||
spaceanswer.state.open = state;
|
spaceanswer.state.open = state;
|
||||||
|
@ -110,6 +131,7 @@ function sendSimple() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function work() {
|
function work() {
|
||||||
|
ctdoapi.poll();
|
||||||
ippoll.pollState();
|
ippoll.pollState();
|
||||||
sendSimple();
|
sendSimple();
|
||||||
}
|
}
|
||||||
|
@ -144,6 +166,11 @@ app.get('/api/simple/v2', function (req, res) {
|
||||||
res.send(simpleanswer);
|
res.send(simpleanswer);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/api/usercount', function (req, res) {
|
||||||
|
usercountanswer.at = simpleanswer.lastchange;
|
||||||
|
usercountanswer.current_value = simpleanswer.count;
|
||||||
|
res.send(usercountanswer);
|
||||||
|
});
|
||||||
|
|
||||||
function getstatusImage(req, res) {
|
function getstatusImage(req, res) {
|
||||||
if (spaceanswer.state.open == true) {
|
if (spaceanswer.state.open == true) {
|
||||||
|
@ -163,7 +190,8 @@ app.get('/api/simple/image.png', function (req, res) {
|
||||||
getstatusImage(req, res);
|
getstatusImage(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//app.get('/db', routes.db);
|
||||||
|
//app.post('/form', routes.form);
|
||||||
app.get('/', routes.index);
|
app.get('/', routes.index);
|
||||||
|
|
||||||
var server = server.listen(port, address, function (err) {
|
var server = server.listen(port, address, function (err) {
|
||||||
|
|
|
@ -7,7 +7,8 @@ block content
|
||||||
| Hier siehst du den aktuellen Status von uns. Die Daten werden vom Router und unserem Flukso
|
| Hier siehst du den aktuellen Status von uns. Die Daten werden vom Router und unserem Flukso
|
||||||
| eingesammelt. Die Anzahl der Geräte und der Status selber werden Minütlich abgefragt. Unseren
|
| eingesammelt. Die Anzahl der Geräte und der Status selber werden Minütlich abgefragt. Unseren
|
||||||
| Energieverbrauch bekommst du alle fünf Sekunden neu. Den Status "geöffnet" oder "geschlossen"
|
| Energieverbrauch bekommst du alle fünf Sekunden neu. Den Status "geöffnet" oder "geschlossen"
|
||||||
| bestimmt das Programm mit einem ping auf ein Gerät im Raum.
|
| bestimmt das Programm mit einem ping auf den Switch im Raum. Mit dem Knopf unter dem Stromverbrauch
|
||||||
|
| kannst du einschalten, dass du eine Benachrichtigung bei einer Änderung bekommst. Der Tab muss dafür offen bleiben.
|
||||||
|
|
||||||
.ink-grid(ng-controller='StatusCtrl')
|
.ink-grid(ng-controller='StatusCtrl')
|
||||||
.column-group.gutters
|
.column-group.gutters
|
||||||
|
@ -24,11 +25,27 @@ block content
|
||||||
dd {{simple.lastchange | date:'dd.MM.yyyy HH:mm:ss'}}
|
dd {{simple.lastchange | date:'dd.MM.yyyy HH:mm:ss'}}
|
||||||
|
|
||||||
|
|
||||||
|
dt aktive Geräte:
|
||||||
|
dd {{simple.count}}
|
||||||
|
|
||||||
|
.large-50.medium-80.small-100
|
||||||
|
h2 Anzahl Geräte im LAN:
|
||||||
|
|
||||||
|
#graph
|
||||||
|
|
||||||
|
h2 Personen anwesend:
|
||||||
|
|
||||||
|
span(ng-repeat="name in simple.names")
|
||||||
|
| {{name}}
|
||||||
|
|
||||||
|
span(ng-show=" ! $last ")
|
||||||
|
| , <!-- -->
|
||||||
|
|
||||||
.large-30.medium-100.small-100
|
.large-30.medium-100.small-100
|
||||||
h2 Energieverbrauch
|
h2 Energieverbrauch
|
||||||
|
|
||||||
#gauge.power
|
#gauge.power
|
||||||
|
button(type="button", onclick="toggle();", class="btn btn-block btn-danger", id="notificationButton") Statusbenachrichtigungen aus
|
||||||
|
|
||||||
|
|
||||||
block scripts
|
block scripts
|
||||||
|
|
|
@ -17,7 +17,7 @@ html(ng-app="roomstateapp")
|
||||||
.ink-grid
|
.ink-grid
|
||||||
|
|
||||||
header
|
header
|
||||||
h1 Chaostreff Dortmund Raumstatus
|
h1 chaostreff status
|
||||||
|
|
||||||
.main-content
|
.main-content
|
||||||
block content
|
block content
|
||||||
|
|
Loading…
Reference in New Issue