Again, some good ideas here. I am attaching both code fragments - the one that works and the one that fails.
Here's what works (the vanilla Twitter Library sample code):
// Ethernet Shield Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
byte ip[] = { 192, 168, 2, 250 };
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("YOUR-TOKEN-HERE");
// Message to post
char msg[] = "Hello, World! I'm Arduino!";
void setup()
{
delay(1000);
Ethernet.begin(mac, ip);
// or you can use DHCP for automatic IP address configuration.
// Ethernet.begin(mac);
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()
{
}
..and here's what isn't working:
// initialize Twitter object
Twitter twitter(TOKEN);
DhcpState ipState = DhcpStateNone; // a variable to store the DHCP state
void setup() {
serial = getSerial(); // create or obtain a serial number from EEPROM memory
counter = getCounter(); // create or obtain a tweet count from EEPROM memory
// Ethernet Shield Settings
byte mac[] = { 0x31, 0x13, 0x31, 0x13, 0x31, 0x13 }; // use same MAC as Twitter examples
...
Serial.begin(9600); // set the data rate for the hardware serial port
...
// start Ethernet
EthernetDHCP.begin(mac, true); // start ethernet DHCP in non-blocking polling mode
...
dhcpCheck(); // check and update DHCP connection
if (millis() % 60000 == 0 && ipState != DhcpStateLeased && ipState != DhcpStateRenewing) {
blinkLED(COMMLED,1,30); // quick blnk of COMM led if there's no ip address
...
posttweet(URGENT_WATER); // Post it to Twitter
...
}
// post a tweet
void posttweet(char* msg) {
digitalWrite(COMMLED,HIGH); // light the Communications LED
// assemble a string for Twitter, appending a unique ID to prevent Twitter's repeat detection
char *str1 = " [";
char *str2;
str2= (char*) calloc (5,sizeof(char)); // allocate memory to string 2
itoa(serial,str2,16); // turn serial number into a string
char *str3 = "-";
char *str4;
str4= (char*) calloc (5,sizeof(char)); // allocate memory to string 4
itoa(counter%10000,str4,10); // turn message counter into a string
char *str5 = "]";
char *message;
// allocate memory for the message
message = (char*) calloc(strlen(msg) + strlen(str1) + strlen(str2) + strlen(str3) + strlen(str4) + strlen(str5) + 1, sizeof(char));
strcat(message, msg); // assemble (concatenate) the strings into a message
strcat(message, str1);
strcat(message, str2);
strcat(message, str3);
strcat(message, str4);
strcat(message, str5);
Serial.println("connect...");
if (ipState == DhcpStateLeased || ipState == DhcpStateRenewing) {
Serial.println("Lease OK");
if (twitter.post(message)) { // attempt to tweet the message
int status = twitter.wait(&Serial); // receive the status + DEBUG
digitalWrite(COMMLED,LOW); // turn off the communications LED
delay(100);
if (status == 200) {
Serial.println("tweet ok");
}
else {
Serial.print("tweet fail: code ");
Serial.println(status); // if tweet fails, print the error code
blinkLED(COMMLED,2,100); // ...and blink the communications LED twice
}
counter++; // iterate the message counter
setCounter(counter); // store the message counter in EEPROM memory
}
else {
Serial.println("connect fail"); // if connection fails entirely,
blinkLED(COMMLED,4,100); // ...blink the communications LED 4 times
}
}
else {
Serial.println("DHCP fail"); // if connection fails entirely,
blinkLED(COMMLED,6,100); // ...blink the communications LED 4 times
}
free(message); // free the allocated string memory
free(str2);
free(str4);
}
Again, as in the first example, I am seeing valid IP, gateway and DNS addresses and can ping the Ethernet shield. But somehow I am not getting through to the Twitter API via the Neocat proxy site (http://arduino-tweet.appspot.com/). One thought I just had was that maybe the "EthernetDHCP.begin()" statement has been deprecated in favor of simply "Ethernet.begin() as DHCP capability has been folded into IDE 1.0.
As before, any help is appreciated!