From 729bb3824982b9351550db8d6208f5bcba50551a Mon Sep 17 00:00:00 2001 From: Karai Csaba Date: Sat, 7 May 2016 12:41:02 +0200 Subject: [PATCH] Refresh rate implementation --- examples/dummy-web-server.pl | 16 ++++++++++++++++ examples/web-server/GZipped.html.gz | Bin 70 -> 0 bytes examples/web-server/Voltage.html | 10 ++++++++++ html/userpage.js | 21 +++++++++++++++++++++ 4 files changed, 47 insertions(+) delete mode 100644 examples/web-server/GZipped.html.gz create mode 100644 examples/web-server/Voltage.html diff --git a/examples/dummy-web-server.pl b/examples/dummy-web-server.pl index 6743c43..56015ef 100755 --- a/examples/dummy-web-server.pl +++ b/examples/dummy-web-server.pl @@ -423,6 +423,17 @@ sub process_user_comm_led return content_response($r, $http->{url}); } +sub process_user_comm_voltage +{ + my ($http) = @_; + + my $voltage = (((time - $startTime) % 60) - 30) / 30.0 + 4.0; + $voltage = sprintf("%.2f V", $voltage); + + my $r = '{"voltage": "' . $voltage . '"}'; + return content_response($r, $http->{url}); +} + sub process_user_comm() { my ($http) = @_; @@ -431,4 +442,9 @@ sub process_user_comm() { return process_user_comm_led($http); } + + if( $http->{url} eq '/Voltage.html.json' ) + { + return process_user_comm_voltage($http); + } } diff --git a/examples/web-server/GZipped.html.gz b/examples/web-server/GZipped.html.gz deleted file mode 100644 index e9c012cb904e9c9107c4e843e72fcd11459dc711..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 70 zcmV-M0J;AkiwFohktJ6E14mkEaByX0E@*UZYyeYGut~`*v*S_#0-Fp&yO4~`Vg(>d cugWYaNKLWP2Z{kDZS=va0Q%qKmo5MR09@P}TmS$7 diff --git a/examples/web-server/Voltage.html b/examples/web-server/Voltage.html new file mode 100644 index 0000000..08e1017 --- /dev/null +++ b/examples/web-server/Voltage.html @@ -0,0 +1,10 @@ + + +
+

Voltage measurement

+
+ +
+

+

+ diff --git a/html/userpage.js b/html/userpage.js index 9f85a90..3a76530 100644 --- a/html/userpage.js +++ b/html/userpage.js @@ -1,6 +1,8 @@ //===== Java script for user pages var loadCounter = 0; +var refreshRate = 0; +var refreshTimer; function notifyResponse( data ) { @@ -42,6 +44,14 @@ function notifyResponse( data ) } } }); + + if( refreshRate != 0 ) + { + clearTimeout(refreshTimer); + refreshTimer = setTimeout( function () { + ajaxJson("GET", window.location.pathname + ".json?reason=refresh", notifyResponse ); + }, refreshRate ); + } } function notifyButtonPressed( btnId ) @@ -101,6 +111,17 @@ document.addEventListener("DOMContentLoaded", function(){ }; } + // collect metas + var metas = document.getElementsByTagName("meta"); + + for (ndx = 0; ndx < metas.length; ndx++) { + var meta = metas[ndx]; + if( meta.getAttribute("name") == "refresh-rate" ) + { + refreshRate = meta.getAttribute("content"); + } + } + // load variables at first time var loadVariables = function() { ajaxJson("GET", window.location.pathname + ".json?reason=load", notifyResponse,