Skip to content

Instantly share code, notes, and snippets.

@billautomata
Created August 19, 2014 00:14
Show Gist options
  • Save billautomata/7ab9777a366b64437a0c to your computer and use it in GitHub Desktop.
Save billautomata/7ab9777a366b64437a0c to your computer and use it in GitHub Desktop.
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