Last active
August 29, 2015 14:04
-
-
Save shervinshaikh/249efb163b9de903b098 to your computer and use it in GitHub Desktop.
Electric Imp - Yo all subscribers on button press
This file contains hidden or 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
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"); | |
}); |
This file contains hidden or 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
// 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