2

我得到了一个带有集成 WiFi 板的 Intel Edison 来处理和阅读一些推文。到目前为止,我已经下载了 Twitter4j 核心 .jar(版本 4.0.2,截至今天最新),并设置了 Arduino-Processing 通信。每次我尝试执行查询(例如,通过主题标签搜索推文)时,它都会显示Error: api.twitter.com. 我已验证我已连接到网络,并且网络与 Twitter 没有代理问题。它在 之后立即停止工作println("pre query")。有任何想法吗?

我的 Arduino 草图如下:

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

我的处理草图:

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

0 回答 0