Twitter library for the Ethernet shield

Hi all, I wrote a small library to post messages to Twitter using the Ethernet shield. (works on 0015.)

The library is available here: http://dl.getdropbox.com/u/755814/Arduino/Library-Twitter.zip

This library includes an simple example, that shows usage of this library.
Example code is like this:

#include <Ethernet.h>
#include <Twitter.h>
Twitter twitter("YourID:Password"); // Initialize the library

void setup() {
   Ethernet.begin(...);             // init Ethernet
   delay(1000);
   twitter.post("Hello,World!");    // tweet! (returns true if succeeded.)
   twitter.wait();                  // wait for response, (returns status code)
   ...
}

No MIME encoding stuff by hand is needed. Isn't it easy?

One word : WOW!

nice work NeoCat this library will sure come in handy

Cheers Rob,

Now I can put arduinos around my house and detect what room i am and send tweets whenever i enter a room. GREAT, Lets go annoy people!

NeoCat, well done.
Did you put it on the arduino's wiki?
I think it could be a great addon.

Thanks for comments! :wink:

Did you put it on the arduino's wiki?

Here is the wiki page: http://www.arduino.cc/playground/Code/TwitterLibrary .

This library is awesome! It makes tweeting super easy.

Question: Is there a way to change the application twitter reports?

Currently when I tweet, it says "5 minutes ago from web".

It'd be neat to be able to change the "from web" to an application/system name.

Thakns!

Question: Is there a way to change the application twitter reports?

Currently, No way. Twtter is not accepting new application names now.

This library uses BASIC authentication to post a message to twitter, because it's very simple and suitable for Arduino.
However, Twitter is now going to move to a new and complex authentication mechanism named OAuth.
So, they are already not accepting new application names that uses BASIC authentication.

See below for details:
http://apiwiki.twitter.com/FAQ#HowdoIget“fromMyApp”appendedtoupdatessentfrommyAPIapplication

Oh, great: embedded Twitter.

Next thing ya know, we'll be getting broadcast updates from Britney Spears' underwear drawer whenever she ...

Oh, wait: I guess we won't.

Seriously, though: congratulations on an impressive hack.

Ran

NeoCat:

I think I found a bug in your library (or a bug in my usage). I'm not sure what the right way to contact you is.

The Twitter::checkStatus(void) method doesn't always return, i'm not sure why that is. When I call it from within my setup() I successfully post to twitter but I get hung waiting for status. I think something may go wrong while looping on checkStatus() and you can reach a state where it loops forever.

Have you seen this issue?

How I'm using the library:

if ( twitter.post(msg) ) {
int status = twitter.wait();
if ( status == 200) {
Serial.println("Message Sent Successfully!");
}
else {
Serial.print("failed : code ");
Serial.println(status);
}
}
else {
Serial.println("connectoin failed.");
}

I never get a status message or any of my logging that comes after this code.

Thanks!

Hmm.. I've not seen that problem yet, but possibly because of HTTP KeepAlive connection.
If so, it may be fixed by adding

client.println("Connection: close¥n");

to Twitter::post function in Twitter.cpp line 56 in the Library.

Im not sure if this counts as a bug or not because it should be obvious but for me it wasnt. You need to .stop(and .flush) the client after each post has been completely submitted or on the subsequent post twitter.post will fail. Otherwise this is a great library and once i figure out something cool to do with it, it will be even better

Thanks for your comment. > knuckles904

I fixed the bug on multiple posts and released as version 1.0.1 :
http://www.arduino.cc/playground/Code/TwitterLibrary

I also added a sample sketch to post a message via Arduino's serial port.

Be advised that this library does NOT tweet from your Arduino. It sends your tweet to NeoCat's website, which then tweets it from there. You are obliged to hand over your Twitter ID and password to the website for it to work. Use at your own discretion.

Doh - maybe make an arduino_tweet account to tweet from for the arduino, and keep your actual separate.