@@ -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