Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
This snippet requires both the ntwitter & ar-drone modules to be installed. "npm install ntwitter" and "npm install ar-drone" will suffice. As of this writing, it's merely a POC that one can control an AR Drone over the internet. See [http://tinyurl.com/gogonc] for more information and background.
// CONFIGURE YOUR AR DRONE'S CONNECTION TO THE INTERNET
// See http://tinyurl.com/gogonc (as in "go go node copter!")
// CREDENTIALS.JS - populate with Twitter API credentials
var credentials = {
consumer_key: 'CONSUMERKEY',
consumer_secret: 'CONSUMERSECRET',
access_token_key: 'ACCESSTOKEN',
access_token_secret: 'ACCESSTOKENSECRET'
};
module.exports = credentials;
// MAIN SCRIPT - name it whatever you'd like
var twitter = require('ntwitter');
var credentials = require('./credentials.js');
var arDrone = require('ar-drone');
var options = {ip:'10.0.1.2'};
var client = arDrone.createClient(options);
function alertMe(){
client.takeoff();
client
.after(100, function() {
this.animateLeds('rightMissile', 5, 2)
})
.after(500, function() {
this.stop();
this.land();
});
}
var t = new twitter({
consumer_key: credentials.consumer_key,
consumer_secret: credentials.consumer_secret,
access_token_key: credentials.access_token_key,
access_token_secret: credentials.access_token_secret
});
t.stream(
'statuses/filter',
{ track: ['tinyurl.com/gogonc'] }, // can make this a list
function(stream) {
stream.on('data', function(tweet) {
// check for some keywords to do special stuff
// right now the special stuff is all the same
if( tweet.text.indexOf('fly') > 0 )
{
console.log('takeoff');
console.log(tweet.text);
console.log(tweet.user.screen_name);
alertMe();
}
else if( tweet.text.indexOf('land') > 0 )
{
console.log('land');
console.log(tweet.text);
console.log(tweet.user.screen_name);
alertMe();
}
else alertMe();
});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment