-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
379 lines (293 loc) · 10.3 KB
/
index.html
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<html>
<head>
<!--
NOTE: This plugin will not be visible on public views of a channel.
If you intend to make your channel public, consider using the
MATLAB Visualization App to create your visualizations.
-->
<style type="text/css">
body { background-color: #ddd; }
.header{
text-align:center;
width: 1452px;
margin: auto;
}
.headerText {
font-family: 'Helvetica Neue', 'Lucida Grande', 'Segoe UI', Arial, Helvetica, Verdana, sans-serif;
display: block;
font-size: 2em;
font-weight: bold;
/*
margin-block-start: 0.67em;
margin-block-end: 0.67em;
margin-inline-start: 0px;
margin-inline-end: 0px;
*/
}
.timeRight{
text-align: right;
padding: 5px;
font-family: 'Helvetica Neue', 'Lucida Grande', 'Segoe UI', Arial, Helvetica, Verdana, sans-serif;
}
.timeLeft{
text-align: left;
padding: 5px;
font-family: 'Helvetica Neue', 'Lucida Grande', 'Segoe UI', Arial, Helvetica, Verdana, sans-serif;
}
.gauge { float: left; width: 250px; height: 250px;}
.chartIframe {float: left;}
.inner1 {height:250px; width:1452px; margin:auto; padding-top: 20px; }
.inner2 {height:250px; width:1452px; margin:auto; padding-top: 20px; }
.inner3 {height:250px; width:1452px; margin:auto; padding-top: 20px; }
</style>
<title>[xeri-sk] Temp & Humi Monitoring</title>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
// set your channel id here
var channel_id = 1289568;
// set your channel's read api key here if necessary
var api_key = 'C3O58RRHRTD78GVU';
// maximum value for the gauge
//var max_gauge_value = 70;
// name of the gauge
//var gauge_name = 'Temp';
// global variables
var chart1, chart2, chart3, options1, options2, options3, charts, data;
var chartScale;
var lastUpdateChart = Date.now();
var lastUpdateGauge = Date.now();
// load the google gauge visualization
google.load('visualization', '1', {packages:['gauge']});
google.setOnLoadCallback(initCharts);
//setInterval('chartReload()', 1000);
function onload(){
chartReload();
setInterval('timeRefres()', 1000);
}
function chartReload(){
var chartRange = document.getElementById("selectRange").value;
var chartResults = chartRange * 60;
if(chartRange == 720){
chartScale = 240;
}
else if(chartRange == 168){
chartScale = 60;
}
else if(chartRange == 72){
chartScale = 30;
}
else if(chartRange == 24){
chartScale = 15;
}
else if(chartRange == 12){
chartScale = 10;
}
else if(chartRange == 6){
chartScale = "";
}
var iframeTemplateUrl = "https://thingspeak.com/channels/1289568/charts/";
var iframeTemplaceParamts = "bgcolor=%23ffffff&color=%23d62020&width=1200&type=spline&dynamic=true×cale=" + chartScale + "&results=" + chartResults;
//var iframe1Url = iframeTemplateUrl + "1?" + iframeTemplaceParamts + "&round=0%2C5&title=Temperature&yaxismin=20&yaxismax=30";
var iframe1Url = iframeTemplateUrl + "1?" + iframeTemplaceParamts + "&title=Temperature&yaxismin=20&yaxismax=30";
var iframe2Url = iframeTemplateUrl + "2?" + iframeTemplaceParamts + "&title=Humidity&yaxismin=0&yaxismax=100";
var iframe3Url = iframeTemplateUrl + "3?" + iframeTemplaceParamts + "&title=Socket&yaxismin=0&yaxismax=1";
document.getElementById('iframe1').src = iframe1Url;
document.getElementById('iframe2').src = iframe2Url;
document.getElementById('iframe3').src = iframe3Url;
}
function timeRefres(){
var nowTime = Date.now();
// chart
var lastUpdateGaugeRounded;
// when dont use chartScane, dont round time
if(chartScale == ""){
lastUpdateGaugeRounded = new Date(Date.parse(lastUpdateGauge));
}
else {
// round according chartScale
var coeff = 1000 * 60 * chartScale;
var myDate = new Date(Date.parse(lastUpdateGauge));
lastUpdateGaugeRounded = new Date(new Date(Math.round(myDate) / coeff) * coeff);
}
var sec = parseInt((nowTime - lastUpdateGaugeRounded) / 1000);
var timeStr = 'Last update: ';
if(sec < 60)
timeStr += sec + 'sec';
else
timeStr += parseInt(sec/60) + 'min';
document.getElementById('timeRight').innerHTML = timeStr;
var lastUpdateChart_plus60sec = new Date(lastUpdateChart);
lastUpdateChart_plus60sec.setSeconds(lastUpdateChart_plus60sec.getSeconds() + 60);
// if new data from gauge are newer than last update time [dont apply to chart without chartScale -> use dynamic update by thingspeak]
if(lastUpdateGaugeRounded > lastUpdateChart_plus60sec && chartScale != ""){
//console.log('WAITING');
//setTimeout(function(){ chartReload(); }, 30 * 1000); // wait 30sec for chart data from thingspeak
chartReload();;
lastUpdateChart = Date.now();
}
// gauge
var sec = parseInt((nowTime - Date.parse(lastUpdateGauge)) / 1000);
var timeStr = 'Last update: ';
timeStr += sec + 'sec';
document.getElementById('timeLeft').innerHTML = timeStr;
}
// initialize the chart
function initCharts() {
data = new google.visualization.DataTable();
data.addColumn('string', 'Label');
data.addColumn('number', 'Value');
data.addRows(1);
chart1 = new google.visualization.Gauge(document.getElementById('gauge_div_temp'));
options1 = {width: 250, height: 250,
min: 18, max: 34,
// RED
greenFrom: 18, greenTo: 34, greenColor: '#DC3912',
// GREEN
redFrom: 22, redTo: 25, redColor: '#109618',
// YELLOW
yellowFrom:20, yellowTo: 27, yellowColor: 'yellow',
animation:{
duration: 2000,
easing: 'inAndOut',
},
majorTicks: [
'18', '20', '22', '24', '26', '28', '30', '32', '34']
};
chart2 = new google.visualization.Gauge(document.getElementById('gauge_div_humi'));
options2 = {width: 250, height: 250,
min: 0, max: 100,
// RED
greenFrom: 0, greenTo: 100, greenColor: '#DC3912',
// GREEN
redFrom: 40, redTo: 60, redColor: '#109618',
// YELLOW
yellowFrom:30, yellowTo: 70, yellowColor: 'yellow',
animation:{
duration: 2000,
easing: 'inAndOut',
},
majorTicks: [
'0', '20', '40', '60', '80', '100' ]
};
chart3 = new google.visualization.Gauge(document.getElementById('gauge_div_heat'));
options3 = {width: 250, height: 250,
min: 0, max: 1,
majorTicks: [
'OFF', 'ON' ]
};
loadData();
// load new data every 15 seconds
setInterval('loadData()', 5000);
}
// load the data
function loadData() {
// variable for the data point
var t, h, heat, date;
// get the data from thingspeak
$.getJSON('https://api.thingspeak.com/channels/' + channel_id + '/feed/last.json?api_key=' + api_key, function(data) {
// get the data point
temp = data.field1;
humi = data.field2;
heat = data.field3;
date = data.created_at;
lastUpdateGauge = date;
//console.log(date);
// if there is a data point display it
if (temp) {
// p = Math.round((p / max_gauge_value) * 100);
displayDataTemp(temp);
}
if (humi) {
// p = Math.round((p / max_gauge_value) * 100);
displayDataHumi(humi);
}
if (heat) {
// p = Math.round((p / max_gauge_value) * 100);
displayDataHeat(heat);
}
else
displayDataHeat(0);
});
}
// display the data
function displayDataTemp(point) {
data.setValue(0, 0, 'Temp');
data.setValue(0, 1, point);
var formatter = new google.visualization.NumberFormat(
{suffix: '°C',pattern:'#.#'}
);
formatter.format(data,1);
chart1.draw(data, options1);
}
// display the data
function displayDataHumi(point) {
data.setValue(0, 0, 'Humi');
data.setValue(0, 1, point);
var formatter = new google.visualization.NumberFormat(
{suffix: '%',pattern:''}
);
formatter.format(data,1);
chart2.draw(data, options2);
}
// display the data
function displayDataHeat(point) {
data.setValue(0, 0, 'Socket');
data.setValue(0, 1, point);
var formatter = new google.visualization.NumberFormat(
{suffix: '',pattern:'#'}
);
formatter.format(data,1);
chart3.draw(data, options3);
}
</script>
</head>
<body onload="onload()">
<div id="container" >
<div class="header">
<span class="headerText"> Temperature & Humidity Monitoring </span>
<div style="padding-top: 5px; padding-bottom: 5px;">
<div style="width:50%; text-align: left; float:left; ">
<span id="timeLeft" class="timeLeft">Last update:</span>
</div>
<div style="width:50%; text-align: right; float:left;">
<span>Range:</span>
<select name="selectRange" id="selectRange" onchange="chartReload()">
<option value="6">6h</option>
<option value="12">12h</option>
<option value="24" selected="selected">1day</option>
<option value="72">3day</option>
<option value="168">1week</option>
<option value="720">1month</option>
</select>
<span id="timeRight" class="timeRight">Last update:</span>
</div>
</div>
</div>
<div id="inner1" class="inner1">
<div class="gauge">
<div id="gauge_div_temp"></div>
</div>
<div class="chartIframe">
<iframe id="iframe1" width="1200" height="260" style="border: 1px solid #cccccc;" src=""></iframe>
</div>
</div>
<div id="inner1" class="inner2">
<div class="gauge">
<div id="gauge_div_humi"></div>
</div>
<div class="chartIframe">
<iframe id="iframe2" width="1200" height="260" style="border: 1px solid #cccccc;" src=""></iframe>
</div>
</div>
<div id="inner1" class="inner3">
<div class="gauge">
<div id="gauge_div_heat" class="gauge"></div>
</div>
<div class="chartIframe">
<iframe id="iframe3" width="1200" height="260" style="border: 1px solid #cccccc;" src=""></iframe>
</div>
</div>
</div>
</body>
</html>