Skip to content

Instantly share code, notes, and snippets.

@shervinshaikh
Last active August 29, 2015 14:04
Show Gist options
  • Save shervinshaikh/249efb163b9de903b098 to your computer and use it in GitHub Desktop.
Save shervinshaikh/249efb163b9de903b098 to your computer and use it in GitHub Desktop.
Electric Imp - Yo all subscribers on button press
const YO_API_TOKEN = "api_token_goes_here";
device.on("yo", function(nothing) {
local url = "http://api.justyo.co/yoall/";
local body = "api_token=" + YO_API_TOKEN;
local req = http.post(url, {}, body);
local res = req.sendsync();
if(res.statuscode != 201) {
server.log(res.statuscode + " error sending message: " + res.body);
} else server.log("Sent YO! to all subscribers " + res.statuscode + " OK");
});
// Alias the GPIO pin as 'button'
button <- hardware.pin1;
function buttonPress() {
local state = button.read();
server.log("Button is triggered: " + (state ? "up" : "down"));
if(state == 1){
agent.send("yo", null);
}
}
// Configure the button to call buttonPress() when the pin's state changes
button.configure(DIGITAL_IN_PULLUP, buttonPress);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment