I was wondering if it was possible to use an Arduino as a webserver and a twitter client (using http://arduino.cc/en/Tutorial/TwitterClient)that tweets data at the same time.
When I mixed the code it didn't work and would crash or fail when getting an IP address from DHCP. Has anyone used both of these libraries in the same sketch before or does anyone know what could be done so they do work?
It was the code from the two libraries. The rest of the code in the sketch is for various sensors for a weather station.
The web server code is the standard code in the examples menu in the Arduino IDE (webserver.ino)
This is the Twitter code from the SimpleTwitter library
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>
// The includion of EthernetDNS is not needed in Arduino IDE 1.0 or later.
// Please uncomment below in Arduino IDE 0022 or earlier.
//#include <EthernetDNS.h>
// 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("847996760-WgdrXp8qI8ENuKyM4h2kLyraZQ2G4BOxBl8fYpIH");
// Message to post
//char msg[] = "Weather Station Tweet Test";
int count=0;
void setup(){
Serial.begin(9600);
}
void loop(){
delay(60000);
//Ethernet.begin(mac, ip);
// or you can use DHCP for automatic IP address configuration.
Ethernet.begin(mac);
count++;
Serial.print(count);
// Message to post
String countStr = String(count);
String tweet = "Count: " + countStr;
char charTweet[140];
tweet.toCharArray(charTweet, 140);
Serial.println("connecting ...");
if (twitter.post(charTweet)) {
// 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.");
}
}