Skip to content

Instantly share code, notes, and snippets.

@martymcguire
Created November 19, 2009 17:07
Show Gist options
  • Save martymcguire/238905 to your computer and use it in GitHub Desktop.
Save martymcguire/238905 to your computer and use it in GitHub Desktop.
Simple example for reading an ambient light sensor via ioBridge
<html><head><title>Shop Light?</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>
</head><body>
The ioBridge is: <div id="module_status">unknown</div>
The shop light is: <div id="light_status">unknown</div>
<script>
// Makes an asynchronous request to fetch our module data and updates
// the module status and light status with the received data.
function refreshLightStatus() {
// replace the URL below with the Feed URL for your own Module
$.getJSON("http://iobridge.com/api/feed/key=waStTNuoEvld6t9wsM&callback=?",
function(data){
var module_status = data["module"]["status"];
$('#module_status').text(module_status);
var light_status = data["module"]["channels"][0]["AnalogInput"];
if(light_status >= 500) {
$('#light_status').text('On');
} else {
$('#light_status').text('Off');
}
});
}
// Start a timer to update the light status every 10 seconds)
var refreshId = setInterval(refreshLightStatus , 10000);
// And go ahead and refresh the light now
refreshLightStatus();
</script>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment