5 function getCookie(name) {
6 var matches = document.cookie.match(new RegExp(
7 "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
9 return matches ? decodeURIComponent(matches[1]) : undefined;
12 function RefreshPageState() {
14 var req = new XMLHttpRequest();
16 req.onreadystatechange = function () {
18 if (this.readyState != 4) return;
19 if (this.status == 200) {
21 var returnedData = JSON.parse(this.responseText);
23 var template = document.getElementById("template").innerHTML;
24 var divider_template = document.getElementById("divider-template").innerHTML;
25 var value_color = document.getElementById("value").style.color;
29 for (var place in returnedData) {
30 var divider = divider_template.replace(/\$PLACE/g,place);
31 html = html + divider;
32 for (var sensor_id in returnedData[place]) {
33 var timestamp = returnedData[place][sensor_id]["timestamp"];
34 for (var sensor in returnedData[place][sensor_id]) {
35 if (sensor != "timestamp") {
36 for (var param in returnedData[place][sensor_id][sensor]) {
37 sensor_path = sensor_id+"."+sensor+"."+param;
38 name = properties["names"][sensor_path];
39 if (! name.startsWith("-")) {
40 value = returnedData[place][sensor_id][sensor][param];
41 if (! name) { name = sensor_path; }
42 units = properties["units"][sensor_path];
43 scale = properties["scale"][sensor_path];
44 color = properties["colors"][sensor_path];
46 value = (scale[0] * value).toFixed(scale[1]);
51 var section = template.replace(/\$SENSOR_ID/g,sensor_id);
52 section = section.replace(/\$SENSOR/g,sensor);
53 section = section.replace(/\$PARAM/g,param);
54 section = section.replace(/\$NAME/g,name);
55 section = section.replace(/\$UNITS/g,units);
56 section = section.replace(/\$VALUE/g,value);
57 section = section.replace(/\$COLOR/g,color);
58 section = section.replace(/\$TIMESTAMP/g,timestamp);
59 html = html + section;
67 document.getElementById("meteo").innerHTML = html;
69 setTimeout(RefreshPageState,60000)
71 setTimeout(RefreshPageState,60000)
75 req.open("GET", urlbase+"state", true);
76 req.withCredentials = true;
81 function GetProperties() {
82 var req = new XMLHttpRequest();
84 req.onreadystatechange = function () {
85 if (this.readyState != 4) return;
86 if (this.status != 200) {
87 setTimeout(GetProperties,30000);
90 properties = JSON.parse(this.responseText);
94 req.open("GET", urlbase+"props", true);
95 req.withCredentials = true;
101 var req = new XMLHttpRequest();
103 req.onreadystatechange = function () {
104 if (this.readyState != 4) return;
105 if (this.status != 200) {
106 setTimeout(GetAuth,30000);
112 req.open("GET", "auth", true);
113 req.withCredentials = true;
118 function CheckCookie() {
120 if (getCookie("auth-token")) {
122 authDiv = document.getElementById("auth");
123 authDiv.innerHTML = "";
129 setTimeout(GetProperties,100);
130 setTimeout(CheckCookie,200);