Last active
December 20, 2015 00:38
-
-
Save manuquentin/6042769 to your computer and use it in GitHub Desktop.
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
var alarmArmed = false; | |
// Called by Ninja Block when the remote button is pressed | |
app.post('/button', function (req, res) { | |
alarmArmed = !alarmArmed; | |
setAlarmStatus(alarmArmed, function(err){ | |
if(err){ | |
console.log('err : '+err); | |
} | |
}); | |
dispatchInfos(); | |
res.send(); | |
}); | |
// Called to change the Ninja Blocks eyes | |
function setAlarmStatus(status, cb){ | |
var path = status ? '/url-alarm-on' : '/url-alarm-off'; | |
var setAlarmOptions = { | |
hostname: 'api.ninja.is', | |
path: path, | |
method: 'POST', | |
headers: {accept: 'text/plain'} | |
}; | |
req = http.request(setAlarmOptions, function(res){ | |
res.on('end', function () { | |
cb(); | |
}); | |
res.on('error', cb); | |
}); | |
req.end(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment