Page 130 - Programming the Photon Getting Started With the Internet of Things
P. 130
g.refresh(volts);
setTimeout(getReading, 1000);
}
else {
alert("uh oh!");
}
}
function getReading(){
$.get(url, {access_token: accessToken}, callback);
}
</script>
</head>
<body>
<div id="gauge" class="200x160px"></div>
<script>
var g = new JustGage({
id: "gauge",
value: 0,
min: 0,
max: 3.3,
title: "Voltage",
levelColors: [
"#00FF00",
"#FFFF00",
"#FF0000"
]
});
getReading();
</script>
</body>
</html>
The gauge JavaScript library is imported from the local .js files, which you can
download from the www.justgauge.com website, and the variables are set up for both the
access token and device ID—make sure that you change these to match the tokens for
your device. The JavaScript function getReading is called to tell the HTTP request to be
sent to the Photon board and then attaches the callback function. When the HTTP request
responds, it checks to make sure that the request sent to the Photo was successful, and if it
was then it retrieves the voltage value. The gauge display is then updated with the new