From 4828f5a7279a0189a921e09891713fbece990bd9 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Sun, 19 Dec 2021 09:57:51 +0100 Subject: [PATCH] Temperature graph --- src/web/AmsWebServer.cpp | 2 +- web/application.js | 63 ++++++++++++++++++++++++++++++++++++++-- web/head32.html | 3 -- web/head8266.html | 3 -- web/index.html | 6 ++++ 5 files changed, 68 insertions(+), 9 deletions(-) diff --git a/src/web/AmsWebServer.cpp b/src/web/AmsWebServer.cpp index 5e147c53..d14c9c9f 100644 --- a/src/web/AmsWebServer.cpp +++ b/src/web/AmsWebServer.cpp @@ -247,7 +247,7 @@ void AmsWebServer::temperatureJson() { conf == NULL || conf->common ? 1 : 0, data->lastRead ); - delay(1); + delay(10); } char* pos = buf+strlen(buf); snprintf(count == 0 ? pos : pos-1, 8, "]}"); diff --git a/web/application.js b/web/application.js index 603f4ead..fc351575 100644 --- a/web/application.js +++ b/web/application.js @@ -18,6 +18,7 @@ var po = { enableInteractivity: false, }; var pl = null; // Last price +var tl = null; // Last temperature // Day plot var ep; @@ -150,6 +151,25 @@ var xo = { } }; +// Temperature plot +var td = false; // Disable temperature +var tp; +var ta; +var to = { + title: 'Temperature sensors', + titleTextStyle: { + fontSize: 14 + }, + bar: { groupWidth: '90%' }, + legend: { position: 'none' }, + vAxis: { + title: '°C', + viewWindowMode: 'maximized' + }, + tooltip: { trigger: 'none'}, + enableInteractivity: false, +}; + $(function() { var meters = $('.plot1'); @@ -364,6 +384,7 @@ var setupChart = function() { ap = new google.visualization.ColumnChart(document.getElementById('ap')); ip = new google.visualization.PieChart(document.getElementById('ip')); xp = new google.visualization.PieChart(document.getElementById('xp')); + tp = new google.visualization.ColumnChart(document.getElementById('tp')); fetch(); drawDay(); drawMonth(); @@ -379,6 +400,10 @@ var redraw = function() { ap.draw(aa, ao); ip.draw(ia, io); xp.draw(xa, xo); + tp.draw(ta, to); + if(tl != null) { + tp.draw(ta, to); + } }; var drawPrices = function() { @@ -475,6 +500,36 @@ var drawMonth = function() { }); }; +var drawTemperature = function() { + if(td) return; + + $.ajax({ + url: '/temperature.json', + timeout: 30000, + dataType: 'json', + }).done(function(json) { + if(json.c > 1) { + $('#tpc').show(); + + var r = 1; + var min = 0; + data = [['Sensor','°C', { role: 'style' }, { role: 'annotation' }]]; + $.each(json.s, function(i, o) { + var name = o.n ? o.n : o.a; + data[r++] = [name, o.v, "color: #6f42c1;opacity: 0.9;", o.v.toFixed(1)]; + Math.min(0, o.v); + }); + if(min == 0) + to.vAxis.minValue = 0; + ta = google.visualization.arrayToDataTable(data); + tp.draw(ta, to); + td = false; + } else { + td = true; + } + }); +}; + var setStatus = function(id, sid) { var item = $('#'+id); item.removeClass('d-none'); @@ -669,12 +724,16 @@ var fetch = function() { $('#ml').html(json.me); } - var temp = parseInt(json.t); - if(temp == -127) { + var temp = parseFloat(json.t); + if(temp == -127.0) { $('.jt').html("N/A"); $('.rt').hide(); } else { $('.rt').show(); + if(tl != temp) { + drawTemperature(); + } + tl = temp; } var vcc = parseFloat(json.v); diff --git a/web/head32.html b/web/head32.html index 27108f87..1dbe0aeb 100644 --- a/web/head32.html +++ b/web/head32.html @@ -50,9 +50,6 @@