-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
167 lines (164 loc) · 4.38 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE HTML>
<head>
<title>Sensing Station</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.highcharts.com/highcharts.js"></script>
<style>
body {
min-width: 310px;
max-width: 800px;
height: 400px;
margin: 0 auto;
}
h2 {
font-family: Arial;
font-size: 2.5rem;
text-align: center;
}
</style>
</head>
<body>
<h2>Remote Sensing Station</h2>
<div id="chart-pm" class="container"></div>
<br>
<br>
<div id="chart-aqi" class="container"></div>
<br>
<br>
<div id="chart-co" class="container"></div>
<br>
</body>
<script>
var freq = 31000;
var qty = 35;
var localtimezone = 19800000;
var chartT = new Highcharts.Chart({
chart:{ renderTo : 'chart-pm' },
title: { text: 'Particulate Matter 1.0 ' },
series: [{
name: 'PM 1.0',
showInLegend: false,
data: []
}],
plotOptions: {
line: { animation: false,
dataLabels: { enabled: true }
},
series: { color: '#059e8a' }
},
xAxis: { type: 'datetime',
dateTimeLabelFormats: { second: '%H:%M:%S' }
},
yAxis: {
title: { text: 'ug/m3' }
},
credits: { enabled: false }
});
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var rq = this.responseText;
var rsp = rq.split(",");
var y = parseFloat(rsp[0]);
var x = ((new Date(rsp[1])).getTime()) + localtimezone;
console.log(x);
if( this.responseText === "NaN"){
console.log(this.responseText);
}
else{
if(chartT.series[0].data.length > qty) {
chartT.series[0].addPoint([x, y], true, true, true);
} else {
chartT.series[0].addPoint([x, y], true, false, true);
}
}
}
};
xhttp.open("GET", "/pm-val.php", true);
xhttp.send();
}, freq ) ;
var chartH = new Highcharts.Chart({
chart:{ renderTo:'chart-aqi' },
title: { text: 'Air Quality Index (AQI)' },
series: [{
name: 'AQI',
showInLegend: false,
data: []
}],
plotOptions: {
line: { animation: false,
dataLabels: { enabled: true }
}
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { second: '%H:%M:%S' }
},
yAxis: {
title: { text: 'AQI' }
},
credits: { enabled: false }
});
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var rq = this.responseText;
var rsp = rq.split(",");
var y = parseFloat(rsp[0]);
var x = ((new Date(rsp[1])).getTime()) + localtimezone;
if(chartH.series[0].data.length > qty) {
chartH.series[0].addPoint([x, y], true, true, true);
} else {
chartH.series[0].addPoint([x, y], true, false, true);
}
}
};
xhttp.open("GET", "/aqi-val.php", true);
xhttp.send();
}, freq ) ;
var chartP = new Highcharts.Chart({
chart:{ renderTo:'chart-co' },
title: { text: 'Carbon Monoxide Index' },
series: [{
name: 'CO',
showInLegend: false,
data: []
}],
plotOptions: {
line: { animation: false,
dataLabels: { enabled: true }
},
series: { color: '#18009c' }
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { second: '%H:%M:%S' }
},
yAxis: {
title: { text: 'CO Index' }
},
credits: { enabled: false }
});
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var rq = this.responseText;
var rsp = rq.split(",");
var y = parseFloat(rsp[0]);
var x = ((new Date(rsp[1])).getTime()) + localtimezone;
console.log(this.responseText);
if(chartP.series[0].data.length > qty) {
chartP.series[0].addPoint([x, y], true, true, true);
} else {
chartP.series[0].addPoint([x, y], true, false, true);
}
}
};
xhttp.open("GET", "/co-val.php", true);
xhttp.send();
}, freq ) ;
</script>
</html>