Compare commits
3 Commits
f6610cf7a2
...
ddadd0e4e6
Author | SHA1 | Date |
---|---|---|
Lucas Pleß | ddadd0e4e6 | |
Lucas Pleß | 275b27448c | |
Lucas Pleß | 782d4a1a35 |
22
ctdo-api.js
22
ctdo-api.js
|
@ -1,22 +0,0 @@
|
|||
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;
|
34
statusbot.js
34
statusbot.js
|
@ -8,7 +8,6 @@ var cookieSession = require('cookie-session');
|
|||
var flash = require('connect-flash');
|
||||
var Flukso = require("./flukso");
|
||||
var IpPoll = require("./ip-poll");
|
||||
var CTDOApi = require("./ctdo-api");
|
||||
var routes = require("./routes");
|
||||
var path = require('path');
|
||||
var mqttClient = require('mqtt');
|
||||
|
@ -61,20 +60,13 @@ var spaceanswer = {
|
|||
description: "overall power consumption from our space",
|
||||
location: "basement",
|
||||
value: 0
|
||||
}],
|
||||
people_now_present: [{
|
||||
value: 0,
|
||||
names: []
|
||||
}]
|
||||
}
|
||||
};
|
||||
var simpleanswer = {state: "unknown", count: 0, names: [], lastchange: 0, power: 0};
|
||||
var usercountanswer = {
|
||||
at: 0, current_value: 0, datapoints: []
|
||||
};
|
||||
var simpleanswer = {state: "unknown", lastchange: 0, power: 0};
|
||||
|
||||
|
||||
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 mqtt = mqttClient.connect('mqtt://raum.ctdo.de');
|
||||
var connected = false;
|
||||
|
@ -82,19 +74,6 @@ var connected = false;
|
|||
var port = '9911';
|
||||
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) {
|
||||
spaceanswer.state.open = state;
|
||||
|
@ -131,7 +110,6 @@ function sendSimple() {
|
|||
}
|
||||
|
||||
function work() {
|
||||
ctdoapi.poll();
|
||||
ippoll.pollState();
|
||||
sendSimple();
|
||||
}
|
||||
|
@ -166,11 +144,6 @@ app.get('/api/simple/v2', function (req, res) {
|
|||
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) {
|
||||
if (spaceanswer.state.open == true) {
|
||||
|
@ -190,8 +163,7 @@ app.get('/api/simple/image.png', function (req, res) {
|
|||
getstatusImage(req, res);
|
||||
});
|
||||
|
||||
//app.get('/db', routes.db);
|
||||
//app.post('/form', routes.form);
|
||||
|
||||
app.get('/', routes.index);
|
||||
|
||||
var server = server.listen(port, address, function (err) {
|
||||
|
|
|
@ -7,8 +7,7 @@ block content
|
|||
| 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
|
||||
| Energieverbrauch bekommst du alle fünf Sekunden neu. Den Status "geöffnet" oder "geschlossen"
|
||||
| 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.
|
||||
| bestimmt das Programm mit einem ping auf ein Gerät im Raum.
|
||||
|
||||
.ink-grid(ng-controller='StatusCtrl')
|
||||
.column-group.gutters
|
||||
|
@ -25,27 +24,11 @@ block content
|
|||
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
|
||||
h2 Energieverbrauch
|
||||
|
||||
#gauge.power
|
||||
button(type="button", onclick="toggle();", class="btn btn-block btn-danger", id="notificationButton") Statusbenachrichtigungen aus
|
||||
|
||||
|
||||
block scripts
|
||||
|
|
|
@ -17,7 +17,7 @@ html(ng-app="roomstateapp")
|
|||
.ink-grid
|
||||
|
||||
header
|
||||
h1 chaostreff status
|
||||
h1 Chaostreff Dortmund Raumstatus
|
||||
|
||||
.main-content
|
||||
block content
|
||||
|
|
Loading…
Reference in New Issue