-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
165 lines (143 loc) · 5.96 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
<!DOCTYPE html>
<html>
<head>
<title>Home Climate Monitoring</title>
<!-- EXTERNAL LIBS-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://www.google.com/jsapi"></script>
<!-- EXAMPLE SCRIPT -->
<script>
// Find the right method, call on correct element
function launchIntoFullscreen(element) {
if(element.requestFullscreen) {
element.requestFullscreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if(element.msRequestFullscreen) {
element.msRequestFullscreen();
}
}
// Whack fullscreen
function exitFullscreen() {
if(document.exitFullscreen) {
document.exitFullscreen();
} else if(document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if(document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
// onload callback
function drawChart() {
var cloud_url = 'https://data.sparkfun.com/output/';
// Public Key from https://data.sparkfun.com
var public_key = 'q5njo01A2GImgabArVp3';
// JSONP request
var jsonData = $.ajax({
url: cloud_url + public_key + '.json',
data: {page: 1},
dataType: 'jsonp',
}).done(function (results) {
var combinedResults = results
console.log(results);
console.log(combinedResults);
var jsonData = $.ajax({
url: cloud_url + public_key + '.json',
data: {page: 2},
dataType: 'jsonp',
}).done(function (results) {
combinedResults = combinedResults.concat(results);
console.log(results);
console.log(combinedResults);
var jsonData = $.ajax({
url: cloud_url + public_key + '.json',
data: {page: 3},
dataType: 'jsonp',
}).done(function (results) {
combinedResults = combinedResults.concat(results);
console.log(results);
console.log(combinedResults);
var latest = combinedResults[0];
var tempGauge = new google.visualization.Gauge($('#tempGauge').get(0));
var tempGaugeData = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Temp\u00E9rature', 0],
]);
var tempGaugeOptions = {
width: 300, height: 300,
redFrom: 30, redTo: 50,
greenFrom:20, greenTo: 30,
yellowFrom:0, yellowTo: 20,
yellowColor: "#00ccff",
minorTicks: 10,
majorTicks: ['0', '10', '20', '30', '40', '50'],
max: 50
};
// For animation purpose only
//tempGauge.draw(tempGaugeData,tempGaugeOptions);
// Show real data
tempGaugeData.setValue(0,1,parseFloat(latest.temp));
tempGauge.draw(tempGaugeData,tempGaugeOptions);
var humidityGauge = new google.visualization.Gauge($('#humidityGauge').get(0));
var humidityGaugeData = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Humidit\u00E9', 0],
]);
var humidityGaugeOptions = {
width: 300, height: 300,
redFrom: 45, redTo: 100,
greenFrom:30, greenTo: 45,
yellowFrom:0, yellowTo: 30,
minorTicks: 10,
majorTicks: ['0', '20', '40', '60', '80', '100'],
max: 100
};
// For animation purpose only
//humidityGauge.draw(humidityGaugeData,humidityGaugeOptions);
// Show real data
humidityGaugeData.setValue(0,1,parseFloat(latest.humidity));
humidityGauge.draw(humidityGaugeData,humidityGaugeOptions);
var data = new google.visualization.DataTable();
data.addColumn('datetime', 'Time');
data.addColumn('number', 'Temp\u00E9rature');
data.addColumn('number', 'Humidit\u00E9');
$.each(combinedResults, function (i, row) {
data.addRow([
(new Date(row.timestamp)),
parseFloat(row.temp),
parseFloat(row.humidity),
]);
});
var chart = new google.visualization.LineChart($('#temperature').get(0));
chart.draw(data, {
title: 'Historical Data',
height: 285,
theme: 'maximized',
explorer: {},
vAxis:{minValue: 0,maxValue: 100}
});
});
});
});
setTimeout(function () {
drawChart();
}, 60000);
}
// load chart lib
google.load('visualization', '1', {
packages: ['corechart','gauge']
});
// call drawChart once google charts is loaded
google.setOnLoadCallback(drawChart);
</script>
</head>
<body style="text-align:center">
<div id="tempGauge" style="display:inline-block;width:300px;margin-left:auto;margin-right:auto;"></div>
<div id="humidityGauge" style="display:inline-block;width:300px;margin-left:auto;margin-right:auto;"></div>
<div id="temperature" style="width: 95%;display:inline-block"></div>
<div id="fullscreen-button" style="display:block"><button onclick="launchIntoFullscreen(document.documentElement)">Full-screen</button></div>
<div id="exit-fullscreen-button" style="display:block"><button onclick="exitFullscreen()">Exit Full-screen</button></div>
</body>
</html>