Go Down

Topic: Ethernet Shield Twitter posting quesion (Read 595 times) previous topic - next topic

0miker0

I have twitter posts working on my Ethernet Shield using the simple post example. My goal is to have a loop running so it will tweet a number for each button press.

char msg[] = "button Tweet"; //Works

char msg[] = {"Count'i'"}; 
char msg[] = {'Count"}; 
Do not work. I'm not sure if I have to convert a number to a char or not.

No idea,
Mike

mkwired

You're example code doesn't make any sense.  Post the real code then we may be able to help.

James C4S

count++;
sprintf(msg,"Counter: %d", count);
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

0miker0

I have twitter updating the number with each button press. Right now it just tweets a number. How can I have a bit of text in front of the number? Something like. Button press 1, Button Press 2?

For the line:twitter.post(temp1);
I have tried things like twitter.post("Button press",temp1);  like I would on an LCD but no luck here.

#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>

const int buttonPin = 9;     // the pushbutton pin
//int buttonState = 0;         // previous state of the button

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

// 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, 195 };

// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("my token");

int temp2;

void setup()
{
  delay(1000);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
 
  //Ethernet.begin(mac, ip);
  // or you can use DHCP for autoomatic IP address configuration.
  Ethernet.begin(mac);
  Serial.begin(9600);
 
  Serial.println("connecting ...");
}

void loop()
{
  int j=0;
  char temp1[7];

  buttonState = digitalRead(buttonPin);

  if (buttonState != lastButtonState)
  {
    if (buttonState == HIGH)
    {
     buttonPushCounter++;
    }
   
    itoa (buttonPushCounter,temp1,10);
    twitter.post(temp1);    //This is where is the number is tweeted

    // 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.");
  }
   
  //delay(100);
  lastButtonState = buttonState;
}

PaulS

Quote
How can I have a bit of text in front of the number? Something like. Button press 1, Button Press 2?

Put it there.

Quote
For the line:twitter.post(temp1);
I have tried things like twitter.post("Button press",temp1);  like I would on an LCD but no luck here.

Of course not.

Code: [Select]
char tweet[40];
sprintf(tweet, "Button press %d", buttonPushCounter);
twitter.post(tweet);

0miker0

Thank You! That worked perfectly. I'll have to read up on the sprintf function. I would never have got that on my own.

Go Up