diff --git a/.gitignore b/.gitignore index 8ca11cb..f72ef17 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.out *.pid *.gz +*.off .idea .idea/ diff --git a/README.md b/README.md index ddbac05..544cbd5 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Aquastream XT application for Linux ## Introduction This is a Node.js application for displaying Aquastream XT pump information, such as water temperature, flow, current frequency, etc. -It is built on top of [node-aquastreamxt-api](node-aquastreamxt-api), which is a native Node.js addon I wrote for communicating with the hardware. +It is built on top of [node-aquastreamxt-api](https://github.com/adick/node-aquastreamxt-api), which is a native Node.js addon I wrote for communicating with the hardware. Currently it is *read-only*, so you can't change any settings yet. I still have some problems with writing data to the device but this is planned to be supported some day. @@ -31,7 +31,7 @@ This guide is for Debian based distros (Debian, Ubuntu. LMDE/Mint, ...) so you m $ npm install -This installs all required dependencies (including [node-aquastreamxt-api](node-aquastreamxt-api)). +This installs all required dependencies (including [node-aquastreamxt-api](https://github.com/adick/node-aquastreamxt-api)). ### Done! @@ -41,7 +41,7 @@ Run the app with and visit [http://localhost:8080](http://localhost:8080) - you should see the interface: -![screenshot](https://github.com/adick/node-aquastreamxt/master/screenshot.png) +![screenshot](https://raw.githubusercontent.com/adick/node-aquastreamxt/master/screenshot.png) ## Troubleshooting diff --git a/app.js b/app.js index c354a52..6843a4c 100644 --- a/app.js +++ b/app.js @@ -9,10 +9,10 @@ conf = require('nconf'); fs = require('fs'); var express = require('express'), - http = require('http'), - socketio = require('socket.io'), - routes = require('./routes'), - path = require('path'); + http = require('http'), + socketio = require('socket.io'), + routes = require('./routes'), + path = require('path'); // Load config file conf.file({file: 'config.json'}); diff --git a/public/js/frontend.js b/public/js/frontend.js index f3a9534..fa4a763 100644 --- a/public/js/frontend.js +++ b/public/js/frontend.js @@ -5,44 +5,44 @@ * @author Alexander Dick */ -jQuery(function() { +jQuery(function () { /** * Register Handlebars Helpers */ - for(var h in Helper.Handlebars) + for (var h in Helper.Handlebars) Handlebars.registerHelper(h, Helper.Handlebars[h]); /** * Pump data and info tables */ - var pumpDataTemplate = - '

Current values

\ - \ - \ - \ - \ - \ - \ -
Frequency{{frequency}} Hz
Max. Frequency{{frequencyMax}} Hz
Power Consumption{{pumpCurrent}} mA
Power{{round pumpPower}} W
Voltage{{round voltage}} V
'; - - pumpDataTemplate = Handlebars.compile(pumpDataTemplate); - - var pumpInfoTemplate = - '

Hardware

\ - \ - \ - \ - \ - \ - \ -
Pump Mode{{pumpMode mode}}
Firmware{{hardware.firmware}}
Hardware{{hardware.hardware}}
Serial{{hardware.serial}}
Public Key{{join hardware.publicKey}}
'; - - - pumpInfoTemplate = Handlebars.compile(pumpInfoTemplate); - var pumpInfoHtml = pumpInfoTemplate(pumpData); - jQuery('#pump-info').html(pumpInfoHtml); + var pumpDataTemplate = + '

Current values

\ + \ + \ + \ + \ + \ + \ +
Frequency{{frequency}} Hz
Max. Frequency{{frequencyMax}} Hz
Power Consumption{{pumpCurrent}} mA
Power{{round pumpPower}} W
Voltage{{round voltage}} V
'; + + pumpDataTemplate = Handlebars.compile(pumpDataTemplate); + + var pumpInfoTemplate = + '

Hardware

