3 <link rel="shortcut icon" href="favicon.svg">
4 <title>ampy - Le compteur espion qui ne moucharde pas</title>
5 <script src=ampy.js></script>
13 padding: 1px 2px 1px 2px;
17 <div id=errorpannel style="display:none;">
20 Puissance instannée: <span id=currentpower>Unknown</span> watts
23 Compteur: <span id=totalpower>unknown</span> kWh
28 <a href='javascript:refresh_graph(0,5)'>5m</a>
29 <a href='javascript:refresh_graph(0,30)'>30m</a>
30 <a href='javascript:refresh_graph(1)'>1h</a>
31 <a href='javascript:refresh_graph(2)'>2h</a>
32 <a href='javascript:refresh_graph(6)'>6h</a>
33 <a href='javascript:refresh_graph(12)'>12h</a>
34 <a href='javascript:refresh_graph(24)'>1d</a>
35 <a href='javascript:refresh_graph(2*24)'>2d</a>
36 <a href='javascript:refresh_graph(7*24)'>7d</a>
37 <a href='javascript:refresh_graph(30*24)'>30d</a>
38 <a href='javascript:refresh_graph(365*24)'>1y</a>
43 <img id='loadcurve' src='graph.php'>
47 function startComet() {
48 MAX_BUFFER_SIZE = 64*1024; // 64 kiB
49 xhr = new XMLHttpRequest();
50 xhr.onreadystatechange = function() {
51 //console.log("xhr.status:"+xhr.status+". xhr.readyState="+xhr.readyState);
52 if (xhr.status == 200) {
53 switch (xhr.readyState) {
55 response = xhr.responseText;
56 //console.log("responseText:"+response);
57 new_text = response.substring(xhr.ampy_len);
58 xhr.ampy_len = response.length;
59 //console.log("new_text: "+new_text);
61 // If the client is lagging, we can get several json items
62 // at once. Truncate them:
63 for (datum of new_text.trim().split("}")) {
65 updatePage(datum+"}");
67 if (xhr.ampy_len > MAX_BUFFER_SIZE) {
68 xhr.abort(); // Don't let the buffer get too big
73 repportError("XMLHttpRequest connection lost. Reconnecting...");
78 switch (xhr.readyState) {
79 case 2: /* header received */
80 repportError("XMLHttpRequest returned code "+xhr.status+" ("+xhr.statusText+")");
86 xhr.open('GET', 'currentjson_chunked.php', true /*async*/);
91 function refresh_graph(hours=0, minutes=0) {
92 img = document.getElementById('loadcurve');
93 img.src = 'graph.php?h='+hours+'&m='+minutes+'&t='+new Date().getTime();
98 <!--img src="graph.php"-->