Skip to content

Instantly share code, notes, and snippets.

@marksharratt
Last active July 30, 2018 18:01
Show Gist options
  • Save marksharratt/8435524 to your computer and use it in GitHub Desktop.
Save marksharratt/8435524 to your computer and use it in GitHub Desktop.
Simple energyhive data grab test
<p>This is a simple test to show that we can get energyhive data via imported GISTs. Pretty cool eh?</p>
#pwer_reading {
font-size: 32px;
color: #f0f;
margin: 30px 0;
}
<div class="row-fluid">
<div class="span6 offset3 gridON center">
<h1>This is my realtime energy usage data</h1>
<div id="pwer_reading"></div>
<div id="sensor_id"></div>
<div id="pwer_age"></div>
</div>
</div>
$(function() {
getInstantData = function() {
$.ajax({
url: '/proxy/getCurrentValuesSummary',
type: 'GET',
dataType: 'json',
data: '',
timeout: 9000,
success: function(json){
if (json.error && json !== null) {
alert('Error!')
} else {
for (var index in json) {
var reading = 0;
var ts = 0;
for (var d in json[index].data[0]) {
reading = json[index].data[0][d];
ts = d;
}
if (json[index].cid === 'PWER') {
if (reading !== null) {
$('#pwer_reading').text(reading/1000 + ' kW');
$('#sensor_id').text('SensorID:' + json[index].sid);
$('#pwer_age').text('last reading:' + json[index].age + ' seconds ago');
}
}
}
}
}
});
};
getInstantData();
setInterval(getInstantData, 6000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment