added justgage for display of power consumption
added power consumption in spaceapi
This commit is contained in:
parent
156616ebcf
commit
0dd746c47f
34
node/bla
34
node/bla
|
@ -1,34 +0,0 @@
|
|||
member: cn=tidirium,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=tatonka,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=ulihd,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=nospoonuser,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=progamler,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=zeus,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=lichtscheu,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=stefan,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=wegginho,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=jcoder,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=smash,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=pascal,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=herbern,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=syn,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=seppo,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=blueberry,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=immo,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=freakfairy,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=badboy,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=alteisen,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=eimann,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=downhill,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=annett,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=dukat,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=klapauzius,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=hotte,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=henne,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=tunix,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=fiurin,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=jsilence,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=kuro,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=klara,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
member: cn=lucas,ou=people,dc=chaostreff-dortmund,dc=de
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
var redis = require("redis");
|
||||
var util = require('util');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var http = require("http");
|
||||
|
||||
var redisprefix = "flukso:";
|
||||
|
||||
var Flukso = function(hostname, pathname) {
|
||||
var self = this;
|
||||
|
||||
var redisClient = redis.createClient();
|
||||
var regexp = /([0-9]+)\]\]$/; // /\(([0-9]+) hosts* up\)/;
|
||||
|
||||
|
||||
redisClient.on("connect", function () {
|
||||
console.log("connected to redis");
|
||||
self.emit('ready');
|
||||
});
|
||||
|
||||
this.pollPower = function() {
|
||||
|
||||
http.request({ host: hostname, path: pathname }, function(response) {
|
||||
var str = '';
|
||||
|
||||
response.on('data', function(chunk) {
|
||||
str += chunk;
|
||||
});
|
||||
|
||||
response.on('end', function () {
|
||||
// console.log("http received: " + str);
|
||||
|
||||
var matches = regexp.exec(str);
|
||||
if(matches != null && matches.length == 2) {
|
||||
var time = Date.now();
|
||||
|
||||
redisClient.zremrangebyscore(redisprefix + 'power', "-inf", time - 7*24*60*1000);
|
||||
|
||||
var num = matches[1];
|
||||
|
||||
redisClient.zadd(redisprefix + 'power', time, time + "|" + num, function() {
|
||||
self.emit('done', parseInt(num));
|
||||
});
|
||||
}
|
||||
});
|
||||
}).end();
|
||||
};
|
||||
|
||||
// this.getHistory = function(start, end, callback) {
|
||||
//
|
||||
// redisClient.zrangebyscore(redisprefix + 'power', start, end, function(err, replies) {
|
||||
// var data = [];
|
||||
//
|
||||
// replies.forEach(function (reply, i) {
|
||||
// var line = reply.split('|');
|
||||
// data.push( { at: moment(parseInt(line[0])).format(), value: line[1] });
|
||||
// });
|
||||
//
|
||||
// callback(data);
|
||||
// });
|
||||
// };
|
||||
};
|
||||
|
||||
util.inherits(Flukso, EventEmitter);
|
||||
|
||||
module.exports = Flukso;
|
|
@ -10,7 +10,7 @@ var IpPoll = function(switchaddr, hostsaddr) {
|
|||
|
||||
var redisClient = redis.createClient();
|
||||
var regexp = /\(([0-9]+) hosts* up\)/;
|
||||
var nmap = "nmap -n -sP -T4 ";
|
||||
var nmap = "nmap -n -sP -T3 ";
|
||||
|
||||
redisClient.on("connect", function () {
|
||||
console.log("connected to redis");
|
||||
|
@ -24,12 +24,12 @@ var IpPoll = function(switchaddr, hostsaddr) {
|
|||
if(matches != null && matches.length == 2) {
|
||||
var time = Date.now();
|
||||
|
||||
redisClient.zremrangebyscore('onlinecount', "-inf", time - 7*24*60*1000);
|
||||
redisClient.zremrangebyscore(redisprefix + 'onlinecount', "-inf", time - 7*24*60*1000);
|
||||
|
||||
var num = matches[1];
|
||||
|
||||
redisClient.zadd('onlinecount', time, time + "|" + num, function() {
|
||||
self.emit('doneCount', num);
|
||||
redisClient.zadd(redisprefix + 'onlinecount', time, time + "|" + num, function() {
|
||||
self.emit('doneCount', parseInt(num));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ var IpPoll = function(switchaddr, hostsaddr) {
|
|||
|
||||
this.getHistory = function(start, end, callback) {
|
||||
|
||||
redisClient.zrangebyscore('onlinecount', "-inf", "+inf", function(err, replies) {
|
||||
redisClient.zrangebyscore(redisprefix + 'onlinecount', "-inf", "+inf", function(err, replies) {
|
||||
var data = [];
|
||||
|
||||
replies.forEach(function (reply, i) {
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
body {
|
||||
margin: 20px 0 0 0;
|
||||
}
|
||||
|
||||
.intro {
|
||||
margin: 10px 0 40px 0;
|
||||
}
|
||||
|
||||
.status-icon {
|
||||
width: 128px;
|
||||
height: 128px;
|
||||
|
@ -28,3 +36,10 @@ h2 {
|
|||
height: 200px;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
#gauge {
|
||||
width: 290px;
|
||||
height: 200px;
|
||||
display: inline-block;
|
||||
margin: 0;
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
var gpower;
|
||||
|
||||
angular.module('roomstateapp.controllers', []).
|
||||
controller('StatusCtrl', function ($scope, $http, Socket) {
|
||||
|
||||
|
@ -9,6 +11,7 @@ angular.module('roomstateapp.controllers', []).
|
|||
}).
|
||||
success(function (data, status, headers, config) {
|
||||
$scope.simple = data;
|
||||
gpower.refresh(message.data.power);
|
||||
}).
|
||||
error(function (data, status, headers, config) {
|
||||
//$scope.name = 'Error!'
|
||||
|
@ -18,6 +21,7 @@ angular.module('roomstateapp.controllers', []).
|
|||
Socket.on('sdata', function(message) {
|
||||
console.log("received data from server: " + message.data.names);
|
||||
$scope.simple = message.data;
|
||||
gpower.refresh(message.data.power);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -64,4 +68,15 @@ angular.module('roomstateapp.statusfilter', []).filter('statustostring', functio
|
|||
angular.module('roomstateapp', ['roomstateapp.controllers', 'roomstateapp.services', 'roomstateapp.statusfilter']);
|
||||
|
||||
|
||||
$( document ).ready(function() {
|
||||
console.log( "ready!" );
|
||||
|
||||
gpower = new JustGage({
|
||||
id: "gauge",
|
||||
value: 0,
|
||||
min: 0,
|
||||
max: 15000,
|
||||
title: "Power"
|
||||
});
|
||||
|
||||
});
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -6,6 +6,7 @@ var flash = require('connect-flash');
|
|||
var moment = require('moment');
|
||||
var SnmpMac = require("./snmp-mac");
|
||||
var IpPoll = require("./ip-poll");
|
||||
var Flukso = require("./flukso");
|
||||
var routes = require("./routes");
|
||||
var path = require('path');
|
||||
|
||||
|
@ -33,14 +34,29 @@ var spaceanswer = {
|
|||
issue_report_channels: [ "issue_mail" ],
|
||||
state: {
|
||||
open: null,
|
||||
lastchange: 0
|
||||
lastchange: 0,
|
||||
icon: {
|
||||
open: "http://status.ctdo.de/img/green.png",
|
||||
closed: "http://status.ctdo.de/img/red.png"
|
||||
}
|
||||
},
|
||||
sensors: {
|
||||
power_consumption: [ {
|
||||
unit: "W",
|
||||
name: "mains power",
|
||||
description: "overall power consumption from our space",
|
||||
location: "basement",
|
||||
value: 0 } ]
|
||||
}
|
||||
};
|
||||
var simpleanswer = { state: "unknown", count: 0, names: [], lastchange: 0 };
|
||||
var usercountanswer = { at: 0, current_value: 0, datapoints: [ { at : 0, value: 0 } ]};
|
||||
var simpleanswer = { state: "unknown", count: 0, names: [], lastchange: 0, power: 0 };
|
||||
var usercountanswer = { at: 0, current_value: 0, datapoints: [
|
||||
{ at: 0, value: 0 }
|
||||
]};
|
||||
|
||||
var snmpMac = new SnmpMac("juni.ctdo.de", "ctdo23");
|
||||
var ippoll = new IpPoll("switch2.raum.ctdo.de", "195.160.169.20-62 195.160.169.70-126");
|
||||
var flukso = new Flukso("flukso.raum.ctdo.de", "/sensor/cf00e0b22230f4a8870af58f2b8719dd");
|
||||
|
||||
snmpMac.on('done', function (res) {
|
||||
simpleanswer.names = res;
|
||||
|
@ -61,6 +77,12 @@ ippoll.on('doneState', function (state) {
|
|||
io.sockets.emit('sdata', { data: simpleanswer });
|
||||
});
|
||||
|
||||
flukso.on('done', function (num) {
|
||||
simpleanswer.power = num;
|
||||
spaceanswer.sensors.power_consumption[0].value = num;
|
||||
io.sockets.emit('sdata', { data: simpleanswer });
|
||||
});
|
||||
|
||||
io.configure(function () {
|
||||
io.set('log level', 0);
|
||||
});
|
||||
|
@ -69,17 +91,14 @@ io.configure(function () {
|
|||
function work() {
|
||||
snmpMac.poll();
|
||||
ippoll.pollCount();
|
||||
|
||||
// simpleanswer.names.length = 0;
|
||||
// for(var i=0;i<4+Math.random() * 100;i++) {
|
||||
// simpleanswer.names.push("nickname"+i);
|
||||
// }
|
||||
// io.sockets.emit('sdata', { "data": simpleanswer }); // TODO: enable data simulation in dev env
|
||||
}
|
||||
|
||||
setInterval(work, 60000); // TODO: make 60s in prod and 10s in dev env
|
||||
setInterval(work, 60000);
|
||||
work();
|
||||
|
||||
setInterval(flukso.pollPower, 5000);
|
||||
flukso.pollPower();
|
||||
|
||||
app.set('snmpMac', snmpMac); //TODO: wie kann man das schoener machen? (Modul in die Routes reintun)
|
||||
app.set('views', __dirname + '/views');
|
||||
app.set('view engine', 'jade');
|
||||
|
@ -97,12 +116,19 @@ app.use(flash());
|
|||
|
||||
|
||||
app.get('/api/spaceapi/v13', function (req, res) {
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
res.setHeader("Cache-Control", "no-cache");
|
||||
res.send(spaceanswer);
|
||||
});
|
||||
app.get('/api/simple/v2', function (req, res) {
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
res.setHeader("Cache-Control", "no-cache");
|
||||
res.send(simpleanswer);
|
||||
});
|
||||
app.get('/api/usercount', function (req, res) {
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
res.setHeader("Cache-Control", "no-cache");
|
||||
|
||||
//TODO: respect query params "start", "end", "interval" (s) and "limit" (like Xively)
|
||||
// maybe skip "interval" if code gets too complex :)
|
||||
|
||||
|
@ -116,6 +142,9 @@ app.get('/api/usercount', function (req, res) {
|
|||
|
||||
});
|
||||
app.get('/api/simple/image', function (req, res) {
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
res.setHeader("Cache-Control", "no-cache");
|
||||
|
||||
if (spaceanswer.state.open == true) {
|
||||
res.sendfile(path.resolve(__dirname, 'public/img/green.png'));
|
||||
} else if (spaceanswer.state.open == false) {
|
||||
|
@ -130,7 +159,7 @@ app.post('/form', routes.form);
|
|||
app.get('/', routes.index);
|
||||
|
||||
|
||||
server.listen(3000, 'localhost');
|
||||
server.listen(3000, '0.0.0.0');
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ block content
|
|||
|
||||
.ink-grid(ng-controller='StatusCtrl')
|
||||
.column-group.gutters
|
||||
.large-20.small-100
|
||||
.large-20.medium-20.small-100
|
||||
|
||||
|
||||
div(class="status-icon status-icon-{{simple.state}}")
|
||||
|
@ -21,7 +21,7 @@ block content
|
|||
|
||||
|
||||
|
||||
.large-80.small-100
|
||||
.large-50.medium-80.small-100
|
||||
h2 Anzahl Geräte:
|
||||
|
||||
#graph
|
||||
|
@ -36,9 +36,18 @@ block content
|
|||
span(ng-show=" ! $last ")
|
||||
| , <!-- -->
|
||||
|
||||
.large-30.medium-100.small-100
|
||||
h2 Energieverbrauch
|
||||
|
||||
#gauge.power
|
||||
|
||||
|
||||
|
||||
block scripts
|
||||
script(type="text/javascript",src="/js/vendor/d3.min.js")
|
||||
script(type="text/javascript",src="/js/vendor/d3.layout.min.js")
|
||||
script(type="text/javascript",src="/js/vendor/rickshaw.min.js")
|
||||
script(type="text/javascript",src="/js/vendor/moment.min.js")
|
||||
script(type="text/javascript",src="/js/graph.js")
|
||||
script(type="text/javascript",src="/js/vendor/raphael.2.1.0.min.js")
|
||||
script(type="text/javascript",src="/js/vendor/justgage.1.0.1.min.js")
|
||||
|
|
|
@ -11,6 +11,7 @@ html(ng-app="roomstateapp")
|
|||
link(rel='stylesheet', href='/css/ink-min.css')
|
||||
link(rel='stylesheet', href='/css/rickshaw.min.css')
|
||||
link(rel='stylesheet', href='/css/style.css')
|
||||
meta(name="viewport", content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0")
|
||||
body
|
||||
|
||||
.ink-grid
|
||||
|
@ -18,6 +19,13 @@ html(ng-app="roomstateapp")
|
|||
header
|
||||
h1 chaostreff status
|
||||
|
||||
.intro
|
||||
p
|
||||
| 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.
|
||||
|
||||
.main-content
|
||||
block content
|
||||
|
||||
|
|
Loading…
Reference in New Issue