Skip to content

Instantly share code, notes, and snippets.

@stenehall
Created April 22, 2015 14:09
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 stenehall/96df8bdacbbc79bd9543 to your computer and use it in GitHub Desktop.
Save stenehall/96df8bdacbbc79bd9543 to your computer and use it in GitHub Desktop.
Express app for Narratives coffeemaker
var stateCount = 0;
var timer;
var resetTimer;
var brewing = false;
app.post('/brew_hook', function(req, res) {
stateCount++;
clearTimeout(resetTimer);
resetTimer = setTimeout(function() {
stateCount = 0;
brewing = false;
}, 60000);
if (stateCount > 1) {
if (brewing === false) {
brewing = true;
io.emit('brew_update', JSON.stringify({ "brewing": brewing }));
request(hubotDomain + '/brewingcoffee'); // Ping hubot webhook that the coffee is ready
}
clearTimeout(timer);
timer = setTimeout(function() {
stateCount = 0;
brewing = false;
var CoffeeObject = Parse.Object.extend("Coffee");
var coffeeObject = new CoffeeObject();
coffeeObject.save({cups: 7});
io.emit('brew_update', JSON.stringify({ "brewing": brewing }));
request(hubotDomain + '/donecoffee'); // Ping hubot webhook that the coffee is ready
}, 240000);
}
res.sendStatus(200);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment