Twitter(const char *user_and_passwd);
is in the #include <twitter.h>
and uses the twitter token from the main sketch below.
if I don't get the serial data from a string class, what other way would there be?
the twitter simple post sketch and SerialEvent http://www.arduino.cc/en/Tutorial/SerialEvent
function perfectly independently... when I combine them it all went sour.
need a way to call the serial event to post it to twitter on a set schedule?
Thanks for taking the time...
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>
// from http://arduino-tweet.appspot.com/
// 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, 1, 66 };
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("541602119-Ev6uolkGa72Y8cbvAM9uExRL4HUCGOHFKA5gzyzH");
//from SerialEvent
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
// Message to post
// reserve 200 bytes for the inputString:
void setup()
{
delay(10000);
Ethernet.begin(mac, ip);
// or you can use DHCP for autoomatic IP address configuration.
// Ethernet.begin(mac);
Serial.begin(9600);
inputString.reserve(40); //(200
char msg[] = "(inputString)"; //char
String::toCharArray()
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() {
// print the string when a newline arrives:
if (stringComplete) {
Serial.println(inputString);
// clear the string:
inputString = "";
stringComplete = false;
}
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// delay (10000);
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}