Last active
April 16, 2018 22:21
-
-
Save Kamrad117/518213a5d98d3a1c1aaccb5f14d15949 to your computer and use it in GitHub Desktop.
Mongoose os example of toggling led using index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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