-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.htm
153 lines (148 loc) · 8.05 KB
/
index.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!doctype html>
<html lang="en">
<head>
<script>
const debugip="192.168.0.90"; //change this to the esp32 ip for remote running of this page
</script>
<meta charset="utf-8">
<meta name="viewport" content="minimal-ui,width=device-width,initial-scale=1.0,user-scalable=no" />
<link rel="icon" href="data:;base64,iVBORw0KGgo="><!--prevent favicon requests-->
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<title>slimme meter</title>
<meta name="description" content="smartMeterLogger-esp32">
<meta name="author" content="Cellie">
<script>!function(a,b){"function"==typeof define&&define.amd?define([],b):"undefined"!=typeof module&&module.exports?module.exports=b():a.ReconnectingWebSocket=b()}(this,function(){function a(b,c,d){function l(a,b){var c=document.createEvent("CustomEvent");return c.initCustomEvent(a,!1,!1,b),c}var e={debug:!1,automaticOpen:!0,reconnectInterval:1e3,maxReconnectInterval:3e4,reconnectDecay:1.5,timeoutInterval:2e3};d||(d={});for(var f in e)this[f]="undefined"!=typeof d[f]?d[f]:e[f];this.url=b,this.reconnectAttempts=0,this.readyState=WebSocket.CONNECTING,this.protocol=null;var h,g=this,i=!1,j=!1,k=document.createElement("div");k.addEventListener("open",function(a){g.onopen(a)}),k.addEventListener("close",function(a){g.onclose(a)}),k.addEventListener("connecting",function(a){g.onconnecting(a)}),k.addEventListener("message",function(a){g.onmessage(a)}),k.addEventListener("error",function(a){g.onerror(a)}),this.addEventListener=k.addEventListener.bind(k),this.removeEventListener=k.removeEventListener.bind(k),this.dispatchEvent=k.dispatchEvent.bind(k),this.open=function(b){h=new WebSocket(g.url,c||[]),b||k.dispatchEvent(l("connecting")),(g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","attempt-connect",g.url);var d=h,e=setTimeout(function(){(g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","connection-timeout",g.url),j=!0,d.close(),j=!1},g.timeoutInterval);h.onopen=function(){clearTimeout(e),(g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","onopen",g.url),g.protocol=h.protocol,g.readyState=WebSocket.OPEN,g.reconnectAttempts=0;var d=l("open");d.isReconnect=b,b=!1,k.dispatchEvent(d)},h.onclose=function(c){if(clearTimeout(e),h=null,i)g.readyState=WebSocket.CLOSED,k.dispatchEvent(l("close"));else{g.readyState=WebSocket.CONNECTING;var d=l("connecting");d.code=c.code,d.reason=c.reason,d.wasClean=c.wasClean,k.dispatchEvent(d),b||j||((g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","onclose",g.url),k.dispatchEvent(l("close")));var e=g.reconnectInterval*Math.pow(g.reconnectDecay,g.reconnectAttempts);setTimeout(function(){g.reconnectAttempts++,g.open(!0)},e>g.maxReconnectInterval?g.maxReconnectInterval:e)}},h.onmessage=function(b){(g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","onmessage",g.url,b.data);var c=l("message");c.data=b.data,k.dispatchEvent(c)},h.onerror=function(b){(g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","onerror",g.url,b),k.dispatchEvent(l("error"))}},1==this.automaticOpen&&this.open(!1),this.send=function(b){if(h)return(g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","send",g.url,b),h.send(b);throw"INVALID_STATE_ERR : Pausing to reconnect websocket"},this.close=function(a,b){"undefined"==typeof a&&(a=1e3),i=!0,h&&h.close(a,b)},this.refresh=function(){h&&h.close()}}return a.prototype.onopen=function(){},a.prototype.onclose=function(){},a.prototype.onconnecting=function(){},a.prototype.onmessage=function(){},a.prototype.onerror=function(){},a.debugAll=!1,a.CONNECTING=WebSocket.CONNECTING,a.OPEN=WebSocket.OPEN,a.CLOSING=WebSocket.CLOSING,a.CLOSED=WebSocket.CLOSED,a});</script>
<style>
*{box-sizing:border-box;}
body{
padding:0;
width:100%;
background:black;
color:antiquewhite;
text-align:center;
font-family:'Roboto',sans-serif;
font-size:20px;
margin:0;
}
.noselect{
-webkit-touch-callout:none; /* iOS Safari */
-webkit-user-select:none; /* Safari */
-khtml-user-select:none; /* Konqueror HTML */
-moz-user-select:none; /* Firefox */
-ms-user-select:none; /* Internet Explorer/Edge */
user-select:none; /* Non-prefixed version,currently
supported by Chrome and Opera */
}
.container{
margin:0 0 20px;
}
.info{
margin:0;
font-size:25px;
}
#topmenu{
margin:0 auto;
width:fit-content;
align-items: center;
}
#title{
font-size:20px;
color:yellow;
margin:5px;
text-align:center;
width:fit-content;
}
a, span{
display:inline-block;
white-space:nowrap;
}
a{
width:fit-content;
text-decoration:none;
color:white;
white-space:normal;
font-size:20px;
margin:5px;
}
.name, .value{
width:40%;
display:inline-block;
margin:2px 5px;
}
.name{
text-align:right;
}
.value{
text-align:left;
}
</style>
</head>
<body class="noselect">
<div id="topmenu">
<span id="title">slimme meter</span><a href="/daggrafiek">vandaag</a>
</div>
<p class="info">nu</p>
<div class="container">
<p class="name">verbruik:</p><p id="currentUse" class="value"></p>
<p class="name">tarief:</p><p id="tariff" class="value"></p>
</div>
<p class="info">vandaag</p>
<div class="container">
<p class="name">electra laag:</p><p id="lowToday" class="value"></p>
<p class="name">electra hoog:</p><p id="highToday" class="value"></p>
<p class="name">totaal:</p><p id="total_tUse" class="value"></p>
<p class="name">gas:</p><p id="gasToday" class="value"></p>
</div>
<p class="info">totaal</p>
<div class="container">
<p class="name">electra laag:</p><p id="lowUse" class="value"></p>
<p class="name">electra hoog:</p><p id="highUse" class="value"></p>
<p class="name">totaal:</p><p id="total_eUse" class="value"></p>
<p class="name">gas:</p><p id="gasUse" class="value"></p>
</div>
<script>
const http_protocol = window.location.protocol !== 'https:' ? 'http://' : 'https://';
const http_host = http_protocol + (window.location.hostname ? window.location.hostname : debugip);
const ws_protocol = window.location.protocol !== 'https:' ? 'ws://' : 'wss://';
const ws_host = ws_protocol + (window.location.hostname ? window.location.hostname : debugip) + "/events";
function ready(callbackFunction){
if (document.readyState != 'loading')
callbackFunction(event);
else
document.addEventListener("DOMContentLoaded", callbackFunction);
}
ready(event => {
var ws = new ReconnectingWebSocket(ws_host, null, {debug:false, reconnectInterval:3500});
ws.onmessage = function(e){
if (!e.data.startsWith('current\n')) return;
var dsmr = e.data.substring(e.data.indexOf('\n') + 1).split('\n');
document.getElementById('currentUse').innerHTML = dsmr[0] + " W";
document.getElementById('lowUse').innerHTML = (dsmr[1] / 1000.0).toFixed(1).replace(".", ",") + ' kWh';
document.getElementById('highUse').innerHTML = (dsmr[2] / 1000.0).toFixed(1).replace(".", ",") + ' kWh';
document.getElementById('lowToday').innerHTML = (dsmr[4] / 1000.0).toFixed(3).replace(".", ",") + ' kWh';
document.getElementById('highToday').innerHTML = (dsmr[5] / 1000.0).toFixed(3).replace(".", ",") + ' kWh';
document.getElementById('gasUse').innerHTML = (dsmr[3] / 1000.0).toFixed(1).replace(".", ",") + ' m³';
document.getElementById('gasToday').innerHTML = (dsmr[6] / 1000.0).toFixed(3).replace(".", ",") + ' m³';
document.getElementById('tariff').innerHTML = dsmr[7];
document.getElementById('total_eUse').innerHTML = ((dsmr[1] / 1000.0 + dsmr[2] / 1000.0)).toFixed(1).replace(".", ",") + ' kWh';
document.getElementById('total_tUse').innerHTML = ((dsmr[4] / 1000.0 + dsmr[5] / 1000.0)).toFixed(3).replace(".", ",") + ' kWh';
};
ws.onopen = function(){console.log('[WebSocket] Connected to ' + ws_host);}
ws.onclose = function(event){console.log('[WebSocket] Connection died, code=' + event.code + ' reason=' + event.reason);}
ws.onerror = function(error){console.log('[WebSocket] ' + ws_host + ' Error: ' + error.message);}
document.addEventListener('visibilitychange', e=>{
switch(document.visibilityState) {
case 'visible' : {
ws.open();
}
break;
case 'hidden' : {
ws.close();
}
default : {}
}
});
});
</script>
</body>
</html>