Skip to content

Commit ff73501

Browse files
Cleanup html & js.
1 parent cfe88b8 commit ff73501

File tree

2 files changed

+192
-220
lines changed

2 files changed

+192
-220
lines changed

index.htm

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<meta name="description" content="smartMeterReader-esp32">
1414
<meta name="author" content="Cellie">
1515
<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>
16-
<!-- https://www.w3schools.com/howto/howto_js_tabs.asp -->
1716
<style>
1817
*{box-sizing:border-box;}
1918
html,body{
@@ -42,9 +41,6 @@
4241
#currentUse{
4342
font-size:80px;
4443
}
45-
#totals{
46-
//display:inline-flex;
47-
}
4844
#lowUsed, #highUsed, #gasUsed{
4945
font-size:20px;
5046
margin:20px;
@@ -53,40 +49,29 @@
5349
</style>
5450
</head>
5551
<body class="noselect">
56-
<h2 id="header">Huidig tarief:&nbsp;&nbsp;<span id="tariff"></span></h2>
57-
<div id="currentUse"></div>
52+
<h2 id="header">Huidig tarief:&nbsp;&nbsp;<span id="tariff">onbekend</span></h2>
53+
<div id="currentUse">Nog geen data</div>
5854
<div id="totals"><p id="lowUsed"></p><p id="highUsed"></p><p id="gasUsed"></p></div>
5955
<script>
6056
var url="http://";
6157
if (window.location.hostname)url+=window.location.hostname;
6258
else url+=debugip;
63-
6459
var ws_host="ws://";
6560
if(window.location.hostname)ws_host+=window.location.hostname+"/current";
6661
else ws_host+=debugip+"/current";
67-
6862
$(document).ready(function(){
6963
var ws=new ReconnectingWebSocket(ws_host,null,{debug:true,reconnectInterval:3000});
70-
71-
// https://www.bitdegree.org/learn/javascript-number-format
72-
7364
ws.onmessage=function(e){
7465
var dsmr = e.data.split('\n');
7566
if(dsmr[0])$('#currentUse').html(dsmr[0]+"W");
76-
if(dsmr[1])$('#lowUsed').html("Totaal laag: "+(dsmr[1]/1000.0).toFixed(3).replace(".", ",")+" kWh&nbsp;&nbsp;&nbspvandaag: "+(dsmr[4]/1000.0).toFixed(3).replace(".", ",")+" kWh");
77-
if(dsmr[2])$('#highUsed').html("Totaal hoog: "+(dsmr[2]/1000.0).toFixed(3).replace(".", ",")+" kWh&nbsp;&nbsp;&nbspvandaag: "+(dsmr[5]/1000.0).toFixed(3).replace(".", ",")+" kWh");
78-
if(dsmr[3])$('#gasUsed').html("Totaal gas: "+(dsmr[3]/1000.0).toFixed(3).replace(".", ",")+" m³&nbsp;&nbsp;&nbspvandaag: "+(dsmr[6]/1000.0).toFixed(3).replace(".", ",")+" m³");
67+
if(dsmr[1])$('#lowUsed').html("Totaal laag: "+(dsmr[1]/1000.0).toFixed(3).replace(".", ",")+" kWh&nbsp;&nbsp;&nbsp;vandaag: "+(dsmr[4]/1000.0).toFixed(3).replace(".", ",")+" kWh");
68+
if(dsmr[2])$('#highUsed').html("Totaal hoog: "+(dsmr[2]/1000.0).toFixed(3).replace(".", ",")+" kWh&nbsp;&nbsp;&nbsp;vandaag: "+(dsmr[5]/1000.0).toFixed(3).replace(".", ",")+" kWh");
69+
if(dsmr[3])$('#gasUsed').html("Totaal gas: "+(dsmr[3]/1000.0).toFixed(3).replace(".", ",")+" m³&nbsp;&nbsp;&nbsp;vandaag: "+(dsmr[6]/1000.0).toFixed(3).replace(".", ",")+" m³");
7970
if(dsmr[7])$('#tariff').html(dsmr[7]);
8071
};
81-
82-
ws.onopen=function(event){
83-
console.log('[WebSocket] Connected');
84-
}
85-
86-
ws.onclose=function(event){
87-
console.log('[WebSocket] Connection died, code='+event.code+' reason='+event.reason);
88-
}
89-
ws.onerror=function(error){console.log('[WebSocket] Error: '+error.message);};
72+
ws.onopen=function(event){console.log('[WebSocket] Connected');}
73+
ws.onclose=function(event){console.log('[WebSocket] Connection died, code='+event.code+' reason='+event.reason);}
74+
ws.onerror=function(error){console.log('[WebSocket] Error: '+error.message);}
9075
})
9176
</script>
9277
</body>

0 commit comments

Comments
 (0)