I'm using this example code to use sensors to send tweets.
#include <SPI.h>
#include <Ethernet.h>
//#include <EthernetDNS.h>
#include <Twitter.h>
// our event messages
char b1[]="one";
char b2[]="two";
char b3[]="three";
char b4[]="four";
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xCD, 0x44 }; // create MAC address for ethernet shield
byte ip[] = { 131,128,138,69}; // choose your own IP for ethernet shield
byte gateway[] = {131,128,138,1}; // your network gateway
byte subnet[] = {255,255,255,0}; // your network subnet
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("aaaaaa");
// replace aaaaaaa with your token
void setup()
{
delay(5000);
Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(9600);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
}
void tweet(char msg[])
{
Serial.println("connecting ...");
if (twitter.post(msg))
{
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()
{
if (digitalRead(2)==HIGH)
{ tweet(b1); delay(2000); }
if (digitalRead(3)==HIGH)
{ tweet(b2); delay(2000); }
if (digitalRead(4)==HIGH)
{ tweet(b3); delay(2000); }
if (digitalRead(5)==HIGH)
{ tweet(b4); delay(2000); }
}
It's not working. It compiles fine, but it always says "failed connection code 0". I have the token in in my code and it still isn't working. Any ideas?