|
2 | 2 | <html lang="en">
|
3 | 3 | <head>
|
4 | 4 | <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 |
6 | 6 | </script>
|
7 | 7 | <meta charset="utf-8">
|
8 | 8 | <meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
|
140 | 140 | .navbutton:active,.rangebutton:active {
|
141 | 141 | transform:scale(0.95);
|
142 | 142 | }
|
143 |
| -#nographics{ |
144 |
| - line-height:200px; |
| 143 | +#currentuse{ |
| 144 | + //line-height:120px; |
145 | 145 | display:none;
|
146 | 146 | font-size:115px;
|
147 | 147 | white-space:nowrap;
|
|
170 | 170 | display:none;
|
171 | 171 | }
|
172 | 172 | #currentdate{display:block;}
|
173 |
| - #nographics{display:block;} |
| 173 | + #currentuse{display:block;} |
174 | 174 | #header,#current{display:none;}
|
175 | 175 | #footerbox,#compare{display:none;}
|
176 | 176 |
|
|
219 | 219 | font-size:35px;
|
220 | 220 | line-height:10px;
|
221 | 221 | }
|
| 222 | +.currenttext{ |
| 223 | + font-size:20px; |
| 224 | + margin:0; |
| 225 | + padding:0; |
| 226 | +} |
222 | 227 | .navbutton{
|
223 | 228 | vertical-align:middle;
|
224 | 229 | }
|
|
260 | 265 | <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>
|
261 | 266 | </div>
|
262 | 267 | <p id="currentdate"> </p>
|
263 |
| -<div id="nographics"></div> |
| 268 | +<div id="currentuse"></div> |
264 | 269 | <div id="footerbox"></div>
|
265 | 270 | <script>
|
266 | 271 | const http_host = "http://" + (window.location.hostname ? window.location.hostname : debugip);
|
|
285 | 290 | document.addEventListener("DOMContentLoaded", callbackFunction);
|
286 | 291 | }
|
287 | 292 |
|
288 |
| -function datumUrl(date) { |
| 293 | +function logFileUrl(date) { |
289 | 294 | const datum = new Date(date);
|
290 | 295 | return http_host + '/' + datum.getFullYear() + '/' + (datum.getMonth() + 1) + '/' + datum.getDate() + '.log';
|
291 | 296 | }
|
|
328 | 333 | drawGraph(savedCompareData, true);
|
329 | 334 | }
|
330 | 335 |
|
331 |
| -function getData(time, callBack, toCompareCanvas) { |
| 336 | +function getData(date, callBack, toCompareCanvas) { |
332 | 337 | var xhttp = new XMLHttpRequest();
|
333 | 338 | xhttp.onreadystatechange = function() {
|
334 |
| - const date = new Date(time); |
335 | 339 | if (this.readyState == 4) {
|
336 | 340 | switch (this.status) {
|
337 | 341 | case 200 :
|
338 | 342 | if (!toCompareCanvas) {
|
339 | 343 | savedData = this.responseText;
|
340 |
| - currentDay = time; |
| 344 | + currentDay = date; |
341 | 345 | }
|
342 | 346 | else {
|
343 | 347 | savedCompareData = this.responseText;
|
344 |
| - compareDay = time; |
| 348 | + compareDay = date; |
345 | 349 | }
|
346 | 350 | callBack(this.responseText, toCompareCanvas);
|
347 | 351 | break;
|
348 | 352 | case 404 : {
|
349 | 353 | 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>'; |
351 | 355 | }
|
352 | 356 | break;
|
353 | 357 | default : console.log("unhandled xhr status code " + this.status);
|
354 | 358 | }
|
355 | 359 | }
|
356 | 360 | }
|
357 |
| - xhttp.open('GET', datumUrl(time), true); |
| 361 | + xhttp.open('GET', logFileUrl(date), true); |
358 | 362 | xhttp.send();
|
359 | 363 | }
|
360 | 364 |
|
|
375 | 379 | const savedYear = document.getElementById('years').selectedIndex;
|
376 | 380 | document.getElementById('datepicker').innerHTML += html;
|
377 | 381 | //restore the saved index
|
378 |
| - const years = document.getElementById('years'); |
| 382 | + var years = document.getElementById('years'); |
379 | 383 | years.selectedIndex = savedYear;
|
380 | 384 | years.setAttribute('disabled', true)
|
381 | 385 | document.getElementById('months').focus();
|
|
458 | 462 |
|
459 | 463 | ready(event => {
|
460 | 464 | const oneday = 86400 * 1000;
|
461 |
| - var ws = new ReconnectingWebSocket(ws_host, null, {debug:false, reconnectInterval:3000}); |
| 465 | + var ws = new ReconnectingWebSocket(ws_host); |
462 | 466 |
|
463 | 467 | ws.onmessage = function(e){
|
464 | 468 | if (e.data.startsWith('current\n')) {
|
465 | 469 | 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>'; |
467 | 471 | }
|
468 | 472 | else if (e.data.startsWith('electric_saved\n')) {
|
469 | 473 | if (currentDayEqualsToday()) {
|
|
482 | 486 | }
|
483 | 487 | }
|
484 | 488 |
|
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 | + } |
487 | 498 |
|
488 | 499 | document.getElementById('prevbutton').addEventListener('mouseup', function() {
|
489 | 500 | const previousday = new Date(currentDay).getTime() - oneday;
|
|
570 | 581 | document.getElementById('currentdate').innerHTML = new Date().toLocaleDateString('nl-NL', {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour12: false});
|
571 | 582 |
|
572 | 583 | drawBackground();
|
573 |
| - currentDay = new Date(Date.now()); |
| 584 | + currentDay = new Date(); |
574 | 585 | document.getElementById('startRange').focus();
|
575 | 586 |
|
576 | 587 | document.addEventListener('visibilitychange', e =>{
|
|
0 commit comments