Created
August 19, 2014 00:14
-
-
Save billautomata/7ab9777a366b64437a0c 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 db = require('orchestrate')('MY DATABASE KEY') | |
var gpio = require("gpio"); | |
var gpio4 = gpio.export(4, { | |
direction: "in", | |
ready: function() { | |
} | |
}); | |
// whenever gpio4 changes, call this function that uses the argument 'val' | |
// which is the value of the pin | |
gpio4.on('change', function(val){ | |
if(val == 1){ | |
console.log(new Date(), 'motion!') | |
} | |
// send the data to the server to the collection 'motion' | |
db.post('motion', | |
{ | |
date: new Date, | |
value: val | |
} | |
).then(function(result){ | |
console.log('done posting to o.io '+ result) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment