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 e9c012c..0000000 Binary files a/examples/web-server/GZipped.html.gz and /dev/null differ 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,