Skip to content

Instantly share code, notes, and snippets.

@cat-haines
Created November 15, 2014 15:54
Show Gist options
  • Select an option

  • Save cat-haines/9b2d2506511e90913330 to your computer and use it in GitHub Desktop.

Select an option

Save cat-haines/9b2d2506511e90913330 to your computer and use it in GitHub Desktop.
LED API
http.onrequest(function(req, resp) {
if(req.path=="/led/on") {
device.send("led", 1);
}
if(req.path=="/led/off") {
device.send("led", 0);
}
resp.send(200, "OK")
});
device.on("button", function(state) {
http.get("http://requestb.in/1gr2jab1").sendasync(function(resp) {
server.log(resp.statuscode);
});
});
led <- hardware.pin9;
led.configure(DIGITAL_OUT, 0);
agent.on("led", function(state) {
led.write(state);
});
btn <- hardware.pin1;
btn.configure(DIGITAL_IN_PULLUP, function() {
local state = btn.read();
agent.send("button", state);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment