Pages: [1]   Go Down
Author Topic: Send dynamic tweet strings via the Twitter library  (Read 985 times)
0 Members and 1 Guest are viewing this topic.
Greece
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/* 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:
char msg[] = "Hello, World! I'm Arduino!";

The "post" function of the twitter library
Code:
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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46090
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

twitter.post(buffer);
Logged

Greece
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you PaulS!!

It works OK now!
Logged

Pages: [1]   Go Up
Jump to: