aboutsummaryrefslogtreecommitdiff
path: root/libraries/Ethernet/examples/TwitterClient
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2012-06-27 13:51:16 +0200
committerCristian Maglie <c.maglie@bug.st>2012-06-27 13:51:16 +0200
commit2d2050eabeaff7109ba89fdd0100556c981cf373 (patch)
tree1f6d9725b59aa02e5400a8117eeec3206d88047d /libraries/Ethernet/examples/TwitterClient
parent324023a67afd1691f12ead4388d7cdf1a9d1a6ef (diff)
parent31c24577835b0a9c7a1291ffbda1b61d96818511 (diff)
Merged master
Diffstat (limited to 'libraries/Ethernet/examples/TwitterClient')
-rw-r--r--libraries/Ethernet/examples/TwitterClient/TwitterClient.ino21
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();
}
+