5 function RefreshPageState() {
7 var req = new XMLHttpRequest();
9 req.onreadystatechange = function () {
11 if (this.readyState != 4) return;
12 if (this.status == 200) {
14 var returnedData = JSON.parse(this.responseText);
16 var template = document.getElementById("template").innerHTML;
17 var value_color = document.getElementById("value").style.color;
21 for (var sensor_id in returnedData) {
22 var timestamp = returnedData[sensor_id]["timestamp"];
23 for (var sensor in returnedData[sensor_id]) {
24 if (sensor != "timestamp") {
25 for (var param in returnedData[sensor_id][sensor]) {
26 sensor_path = sensor_id+"."+sensor+"."+param;
27 value = returnedData[sensor_id][sensor][param];
28 name = properties["names"][sensor_path];
29 if (! name) { name = sensor_path; }
30 units = properties["units"][sensor_path];
31 scale = properties["scale"][sensor_path];
32 color = properties["colors"][sensor_path];
34 value = (scale[0] * value).toFixed(scale[1]);
39 var section = template.replace(/\$SENSOR_ID/g,sensor_id);
40 section = section.replace(/\$SENSOR/g,sensor);
41 section = section.replace(/\$PARAM/g,param);
42 section = section.replace(/\$NAME/g,name);
43 section = section.replace(/\$UNITS/g,units);
44 section = section.replace(/\$VALUE/g,value);
45 section = section.replace(/\$COLOR/g,color);
46 section = section.replace(/\$TIMESTAMP/g,timestamp);
47 html = html + section;
53 document.getElementById("meteo").innerHTML = html;
55 setTimeout(RefreshPageState,5000)
57 setTimeout(RefreshPageState,15000)
61 req.open("GET", urlbase+"state", true);
66 function GetProperties() {
67 var req = new XMLHttpRequest();
69 req.onreadystatechange = function () {
70 if (this.readyState != 4) return;
71 if (this.status != 200) {
72 setTimeout(GetProperties,30000);
75 properties = JSON.parse(this.responseText);
79 req.open("GET", urlbase+"props", true);
85 setTimeout(GetProperties,100)