Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wifi error emission is messed up #102

Open
Frijol opened this issue Oct 18, 2014 · 0 comments
Open

Wifi error emission is messed up #102

Frijol opened this issue Oct 18, 2014 · 0 comments

Comments

@Frijol
Copy link
Member

Frijol commented Oct 18, 2014

➜  Twitter-Sumobot git:(master) ✗ tessel run index.js
TESSEL! Connected to TM-00-04-f000da30-005c4f48-422c2586.
INFO Bundling directory /Users/frijol/Twitter-Sumobot
INFO Deploying bundle (442.50 KB)...
INFO Running script...
Connecting...
TypeError: Uncaught, unspecified "error" event.
    at js_new (src/colony/lua/colony-init.lua:494)
    at emit (src/colony/lua/colony-node.lua:703)
    at _f (builtin/wifi-cc3000.js:136)
    at <anonymous> (builtin/wifi-cc3000.js:40)
    at connect (builtin/wifi-cc3000.js:40)
    at checkConnection (/app/index.js:23)
    at res (/app/index.js:10)
    at run (src/colony/lua/colony-node.lua:1082)
    at require (src/colony/lua/colony-node.lua:1077)
    at res (/_start.js:4)

Code:

// Get Tessel connected to Wifi
var tessel = require('tessel');
var wifi = require('wifi-cc3000');
var wifiSettings = {
  ssid: 'Gaumenkitzel',
  password: 'Gaumenkitzel',
  timeout: 40
};

checkConnection();

wifi.on('disconnect', function () {
  console.log('Disconnected.');
  checkConnection();
});

function checkConnection () {
  if (wifi.isConnected()) {
    console.log('Connected.');
    main();
  } else {
    console.log('Connecting...');
    wifi.connect(wifiSettings, function (err, res) {
      if(err) {
        console.log('Error connecting:', err);
      }
      checkConnection();
    });
  }
}

function main () {
  // Set up Twitter
  console.log('Setting up Twitter...');
  var twitter = require('twitter');
  var util = require('util');
  var twit = new twitter({
    consumer_key: 'O7oc0pvsZn4xjgcuHuYdX4FaC',
    consumer_secret: 'iJYuHFz2sD46Nvk3mcwzX8uih14aEAMgVWdWoR59nx8v6Zl7ZX',
    access_token_key: '2529232909-luARGU89K4CKFMvfzBjCgG6ubefzDkdDWkSB85i',
    access_token_secret: 'GXQfuzvGdjLEs3t1HEYfhQ9x9bdBcSBVXjBkbRgwYlOE0'
  });
  tessel.led[0].output(1);
  console.log('Twitter is all set up.');

  // Set up servos
  var servoLib = require('servo-pca9685');
  var servo = servoLib.use(tessel.port['A']);

  // When servo module is ready...
  servo.on('ready', function () {
    console.log('Servo module ready. Listening for tweets...');
    tessel.led[1].output(1);
    // Stream tweets that mention the keyword
    twit.stream('statuses/filter', {track:'#Tesselbot'}, function(stream) {
      stream.on('data', function(data) {
        var tweet = data.text;
        console.log(tweet);
        if (tweet.indexOf('forward') > 0) {
          forward();
        } else if ( tweet.indexOf('back') > 0 ) {
          back();
        } else if (tweet.indexOf('right') > 0 ) {
          right();
        } else if (tweet.indexOf('left') > 0) {
          left();
        } else {
          // Anything not an explicit command makes it stop
          stop();
        }
      });
      stream.on('error', function (err) {
        console.log('Twitter error:', err);
      });
    });
  });
}

// Motion functions
function forward() {
  console.log('Moving: forward');
  servo.move(1, 1);
  servo.move(2, 0);
}

function back() {
  console.log('Moving: back');
  servo.move(1, 0);
  servo.move(2, 1);
}

function right() {
  console.log('Moving: right');
  servo.move(1, 1);
  servo.move(2, 1);
}

function left() {
  console.log('Moving: left');
  servo.move(1, 0);
  servo.move(2, 0);
}

function stop() {
  console.log('Stopping.');
  servo.move(1, 0.5);
  servo.move(2, 0.5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant