Go Down

Topic: Send dynamic tweet strings via the Twitter library (Read 1 time) previous topic - next topic

Giannis

Hello everyone!

I use the Twitter library that supports OAuth http://www.arduino.cc/playground/Code/TwitterLibrary and i want to post the values from a temperature sensor along with some additional text, in the same tweet.

As such, a tweet should contain a static text as well as the dynamic temperature value taken from the temp sensor.

So here is my question:

How can i concatenate a static text with a dynamic value in order to send the entire string via a single tweet ?

I test the following code taken from the Twitter library page:

Code: [Select]
/* Post a simple message to Twitter  */
#include <Ethernet.h>
#include <Twitter.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };
byte gateway[] = { 10, 0, 0, 1 };
byte subnet[] = { 255, 255, 0, 0 };

Twitter twitter("YOUR-TOKEN");
char msg[] = "Hello, World! I'm Arduino!";

void setup()
{
 Ethernet.begin(mac, ip, gateway, subnet);
 Serial.begin(9600);

 delay(1000);

 Serial.println("connecting ...");
 if (twitter.post(msg)) {
   int status = twitter.wait();
   if (status == 200) {
     Serial.println("OK.");
   } else {
     Serial.print("failed : code ");
     Serial.println(status);
   }
 } else {
   Serial.println("connection failed.");
 }
}

void loop()
{
}


In the example code above, the string array variable contains a static string
Code: [Select]
char msg[] = "Hello, World! I'm Arduino!";

The "post" function of the twitter library
Code: [Select]
twitter.post(msg) expects a const char *message variable.


What do i need to do to concatenate a static text and a dynamic value ?

Any help to the right direction is much appreciated!

John

PaulS

Something like this:
Code: [Select]
char buffer[80];
sprintf(buffer, "Current temp: %d", tempC);

twitter.post(buffer);

Giannis


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy