Tweet with ENC28J60 , Message and random number

Hi All

I am try to add random number with the tweet message but i am failed to add this function by use analog read to the message can any one help be with code ...

#include <EtherCard.h>

// OAUTH key from http://arduino-tweet.appspot.com/
#define TOKEN   ""

// ethernet interface mac address, must be unique on the LAN
byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

const char website[] PROGMEM = "arduino-tweet.appspot.com";

static byte session;

byte Ethernet::buffer[700];
Stash stash;

static void sendToTwitter () {
  Serial.println("Sending tweet...");
  byte sd = stash.create();



  const char tweet[] = "My Message here"; / i want to add analog reading to my message every time tweet.
  stash.print("token=");
  stash.print(TOKEN);
  stash.print("&status=");
  stash.println(tweet);
  stash.save();
  int stash_size = stash.size();

  // Compose the http POST request, taking the headers below and appending
  // previously created stash in the sd holder.
  Stash::prepare(PSTR("POST http://$F/update HTTP/1.0" "\r\n"
    "Host: $F" "\r\n"
    "Content-Length: $D" "\r\n"
    "\r\n"
    "$H"),
  website, website, stash_size, sd);

  // send the packet - this also releases all stash buffers once done
  // Save the session ID so we can watch for it in the main loop.
  session = ether.tcpSend();
}

void setup () {
  Serial.begin(57600);
  Serial.println("\n[Twitter Client]");

  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println(F("Failed to access Ethernet controller"));
  if (!ether.dhcpSetup())
    Serial.println(F("DHCP failed"));

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  

  if (!ether.dnsLookup(website))
    Serial.println(F("DNS failed"));

  ether.printIp("SRV: ", ether.hisip);

  sendToTwitter();
}

void loop () {
  ether.packetLoop(ether.packetReceive());

  const char* reply = ether.tcpReply(session);
  if (reply != 0) {
    Serial.println("Got a response!");
    Serial.println(reply);
  }
}

Thank
Zeem

I am try to add random number with the tweet message

I don't see that.

  stash.print("token=");
  stash.print(TOKEN);
  stash.print("&status=");
  stash.println(tweet);
  stash.save();

No random number. No use of analogRead(), either.

PaulS:
I don't see that.

  stash.print("token=");

stash.print(TOKEN);
  stash.print("&status=");
  stash.println(tweet);
  stash.save();



No random number. No use of analogRead(), either.

i want my tweet to be different every time cos twitter reject's the identical content so i think about the random message number to add every time arduino tweet.

i want my tweet to be different every time cos twitter reject's the identical content so i think about the random message number to add every time arduino tweet.

I know that you do, and I know that that stupid system rejects duplicate tweets.

But, you claimed that you tried to add a random number, but the code you posted says that you didn't.

What have you tried?

It is the value in tweet that needs to change, but it can't because there is no more room AND it is const(ant).

const char website[] PROGMEM = "arduino-tweet.appspot.com";
int analogzero;
static byte session;

byte Ethernet::buffer[700];
Stash stash;

static void sendToTwitter () {
  Serial.println("Sending tweet...");
  byte sd = stash.create();
  analogzero=analogRead(A0);
  char tweet[]="MY Message ";
  stash.print("token=");
  stash.print(TOKEN);
  stash.print("&status=");
  stash.println(tweet),analogzero;
  stash.save();
  int stash_size = stash.size();

  // Compose the http POST request, taking the headers below and appending
  // previously created stash in the sd holder.
  Stash::prepare(PSTR("POST http://$F/update HTTP/1.0" "\r\n"
    "Host: $F" "\r\n"
    "Content-Length: $D" "\r\n"
    "\r\n"
    "$H"),
  website, website, stash_size, sd);

  // send the packet - this also releases all stash buffers once done
  // Save the session ID so we can watch for it in the main loop.
  session = ether.tcpSend();
}

I try this on it's compile no problem but not working ..

i try by another way which as below also compile no problem not working

int analogZero;
char tweet[140];
static byte session;

byte Ethernet::buffer[700];
Stash stash;

static void sendToTwitter () {
  Serial.println("Sending tweet...");
  byte sd = stash.create();

  stash.print("token=");
  stash.print(TOKEN);
  stash.print("&status=");
  stash.println(tweet);
  stash.save();
  int stash_size = stash.size();

  // Compose the http POST request, taking the headers below and appending
  // previously created stash in the sd holder.
  Stash::prepare(PSTR("POST http://$F/update HTTP/1.0" "\r\n"
    "Host: $F" "\r\n"
    "Content-Length: $D" "\r\n"
    "\r\n"
    "$H"),
  website, website, stash_size, sd);

  // send the packet - this also releases all stash buffers once done
  // Save the session ID so we can watch for it in the main loop.
  session = ether.tcpSend();
}

void setup () {
  Serial.begin(57600);
  Serial.println("\n[Twitter Client]");

  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println(F("Failed to access Ethernet controller"));
  if (!ether.dhcpSetup())
    Serial.println(F("DHCP failed"));

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  

  if (!ether.dnsLookup(website))
    Serial.println(F("DNS failed"));

  ether.printIp("SRV: ", ether.hisip);

  sendToTwitter();
}

void loop () {
  
  ether.packetLoop(ether.packetReceive());
  analogZero=analogRead(A0);
 sprintf(tweet, "my message: %d. @username.", analogZero);

delay(60000);
  }

any advice....

  stash.println(tweet),analogzero;

What do you think that this code is doing? Abusing the comma operator that way hardly makes sense.

i'am not sure what i did ,

I TRYING TO APPLY THAT LIBRARY TO MY CODE

https://code.google.com/p/tinkerit/wiki/TrueRandom

Do you want to append a random number to the tweet? Or an analog pin reading? Or both? No more tap dancing. Answer the questions.

all i want that random number to be with my tweet message in order to get pass of identical message .

what ever it takes, reading analog pin and add to message or using random library.

  char uselessTweet[30];
  sprintf(uselessTweet, "Useless tweet #%d", random(0, 10000));

  stash.println(uselessTweet);

thanks so much paul yes give random number but only one number which is 6807 .

then i wait one min. there nothing so , i change the message from "Useless tweet"

"NOT working " i received the message with same number 6807.

any idea..

any idea..

The "random" number generator on the Arduino always returns the same sequence of values, unless you call randomSeed(). This is actually useful for testing purposes.

If you are not getting the second and subsequent tweets, you need to determine whether they are being blocked by twitter.

Serial.print() the string uselessTweet to see whether the random number actually changes. It should. If it does, the messages are still be blocked by twitter (and I wouldn't blame them).