#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(9,8,7,6,5,4); //School's Arduino
byte mac[] = {0xA2, 0xB1, 0x9A, 0xD2, 0xB3, 0xC5}; //mac address(do not change)
byte ip[] = {10,2,XX,XX}; //static IP for school
//byte ip[] = {192,168,X,XX}; //Michael Street IP
byte server[] = {128,242,240,20}; // Twitter
char serverName[] = "api.twitter.com"; // twitter URL
char tweet[140];
EthernetClient client;
TextFinder finder(client);
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac,ip);
Serial.println("Connecting..");
}
void loop()
{
client.stop();
client.flush();
checktweet();
checkweather();
delay(80000);
}
this is one of the segments i implement the twitter portion using a get HTTP
void checktweet()
{
{
if (client.connect(serverName,80)) {
client.println("GET http://www.twitter.com/statuses/user_timeline/XXXXXXX.rss HTTP/1.0");
client.println();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Connected");
lcd.setCursor(0,1);
lcd.print("to server!!!");
delay(1500);
}
else {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Connection");
lcd.setCursor(0,1);
lcd.print("failed...");
delay(1500);
return;
}
if (client.connected()) {
// get the last tweet by simply parsing the item and title tags
if((finder.find("<item>")&&(finder.getString("<title>","</title>",tweet,140)!=0)))
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Retrieving");
lcd.setCursor(0,1);
lcd.print("Tweet...");
delay(2000);
lcd.clear();
lcd.print(tweet);
for (int j=0; j<2; j++) {
// first part of the tweet
lcd.clear();
lcd.setCursor(0,0);
for (int i=15; i<35; i++)
lcd.print(tweet[i]);
lcd.setCursor(0,1);
for (int i=35; i<55; i++)
lcd.print(tweet[i]);
}
}
else
lcd.println("Could not find tweet");
}
else {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Could not retrieve");
lcd.setCursor(0,1);
lcd.print("tweet...");
delay(2000);
return;
}
delay(1);
client.stop();
client.flush();
//delay(40000); // wait a minute before next update
/* lcd.clear();
lcd.setCursor(0,0);
lcd.print("Refreshing");
lcd.setCursor(0,1);
lcd.print("connection");
delay(2000);*/
}
}
at home, DHCP using the static IP i have is fine. but in school with all the proxy/firewall and whatnot it's almost impossible to connect to it except via mobile broadband.. such a bother!
cheers mate!
p.s. sorry i can't give my full code cus this is my fyp and i don't want someone to nick it off here. but it's just similar to the checktweet segment.