Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
109 lines (92 sloc) 3.19 KB
<!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) + " &deg;" + pool.temperatureUnit
}).appendTo(poolDiv);
}
else {
$("<span/>", {
"class": "temperature",
html: "--"
}).appendTo(poolDiv);
}
});
});
}
</script>
</body>
</html>
You can’t perform that action at this time.