Pages: [1]   Go Down
Author Topic: Ethernet Shield Twitter posting quesion  (Read 478 times)
0 Members and 1 Guest are viewing this topic.
Nova Scotia
Offline Offline
Full Member
***
Karma: 4
Posts: 186
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

USA
Offline Offline
Full Member
***
Karma: 0
Posts: 235
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Austin, TX
Offline Offline
Faraday Member
**
Karma: 63
Posts: 6049
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

count++;
sprintf(msg,"Counter: %d", count);
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Nova Scotia
Offline Offline
Full Member
***
Karma: 4
Posts: 186
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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;
}
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46008
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
char tweet[40];
sprintf(tweet, "Button press %d", buttonPushCounter);
twitter.post(tweet);
Logged

Nova Scotia
Offline Offline
Full Member
***
Karma: 4
Posts: 186
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: