-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.html
108 lines (92 loc) · 3.19 KB
/
example.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Usage of BHS-API</title>
<meta name="author" content="Derek Hildreth">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<style>
div.pool-data {
display: inline-block;
border: 1px solid #eee;
width: 200px;
height: 100px;
padding: 5px;
background: #f6f6f6;
margin: 10px;
position: relative;
}
div.pool-data i.fa {
font-size: 24px;
color: #333;
position: relative;
top: 35px;
left: 80px;
}
div.pool-data span {
display: block;
text-align: center;
}
div.pool-data span.name {
font-size: 24px;
color: #333;
}
div.pool-data span.temperature {
position: relative;
top: 15px;
font-size: 36px;
font-weight: bold;
color: #27457f;
}
div#last-updated {
font-size: 12px;
color: #777;
}
</style>
</head>
<body>
<h1>Bozeman Hot Springs Pool Tempertures Example Page</h1>
<div class="pool-data" id="pool0"><i class="fa fa-spinner fa-spin fa-3x fa-fw"></i></div>
<div class="pool-data" id="pool1"><i class="fa fa-spinner fa-spin fa-3x fa-fw"></i></div>
<div class="pool-data" id="pool2"><i class="fa fa-spinner fa-spin fa-3x fa-fw"></i></div>
<div id="last-updated"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(function(){
// Initial call to getTemperatures()
getTemperatures();
// Gather pool temperatures every 15 seconds
setInterval(getTemperatures, 15000);
});
function getTemperatures() {
var apiEndpoint = "http://192.168.1.120:8080";
var url = apiEndpoint + '/temperatures';
$.getJSON( url, function( data ) {
if(data) {
$("#last-updated").html(Date());
}
$.each( data, function( key, pool ) {
var poolDiv = $('#pool' + pool.id);
poolDiv.empty();
$("<span/>", {
"class": "name",
html: "Pool Number " + pool.id
}).appendTo(poolDiv);
if(!pool.error) {
$("<span/>", {
"class": "temperature",
html: Math.round(pool.temperature) + " °" + pool.temperatureUnit
}).appendTo(poolDiv);
}
else {
$("<span/>", {
"class": "temperature",
html: "--"
}).appendTo(poolDiv);
}
});
});
}
</script>
</body>
</html>