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);
}