\ + \ + \ + \ + \ + \ + \ +
Pump Mode{{pumpMode mode}}
Firmware{{hardware.firmware}}
Hardware{{hardware.hardware}}
Serial{{hardware.serial}}
Public Key{{join hardware.publicKey}}
'; + + + pumpInfoTemplate = Handlebars.compile(pumpInfoTemplate); + var pumpInfoHtml = pumpInfoTemplate(pumpData); + jQuery('#pump-info').html(pumpInfoHtml); var pumpSettingsTemplate = '

Settings

\ @@ -51,7 +51,6 @@ jQuery(function() { Deaeration mode{{deaerationMode pumpMode}}\ '; - pumpSettingsTemplate = Handlebars.compile(pumpSettingsTemplate); var pumpSettingsHtml = pumpSettingsTemplate(pumpSettings); jQuery('#pump-settings').html(pumpSettingsHtml); @@ -60,20 +59,20 @@ jQuery(function() { /** * Save Flow Sensor settings on change */ - jQuery('#impulses-per-liter').on('change', function() { + jQuery('#impulses-per-liter').on('change', function () { jQuery.post('/config', { key: 'aquastreamXt:flowSensor:impulsesPerLiter', value: this.value - }, function(conf) { + }, function (conf) { // overwrite config with updated values window.config = conf; }, 'json'); }); - jQuery('#measuring-impulses').on('change', function() { + jQuery('#measuring-impulses').on('change', function () { jQuery.post('/config', { key: 'aquastreamXt:flowSensor:measuringImpulses', value: this.value - }, function(conf) { + }, function (conf) { // overwrite config with updated values window.config = conf; }, 'json'); @@ -112,9 +111,9 @@ jQuery(function() { } }, tooltip: { - formatter: function() { - return ''+ this.series.name +'
'+ - Highcharts.dateFormat('%d.%m.%Y %H:%M:%S', this.x) +'
'+ + formatter: function () { + return '' + this.series.name + '
' + + Highcharts.dateFormat('%d.%m.%Y %H:%M:%S', this.x) + '
' + Highcharts.numberFormat(this.y, 1); } }, @@ -124,7 +123,7 @@ jQuery(function() { }, plotOptions: { area: { - lineWidth : 1, + lineWidth: 1, lineColor: '#666666', marker: { enabled: true, @@ -139,46 +138,53 @@ jQuery(function() { } }, - series: [{ - name: 'Flow', - type: 'area', - data: [{x: new Date().getTime(), y: 0}], - color: '#b3c58d', - fillColor : { - linearGradient : [0, 0, 0, 300], - stops : [ - [0, 'rgba(137,165,78,.5)'], - [1, 'rgba(137,165,78,1)'] - ] - } - }, { - name: 'Water Temperature', - type: 'area', - data: [{x: new Date().getTime(), y: 0}], - color: '#948ddf', - fillColor : { - linearGradient: [0, 0, 0, 300], - stops : [ - [0, 'rgba(146,146,235,.5)'], - [1, 'rgba(146,146,235,1)'] - ] + series: [ + { + name: 'Flow', + type: 'area', + data: [ + {x: new Date().getTime(), y: 0} + ], + color: '#b3c58d', + fillColor: { + linearGradient: [0, 0, 0, 300], + stops: [ + [0, 'rgba(137,165,78,.5)'], + [1, 'rgba(137,165,78,1)'] + ] + } + }, + { + name: 'Water Temperature', + type: 'area', + data: [ + {x: new Date().getTime(), y: 0} + ], + color: '#948ddf', + fillColor: { + linearGradient: [0, 0, 0, 300], + stops: [ + [0, 'rgba(146,146,235,.5)'], + [1, 'rgba(146,146,235,1)'] + ] + } } - }] + ] }); /** * Update charts and controls periodically */ - var socket = io.connect(); - var maxPointsPerSeries = (config.ui.chart.period / (config.ui.updateInterval / 1000)) * config.ui.chart.period; - var numSeries = chart.series.length; + var socket = io.connect(); + var maxPointsPerSeries = (config.ui.chart.period / (config.ui.updateInterval / 1000)) * config.ui.chart.period; + var numSeries = chart.series.length; - var updateUi = function(data) { + var updateUi = function (data) { // Remove points older than config.ui.chart.period var numPoints = chart.series[0].points.length - 1; - if(numPoints == maxPointsPerSeries) { - for(var i = 0; i < numSeries; i++) + if (numPoints == maxPointsPerSeries) { + for (var i = 0; i < numSeries; i++) chart.series[i].points.shift().remove(); } @@ -186,24 +192,24 @@ jQuery(function() { var time = new Date().getTime(); var flow = data.current.flow; - if(flow) { - flow = Helper.convert.flow( - flow, - config.aquastreamXt.flowSensor.impulsesPerLiter, - config.aquastreamXt.flowSensor.measuringImpulses - ); - flow = Helper.round(flow, 1); - var flowPlot = [time, flow]; - chart.series[0].addPoint(flowPlot, true, false); - } - - var waterTemp = Helper.round(data.current.temperature.water, 1); - var waterTempPlot = [time, waterTemp]; + if (flow) { + flow = Helper.convert.flow( + flow, + config.aquastreamXt.flowSensor.impulsesPerLiter, + config.aquastreamXt.flowSensor.measuringImpulses + ); + flow = Helper.round(flow, 1); + var flowPlot = [time, flow]; + chart.series[0].addPoint(flowPlot, true, false); + } + + var waterTemp = Helper.round(data.current.temperature.water, 1); + var waterTempPlot = [time, waterTemp]; chart.series[1].addPoint(waterTempPlot, true, false); - // Update data table with current data - var pumpDataHtml = pumpDataTemplate(data.current); - jQuery('#pump-data').html(pumpDataHtml); + // Update data table with current data + var pumpDataHtml = pumpDataTemplate(data.current); + jQuery('#pump-data').html(pumpDataHtml); }; // Initial update with current pumpData assigned in layout.jade diff --git a/public/js/helpers.js b/public/js/helpers.js index 0e5be3e..e7f74e4 100644 --- a/public/js/helpers.js +++ b/public/js/helpers.js @@ -7,7 +7,7 @@ var Helper = { - round: function(number, decimals) { + round: function (number, decimals) { if (arguments.length == 1) return Math.round(number); @@ -19,19 +19,19 @@ var Helper = { format: { - current: function(val) { + current: function (val) { return parseInt(val) + ' mA'; }, - frequency: function(val) { + frequency: function (val) { return parseInt(val) + ' Hz'; }, - power: function(val) { + power: function (val) { return Helper.round(val, 2) + ' W'; }, - voltage: function(val) { + voltage: function (val) { return Helper.round(val, 2) + ' V'; } @@ -39,12 +39,12 @@ var Helper = { convert: { - flow: function(rawFlow, impulsesPerLiter, measuringImpulses) { - if(rawFlow >= 600000) { + flow: function (rawFlow, impulsesPerLiter, measuringImpulses) { + if (rawFlow >= 600000) { return 0; } else { - var time = 46875 * 3600; - var cal = (measuringImpulses / 2) / impulsesPerLiter; + var time = 46875 * 3600; + var cal = (measuringImpulses / 2) / impulsesPerLiter; return time / (rawFlow / cal); } } @@ -52,27 +52,27 @@ var Helper = { }, Handlebars: { - round: function(val) { + round: function (val) { val = Handlebars.Utils.escapeExpression(val); return Helper.round(val, 2); }, - join: function(val) { + join: function (val) { return val.join(':'); }, - pumpMode: function(mode) { + pumpMode: function (mode) { - if(mode.aquastreamModeUltra) + if (mode.aquastreamModeUltra) return 'Ultra'; - if(mode.aquastreamModeAdvanced) + if (mode.aquastreamModeAdvanced) return 'Advanced'; return 'Standard'; }, - frequencyMode: function(pumpMode) { + frequencyMode: function (pumpMode) { return pumpMode.autoPumpMaxFrequency ? 'auto' : 'manual'; }, - deaerationMode: function(pumpMode) { + deaerationMode: function (pumpMode) { return pumpMode.deaeration ? 'on' : 'off'; } }