forked from raspberrypilearning/weather-station-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
120 lines (100 loc) · 3.4 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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Raspberry Pi Weather Demo</title>
<link href="css/rpi.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="js/flot/excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="js/flot/jquery.js"></script>
<script language="javascript" type="text/javascript" src="js/flot/jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="js/flot/jquery.flot.time.js"></script>
<script language="javascript" type="text/javascript" src="js/flot/jquery.flot.navigate.js"></script>
<script type="text/javascript">
$(function(){
var time_now = Date.now();
flot_defaults = {
xaxis: {
mode: "time",
minTickSize: [1, "hour"],
min: time_now - 86400000, //Last 24 hours
max: time_now,
twelveHourClock: true
},
pan: {
interactive: true
},
zoom: {
interactive: true
}
};
columns = [
{title: "Ambient temperature, C", col: "AMBIENT_TEMPERATURE"},
{title: "Ground temperature, C", col: "GROUND_TEMPERATURE"},
{title: "Air quality, %", col: "AIR_QUALITY"},
{title: "Air pressure, hPa", col: "AIR_PRESSURE"},
{title: "Relative humidity, %", col: "HUMIDITY"},
{title: "Wind speed, km/h", col: "WIND_SPEED"},
{title: "Wind gust speed, km/h", col: "WIND_GUST_SPEED"},
{title: "Rainfall, mm", col: "RAINFALL"}
]
var $update_plot = function(plot, $ph, col, timeout) {
var axes = plot.getAxes();
var mysql_from = (axes.xaxis.min / 1000).toFixed(0);
var mysql_to = (axes.xaxis.max / 1000).toFixed(0);
var on_data_received = function(data) {
var opts = $.extend({}, flot_defaults);
opts.xaxis.min = axes.xaxis.min;
opts.xaxis.max = axes.xaxis.max;
$.plot($ph, [data], opts);
};
$.ajax({
url: "./data.php?col=" + col.col + "&from=" + mysql_from + "&to=" + mysql_to,
type: "GET",
dataType: "json",
success: on_data_received
});
timeout = null;
};
var $content = $("#content");
$.each( columns, function(i, col){
var $container = $("<div/>");
$container.addClass("demo-container");
var $title = $("<p/>");
$title.text(col.title);
var $placeholder = $("<div/>");
$placeholder.addClass("demo-placeholder");
$placeholder.attr("id", col.col);
var $info = $("<div/>");
$container.append($placeholder);
$content.append($title);
$content.append($container);
$content.append($info);
var update_timeout = null;
$update_plot_timer = function(event, plot) {
if (update_timeout != null) clearTimeout(update_timeout);
update_timeout = setTimeout(function() {
$update_plot(plot, $placeholder, col, update_timeout);
}, 500);
};
$placeholder.bind("plotpan", $update_plot_timer);
$placeholder.bind("plotzoom", $update_plot_timer);
var plot = $.plot($placeholder, [], flot_defaults);
$update_plot(plot, $placeholder, col, update_timeout);
});
});
</script>
</head>
<body>
<div id="cover">
<div id="header">
<h2>Raspberry Pi Weather Demo</h2>
</div>
</div>
<div id="content">
</div>
<div id="footer">
<a href="http://www.raspberrypi.org/">Raspberry Pi Foundation</a>
<a href="csv.php">Dump entire database to CSV</a>
</div>
</body>
</html>