Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Kamrad117
Last active April 16, 2018 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kamrad117/518213a5d98d3a1c1aaccb5f14d15949 to your computer and use it in GitHub Desktop.
Save Kamrad117/518213a5d98d3a1c1aaccb5f14d15949 to your computer and use it in GitHub Desktop.
Mongoose os example of toggling led using index.html
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="notifications"></div>
<a href="/rpc/Control" >Toggle Led</a>
<script>
$('a').click(function(event) {
event.preventDefault();
$.ajax({
url: $(this).attr('href'),
success: function(response) {
if(response == '0'){
text = 'Led is OFF'
} else {
text = 'Led is ON'
}
document.getElementById("notifications").innerHTML = text;
}
});
return false;
});
</script>
load('api_gpio.js');
load('api_rpc.js');
let led = 16;
GPIO.set_mode(led, GPIO.MODE_OUTPUT);
RPC.addHandler('Control', function(args) {
let result = GPIO.toggle(led);
return result;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment