Stap 5: Volledige code
/* gpio */ gpio.close(pin); // Close pin 16
gpio.open(pin, "output", function(err) { // Open pin 16 for output gpio.write(pin, 1, function() {}); });
/* Slack */ slack.on('message', function(message) { var type = message.type, channel = slack.getChannelGroupOrDMByID(message.channel), user = slack.getUserByID(message.user), time = message.ts, text = message.text, response = '';
if (user === undefined){ /* skip channel messages(skip the messages which are not sent to sesame directly) */ return true; } console.log('Received: %s %s %s "%s"', type, (channel.is_channel ? '#' : '') + channel.name, user.name, time, text);
if (type === 'message') { if (text === 'open'){ openDoor(doorTimeout); response = 'ok'; channel.send(response); console.log(' responded with "%s"', slack.self.name, response); } } });
/ * Toegestane * / slack.on('error', function(error) { console.error('Error: %s', error); });
slack.login(); /* /slack */
function openDoor(){ console.log('open called'); gpio.write(pin, 0, function() {}); setTimeout(function() { gpio.write(pin, 1, function() {}); }, (1 * 1000)); }
sudo npm -g install forever
### BEGIN INIT INFO<br># Provides: sesame # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Sesame ### END INIT INFO
case "$1" in start) su pi -c 'forever start -p /home/pi/.forever /home/pi/sesame/app.js' ;; stop) su pi -c 'forever stopall' ;; *)