diff options
Diffstat (limited to 'libraries/Ethernet/examples/TwitterClient/TwitterClient.ino')
-rw-r--r-- | libraries/Ethernet/examples/TwitterClient/TwitterClient.ino | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino b/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino index f113e17..3587d72 100644 --- a/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino +++ b/libraries/Ethernet/examples/TwitterClient/TwitterClient.ino @@ -14,9 +14,10 @@ version 0019. Circuit: - * Ethernet shield attached to pins 10, 11, 12, 13 + * Ethernet shield attached to pins 10, 11, 12, 13 created 21 May 2011 + modified 9 Apr 2012 by Tom Igoe This code is in the public domain. @@ -35,12 +36,12 @@ IPAddress ip(192,168,1,20); // initialize the library instance: EthernetClient client; -const int requestInterval = 60000; // delay between requests +const unsigned long requestInterval = 60000; // delay between requests char serverName[] = "api.twitter.com"; // twitter URL boolean requested; // whether you've made a request since connecting -long lastAttemptTime = 0; // last time you connected to the server, in milliseconds +unsigned long lastAttemptTime = 0; // last time you connected to the server, in milliseconds String currentLine = ""; // string to hold the text from server String tweet = ""; // string to hold the tweet @@ -51,13 +52,22 @@ void setup() { currentLine.reserve(256); tweet.reserve(150); -// initialize serial: + // Open serial communications and wait for port to open: Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // attempt a DHCP connection: + Serial.println("Attempting to get an IP address using DHCP:"); if (!Ethernet.begin(mac)) { // if DHCP fails, start with a hard-coded address: + Serial.println("failed to get an IP address using DHCP, trying manually"); Ethernet.begin(mac, ip); } + Serial.print("My address:"); + Serial.println(Ethernet.localIP()); // connect to Twitter: connectToServer(); } @@ -114,7 +124,7 @@ void connectToServer() { Serial.println("connecting to server..."); if (client.connect(serverName, 80)) { Serial.println("making HTTP request..."); - // make HTTP GET request to twitter: + // make HTTP GET request to twitter: client.println("GET /1/statuses/user_timeline.xml?screen_name=arduino&count=1 HTTP/1.1"); client.println("HOST: api.twitter.com"); client.println(); @@ -122,3 +132,4 @@ void connectToServer() { // note the time of this connect attempt: lastAttemptTime = millis(); } + |