2

I was given a Intel Edison, with an integrated WiFi board, to mess around with and read some tweets. So far, I've downloaded the Twitter4j core .jar (version 4.0.2, latest as of today), and set up the Arduino-Processing communication. Every time I try to execute a query (search tweets by hashtags, for instance) it says Error: api.twitter.com. I have verified that I am connected to the network, and that the network has no proxy issues with Twitter. It stops working right after println("pre query"). Any ideas?

My Arduino sketch is as follows:

#include <WiFi.h>
#include <WiFiUdp.h>

#include <Ethernet.h>
int ledPin=13;
char ssid[] = "OnePlus One";     // the name of your network
char pass[] = "hugomario";    // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status
void setup()
{
  Serial.println("inside setup");
  pinMode(ledPin, OUTPUT);
  Serial.begin(115200);  
  Serial.println("\nconnecting ...");
  status = WiFi.begin(ssid, pass);

  // if you're not connected, stop here:
  if ( status != WL_CONNECTED) { 
    Serial.println("Couldn't get a wifi connection");
    while(true);
  } 
  // if you are connected :
  else {
      Serial.print("Connected to the network");
  }
}

void loop()
{
  Serial.println("\ninside loop");
  while(Serial.available()==0);
  int val = Serial.read()- '0';  
  Serial.println(val);
  if(val == 1) 
  {
    Serial.println("LED IS ON");
    digitalWrite(ledPin,HIGH);
    delay(1000);
    digitalWrite(ledPin,LOW);    
  }
  else
  {
    Serial.println("LED IS OFF");
    digitalWrite(ledPin,LOW);
  }
}

My Processing sketch:

    import processing.serial.*;

Serial port;

static String OAuthConsumerKey="kxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxO";
static String OAuthConsumerSecret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
static String AccessToken= "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
static String AccessTokenSecret="Mxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5";

String[] searchedTweets = new String[50];
ConfigurationBuilder cb = new ConfigurationBuilder();
Twitter twitter;
void setup() {
  //Set the size of the stage, and the background to black.
  size(200, 200);
  background(0);
  smooth();
  port = new Serial (this, "COM5", 115200);
  connectTwitter();
}

void connectTwitter() {
  cb.setOAuthConsumerKey(" kxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxO ");
  cb.setOAuthConsumerSecret(" kxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxO ");
  cb.setOAuthAccessToken("124767053- kxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxO ");
  cb.setOAuthAccessTokenSecret(" kxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxO ");
  cb.setHttpConnectionTimeout(100000);
  twitter = new TwitterFactory(cb.build()).getInstance();
  println("is twitter null? ");
  println(twitter==null);
  getSearchTweets();
}

void getSearchTweets() {
  String queryStr = "#yolo";
  try {
    println("inside try");
    Query query = new Query(queryStr);
    // query.setRpp(10); //10 out of 100 results
    query.count(10);
    println("pre query");
    QueryResult result = twitter.search(query);
    println("post query");
    ArrayList tweets = (ArrayList) result.getTweets();
    println("tweets size= "+tweets.size());
    for (int i=0; i<tweets.size (); i++) {
      /*
      Tweet t = (Tweet) tweets.get(i);
       String user = t.getFromUser();
       String msg = t.getText();
       Date d = t.getCreatedAt();
       */
      Status t = (Status) tweets.get(i);
      String user = t.getUser().getName();
      String msg = t.getText();
      port.write('1');
      searchedTweets[i] = user +": "+msg;
      println(searchedTweets[i]);
    }
  } 
  catch (TwitterException e) {    
    println("Error: " + e.getMessage());
    port.write('0');
  }
}

void delay(int delay){
  int time = millis();
  while(millis()-time <= delay);
}
George Profenza
  • 50,687
  • 19
  • 144
  • 218
Hugo M. Zuleta
  • 572
  • 1
  • 13
  • 27
  • 1
    You have left in some of your api keys. – Jonathan Jan 20 '15 at 10:45
  • No problem. It might be worth revoking them as anybody can view revisions made to the question. – Jonathan Jan 20 '15 at 10:51
  • Just did that. Thanks again. Do you have any ideas, by the way? – Hugo M. Zuleta Jan 20 '15 at 10:52
  • 2
    Can you post full error? Also can you share the twitter4j package version you are using. – mbaxi Jan 20 '15 at 10:59
  • I'm not at work yet, so I don't have my Edison with me. I'll post the full error on my answer asap. One of the errors it shows is: `exceptionCode=[506c3b98-105d1087 63e3f388-fb44fc20]`. I've tried also setting a timeout for the `ConfigurationBuilder`, and then it says `Connection timed out: connect`. – Hugo M. Zuleta Jan 20 '15 at 11:10
  • 1
    You could actually do all the processing part on the actual edison. You have Python you could use to do the twitter query and pass the data to your sketch via a udp socket for example. You've got node.js preinstalled, and there's a [node.js twitter package](https://www.npmjs.com/package/node-twitter-api) and so on. Also you should look into [Temboo](https://www.temboo.com/arduino/others/) and their [Twitter Choreo](https://www.temboo.com/library/Library/Twitter/), which should allow you to do the whole thing on the Arduino/Quark side – George Profenza Jan 20 '15 at 12:46
  • So, I implemented a python script, tried it in a different network, and it says the following `twitter.update_status(status='SECURITY BREACH!#EdisonAntiBurglar') twython.exceptions.TwythonError: ('Connection aborted.', gaierror(-2, 'Name or service not known'))` Both when I try to post and read tweets, using the Twython libraries. Should I try connecting to a WiFi network directly on the script? Or should I assume that connecting to a network using configure_edison --setup is enough? – Hugo M. Zuleta Jan 22 '15 at 02:52
  • 1
    ```configure_edison --wifi``` should be enough. make sure you are connected to the internet though, so ping a server like twitter.com from your edison to test. – George Profenza Jan 25 '15 at 22:18
  • @GeorgeProfenza It definitely doesn't connect to the Internet, but we checked and it does connect to the network, regardless if connectes to our enterprise or home networks. We decided to give up and start over with a spare Galileo we had. Should I write this as an answer? – Hugo M. Zuleta Jan 25 '15 at 22:20
  • that is strange :/ it get's an IP from the router but it just can't access anything outside the local network ? perhaps also check on the Intel Communities for similar issues. – George Profenza Jan 25 '15 at 22:28

0 Answers0