Hey all,
I'm not sure if this has been done before but I've been doing some work with the newly-released Arduino WiFi shield; it doesn't have much user-generated content available for it at this time. I needed to get the Arduino to tweet over WiFi as a part of my project, and didn't want to bother getting into OAuth, so I did a simple modification of the Twitter Library already present for the Ethernet Shield to port it over. Hope it helps someone out.
Installation:
- Install the Arduino Twitter Library at Arduino Playground - Twitter Library
- Overwrite the Twitter.h and Twitter.cpp files within the newly installed library with the attached files.
- Enjoy.
Note that at this rudimentary stage this will make your twitter library no longer compatible with the Ethernet Shield. To restore, just re-install.
Sample code to tweet, note you will still need to grab a token as was needed with the original library.
#include <SPI.h> // needed in Arduino 0019 or later
#include <WiFi.h>
#include <Twitter.h>
char ssid[] = "Network Name";
char pass[] = "Secret Password";
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("Your Token Here!");
// Message to post
char msg[] = "Automatic tweet!";
void setup()
{
delay(1000);
WiFi.begin(ssid, pass);
// or you can use DHCP for automatic IP address configuration.
// WiFi.begin(mac);
delay(10000);
Serial.begin(9600);
Serial.println("connecting ...");
if (twitter.post(msg)) {
// Specify &Serial to output received response to Serial.
// If no output is required, you can just omit the argument, e.g.
// int status = twitter.wait();
int status = twitter.wait(&Serial);
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}
void loop()
{
}
Twitter.h (520 Bytes)
Twitter.cpp (1.59 KB)