LaundrySorcery

Log | Files | Refs

commit d292a21ad67f67adc293c13bd3988f79c46a3119
parent d19b6f333cd9c94d604f2123877464d598d11142
Author: Dominik Schmidt <das1993@hotmail.com>
Date:   Wed,  6 Jun 2018 16:50:15 +0000

Implement ajax live reloading of state

Diffstat:
www/index.sh | 25+++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/www/index.sh b/www/index.sh @@ -30,10 +30,6 @@ Content-Type: text/html <body> <H1>Laundry Status</H1> <div id="statusLine">The laundry machine is <span id="delta_t"></span></div> - <H1>Light Sensor Data</H1> - <div><img src="light_5min.sh" /></div> - <div><img src="light_1h.sh" /></div> - <div><img src="light_1d.sh" /></div> <script type="text/JavaScript"> <!-- delta_t=${DTIME}; @@ -47,6 +43,22 @@ Content-Type: text/html } } setInterval(function(){ if(delta_t>=0){delta_t++}; updateDisplay();}, 1000); + setInterval(function(){ readTextFile("on_file");}, 5*1000); + function readTextFile(file){ + var rawFile = new XMLHttpRequest(); + rawFile.open("GET", file, false); + rawFile.onreadystatechange = function () + { + if(rawFile.readyState === 4) + { + if(rawFile.status === 200 || rawFile.status == 0) + { + delta_t = rawFile.responseText; + } + } + } + rawFile.send(null); + } function timeSince(delta_t) { var interval = Math.floor(delta_t / 31536000); if (interval > 1) { @@ -70,8 +82,13 @@ Content-Type: text/html } return Math.floor(seconds) + " seconds"; } + updateDisplay(); --> </script> + <H1>Light Sensor Data</H1> + <div><img src="light_5min.sh" /></div> + <div><img src="light_1h.sh" /></div> + <div><img src="light_1d.sh" /></div> </body> </HTML> EOF