Here is Twitter.h
You can see .post here uses char..
I'm guessing the string needs to be converted somehow to simple text for use?
/*
Twitter.cpp - Arduino library to Post messages to Twitter using OAuth.
Copyright (c) NeoCat 2010-2011. All right reserved.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
// ver1.2 - Use <Udp.h> to support IDE 0019 or later
// ver1.3 - Support IDE 1.0
#ifndef TWITTER_H
#define TWITTER_H
#include <inttypes.h>
#include <avr/pgmspace.h>
#if defined(ARDUINO) && ARDUINO > 18 // Arduino 0019 or later
#include <SPI.h>
#endif
#include <Ethernet.h>
#if defined(ARDUINO) && ARDUINO < 100 // earlier than Arduino 1.0
#include <EthernetDNS.h>
#endif
class Twitter
{
private:
uint8_t parseStatus;
int statusCode;
const char *token;
#if defined(ARDUINO) && ARDUINO < 100
Client client;
#else
EthernetClient client;
#endif
public:
Twitter(const char *user_and_passwd);
bool post(const char *msg);
bool checkStatus(Print *debug = NULL);
int wait(Print *debug = NULL);
int status(void) { return statusCode; }
};
#endif //TWITTER_H
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;
}
}
}
The notation String::toCharArray() means that the String class has a toCharArray() method. You have some instance of the string class, that you need to call the method for:
char dumbTweet[80];
inputString.toCharArray(dumbTweet, 80);
if (twitter.post(dumbTweet))
{
sorry I was doing test with, String::toCharArray()
it does compile without that line.
it does pot the msg, (inputString) as a tweet, just '(inputString)' not the serial data collected.
then it runs in a loop of garbage. twitter does not allow multiple post of the same information.
so it posts once then crashes.
the inputString serial data updates once every second and changes all the time (it's a geiger counter random string) like this:
CPS, 0, CPM, 3, uSv/hr, 0.0
CPS, 2, CPM, 29, uSv/hr, 0.16, SLOW
CPS, 2, CPM, 31, uSv/hr, 0