Skip to content

Commit 7de373a

Browse files
Fixes.
1 parent 8608a13 commit 7de373a

File tree

3 files changed

+589
-578
lines changed

3 files changed

+589
-578
lines changed

dagelijks.htm

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<script>
5-
const debugip="192.168.0.104"; //change this to the esp32 ip for remote running of this page
5+
const debugip="192.168.0.106"; //change this to the esp32 ip for remote running of this page
66
</script>
77
<meta charset="utf-8">
88
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
@@ -140,8 +140,8 @@
140140
.navbutton:active,.rangebutton:active {
141141
transform:scale(0.95);
142142
}
143-
#nographics{
144-
line-height:200px;
143+
#currentuse{
144+
//line-height:120px;
145145
display:none;
146146
font-size:115px;
147147
white-space:nowrap;
@@ -170,7 +170,7 @@
170170
display:none;
171171
}
172172
#currentdate{display:block;}
173-
#nographics{display:block;}
173+
#currentuse{display:block;}
174174
#header,#current{display:none;}
175175
#footerbox,#compare{display:none;}
176176

@@ -219,6 +219,11 @@
219219
font-size:35px;
220220
line-height:10px;
221221
}
222+
.currenttext{
223+
font-size:20px;
224+
margin:0;
225+
padding:0;
226+
}
222227
.navbutton{
223228
vertical-align:middle;
224229
}
@@ -260,7 +265,7 @@
260265
<button type="button" id="nextbutton" class="navbutton"><svg class="navicon" xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg></button>
261266
</div>
262267
<p id="currentdate">&nbsp;</p>
263-
<div id="nographics"></div>
268+
<div id="currentuse"></div>
264269
<div id="footerbox"></div>
265270
<script>
266271
const http_host = "http://" + (window.location.hostname ? window.location.hostname : debugip);
@@ -285,7 +290,7 @@
285290
document.addEventListener("DOMContentLoaded", callbackFunction);
286291
}
287292

288-
function datumUrl(date) {
293+
function logFileUrl(date) {
289294
const datum = new Date(date);
290295
return http_host + '/' + datum.getFullYear() + '/' + (datum.getMonth() + 1) + '/' + datum.getDate() + '.log';
291296
}
@@ -328,33 +333,32 @@
328333
drawGraph(savedCompareData, true);
329334
}
330335

331-
function getData(time, callBack, toCompareCanvas) {
336+
function getData(date, callBack, toCompareCanvas) {
332337
var xhttp = new XMLHttpRequest();
333338
xhttp.onreadystatechange = function() {
334-
const date = new Date(time);
335339
if (this.readyState == 4) {
336340
switch (this.status) {
337341
case 200 :
338342
if (!toCompareCanvas) {
339343
savedData = this.responseText;
340-
currentDay = time;
344+
currentDay = date;
341345
}
342346
else {
343347
savedCompareData = this.responseText;
344-
compareDay = time;
348+
compareDay = date;
345349
}
346350
callBack(this.responseText, toCompareCanvas);
347351
break;
348352
case 404 : {
349353
const options = {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour12: false};
350-
document.getElementById('feedbackmsg').innerHTML = 'geen data aanwezig van <span class="nowrap">' + date.toLocaleDateString('nl-NL', options) + '</span>';
354+
document.getElementById('feedbackmsg').innerHTML = 'geen data aanwezig van <span class="nowrap">' + new Date(date).toLocaleDateString('nl-NL', options) + '</span>';
351355
}
352356
break;
353357
default : console.log("unhandled xhr status code " + this.status);
354358
}
355359
}
356360
}
357-
xhttp.open('GET', datumUrl(time), true);
361+
xhttp.open('GET', logFileUrl(date), true);
358362
xhttp.send();
359363
}
360364

@@ -375,7 +379,7 @@
375379
const savedYear = document.getElementById('years').selectedIndex;
376380
document.getElementById('datepicker').innerHTML += html;
377381
//restore the saved index
378-
const years = document.getElementById('years');
382+
var years = document.getElementById('years');
379383
years.selectedIndex = savedYear;
380384
years.setAttribute('disabled', true)
381385
document.getElementById('months').focus();
@@ -458,12 +462,12 @@
458462

459463
ready(event => {
460464
const oneday = 86400 * 1000;
461-
var ws = new ReconnectingWebSocket(ws_host, null, {debug:false, reconnectInterval:3000});
465+
var ws = new ReconnectingWebSocket(ws_host);
462466

463467
ws.onmessage = function(e){
464468
if (e.data.startsWith('current\n')) {
465469
const use = e.data.substring(e.data.indexOf('\n') + 1).split('\n');
466-
document.getElementById('nographics').innerHTML = use[0] + '<span id="smallunit"> w</span>';
470+
document.getElementById('currentuse').innerHTML = '<p class="currenttext">huidig verbruik</p>' + use[0] + '<span id="smallunit"> w</span>';
467471
}
468472
else if (e.data.startsWith('electric_saved\n')) {
469473
if (currentDayEqualsToday()) {
@@ -482,8 +486,15 @@
482486
}
483487
}
484488

485-
ws.onclose = function(event){console.log('[WebSocket] Connection died, code=' + event.code + ' reason=' + event.reason);}
486-
ws.onerror = function(error){console.log('[WebSocket] ' + ws_host + ' Error: ' + error.message);}
489+
ws.onclose = function(event){
490+
console.log('[WebSocket] Connection died, code=' + event.code + ' reason=' + event.reason);
491+
ws.open();
492+
}
493+
494+
ws.onerror = function(error){
495+
console.log('[WebSocket] ' + ws_host + ' Error: ' + error.message);
496+
ws.refresh();
497+
}
487498

488499
document.getElementById('prevbutton').addEventListener('mouseup', function() {
489500
const previousday = new Date(currentDay).getTime() - oneday;
@@ -570,7 +581,7 @@
570581
document.getElementById('currentdate').innerHTML = new Date().toLocaleDateString('nl-NL', {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour12: false});
571582

572583
drawBackground();
573-
currentDay = new Date(Date.now());
584+
currentDay = new Date();
574585
document.getElementById('startRange').focus();
575586

576587
document.addEventListener('visibilitychange', e =>{

dagelijks.htm.gz

5 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)