Skip to content

Commit 8340a3d

Browse files
committed
Moved cumulative data into own topics ready for generic cumulative data solution
1 parent a4127cd commit 8340a3d

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

mqtt/pages/sensors.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<title>
5-
Charlestown Power
5+
Charlestown Sensors
66
</title>
77
<link type="text/css" rel="stylesheet" href="/app.css" media="all">
88
</head>
@@ -11,9 +11,9 @@
1111
<span id="sensors/power/0"> </span>W
1212
</big></big></big>
1313
<P>
14-
<span id="sensors/power/0powercumulativeToday"></span> KWh used today
14+
<span id="sensors/power/0/cumulative/today"></span> KWh used today
1515
<br>
16-
<span id="sensors/power/0powercumulativeHour"></span> KWh this hour
16+
<span id="sensors/power/0/cumulative/hour"></span> KWh this hour
1717
<P>
1818
<canvas id="mycanvas" width="500" height="150"></canvas>
1919
<P>

mqtt/server-stats.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ mqttclient.on('connect', function() {
6060
redisClient.set("powercumulativeToday", powercumulativeToday);
6161
redisClient.set("powercumulativeHour", powercumulativeHour);
6262
// console.log("duration ", duration, "period ", powerused, "today ", powercumulativeToday, "hour ", powercumulativeHour);
63-
mqttclient.publish("sensors/power/0powercumulativeToday", powercumulativeToday.toFixed(2));
64-
mqttclient.publish("sensors/power/0powercumulativeHour", powercumulativeHour.toFixed(2));
63+
mqttclient.publish("sensors/power/0/cumulative/today", powercumulativeToday.toFixed(2));
64+
mqttclient.publish("sensors/power/0/cumulative/hour", powercumulativeHour.toFixed(2));
6565
powerlasttime = powercurrenttime;
6666
}
6767
});

mqtt/server.js

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,22 @@ var config = require('./config.json');
1313
// A whole load of very clumsy routing for static pages and js
1414
//
1515
// First of all log all connections
16-
app.use(function(req, res, next){
17-
console.log('one connection %j %s %s', req.connection.remoteAddress, req.method, req.url);
18-
next();
19-
});
20-
app.get('/smoothie.js', function (req, res) {
21-
res.sendfile(__dirname + '/pages/js/smoothie.js');
22-
});
23-
app.get('/jquery.min.js', function (req, res) {
24-
res.sendfile(__dirname + '/pages/js/jquery.min.js');
25-
});
26-
app.get('/app.css', function (req, res) {
27-
res.sendfile(__dirname + '/pages/app.css');
28-
});
29-
app.get('/sensors', function(req, res) {
30-
res.sendfile(__dirname + '/pages/sensors.html');
31-
});
32-
app.get('/mqtt', function(req, res) {
33-
res.sendfile(__dirname + '/pages/mqtt.html');
34-
});
35-
app.get('/mqttstats', function(req, res) {
36-
res.sendFile(__dirname + '/pages/mqttstats.html');
37-
});
38-
app.get('/stats', function(req, res){
16+
app.use(express.logger());
17+
app.use(express.compress());
18+
19+
app.get('/stats', function(req, res, next){
3920
console.log('This process is pid ' + process.pid + " with an uptime of " + process.uptime());
4021
console.log('Running on ' + process.platform + ' (' + process.arch + ')');
4122
});
4223

24+
app.use(express.static(__dirname + '/pages'));
25+
app.use(express.static(__dirname + '/pages/js'));
26+
27+
// and finally a 404
28+
app.use(function(req, res, next){
29+
res.send(404, 'Sorry cant find that!');
30+
});
31+
4332

4433

4534

@@ -58,6 +47,7 @@ io.of('/sensors').on('connection', function (socket) {
5847

5948
mqttclient.on('connect', function() {
6049
mqttclient.subscribe('sensors/+/+');
50+
mqttclient.subscribe('sensors/power/+/cumulative/+');
6151
// console.log('subscribing to sensors/+/+ on ' + config.mqtt.host + '(' + config.mqtt.port + ')');
6252

6353
mqttclient.on('message', function(topic, message) {

0 commit comments

Comments
 (0)