Made my own TwitterClient and I think it's better than the example one

Hi,

First just try the code as is, but manually change ip, mask, gw and dns (the code doesn't use DHCP). You should know this things from your own network.

byte ip[] = { 192,168,1,10}; //change this
byte subnet[] = {255,255,255,0}; //change this
byte gateway[] = {192,168,1,1}; //change this
byte dns[] = {192,168,1,1}; //change this

ip: pick a free ip in your network
subnet: take the same one from your computer
gateway: take the same one from your computer
dns: take the same one from your computer

juest leave the mac address as is.

once this is running, you can continue to get the message on your LCD

Hi JO3RI,

I've made amendments to the program but i received this error.

'byte dns []' redeclared as different kind of symbol

could my version of Ethernet.h library be different?

i tried commenting the byte dns line but nothing showed up on the LCD.

Appreciate your advise!

cheers!

Hi again,

strange thing:

'byte dns []' redeclared as different kind of symbol

I just uploaded the code (you find in the very beginning of this topic), and uploaded it to my arduino ethernet and arduino IDE 1.0

guess what, it just works :~

Did you try to use dhcp any way on top of my code? (it seems dns got declared more then once)

if you can't find the problem, just post your code here, and I'll cross check it.

Hi again.

This morning I tried Arduino IDE 1.0.1 and guess what ... yep:

'byte dns []' redeclared as different kind of symbol'

So, it must be something with Arduino IDE 1.0.1, but I don't know what. I'll try to figure it out, bur for now, you beter use Arduino IDE 1.0.0 http://arduino.googlecode.com/files/arduino-1.0-windows.zip

Very nice project. I've used the twitter example code you text me on a button press. Would come in handy as some type of alarm of I'm away. Getting it working on the new wifi shield would be nice but its pricey.

Mike

Hey JO3RI,

Thanks for all your help! i've got the program running on the 1.0 IDE. However nothing shows up on my screen on the board. Suspect its either the connection setup that's incorrect, IP/gateway/dns that's wrong, or the fact that my account is set to private that is the problem.

Just to check, my board is connected via USB to the computer, i've got an adapter connected to the power and my Ethernet cable connects it straight from the wall socket. How do you check for the IP/gateway/dns info then? i'm running a mac here. what will happen if you enter a wrong value for the above info? will anything show up on the LCD? right now it's just black pixels on the screen.

i'll try setting my account to public and trying once again.

this is the code i used. edited from yours.

//--------------------------------//
#include <LiquidCrystal.h>

//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x00, 0x00, 0x90, 0xA0, 0xB0, 0xC0 };
byte ip[] = { 192,168,1,20}; //change this
byte subnet[] = {255,255,255,0}; //change this
byte gateway[] = {192,168,0,1}; //change this
byte dns[] = {192,168,0,1}; //change this
EthernetClient client;
String TwitterName ="kennethbeatle"; //change this to your own twittername, or follow me :wink:
char tweet[140];
String SearchString ="";
byte charsize;
char serverName[] = "api.twitter.com"; // twitter URL

void setup() {
// initialize serial:
Serial.begin(9600);
// attempt a DHCP connection:
Ethernet.begin(mac, ip, dns, gateway, subnet);
// connect to Twitter:
delay(3000);
}

void loop(){
Serial.println("connecting to server...");
if (client.connect(serverName, 80)) {
TextFinder finder( client,2 );
Serial.println("making HTTP request...");
// make HTTP GET request to twitter:
client.print("GET /1/statuses/user_timeline.rss?screen_name=");
client.print(TwitterName);
client.println("&count=1 HTTP/1.1");
client.println("HOST: api.twitter.com");
client.println();
Serial.println("sended HTTP request...");
while (client.connected()) {
if (client.available()) {
Serial.println("looking for tweet...");
SearchString = SearchString + TwitterName + ": ";
charsize = SearchString.length() + 1;
char StartHere[charsize];
char EndHere[] = "";
SearchString.toCharArray(StartHere,charsize);
if((finder.find("")&&(finder.getString(StartHere,EndHere,tweet,140)!=0)))
Serial.println(tweet);
break;
}
}
delay(1);
client.stop();
}
Serial.println("delay...");
delay (60000);
// don't make this less than 30000 (30 secs), because you can't connect to the twitter servers faster (you'll be banned)
// off course it would be better to use the "Blink without delay", but I leave that to you.
}

Oké, first of all, you need to use the code brackets when posting code. it makes your post more readable.

second, you made some mistakes:

byte ip[] =  { 192,168,1,20}; //change this
byte subnet[] = {255,255,255,0}; //change this
byte gateway[] = {192,168,0,1}; //change this
byte dns[] = {192,168,0,1}; //change this

your ip isn't in the same network range as your gateway and dns. If your dns and gateway are 192.168.0, then your IP can't be 192.168.1.x

And third, if your twitter account is private, it will not work.

Oh, and did you try my code with your ip, gateway, subnet and mask? did something show up on the console?

sorry about not bracketing my code.

yeah i'm kinda new to mac so i'll probably find out how to get the gateway and DNS up properly.

made a mistake about not making my twitter public.

and last of all, i uploaded your code successfully without any errors on the arduino IDE but nothing came up on the LCD. The arduino IDE stated that uploading was done and is successful without any errors when verifying.

so i'll probably find out how to get the gateway and DNS up properly.

yes, you'll have to figure that out.

i uploaded your code successfully without any errors on the arduino IDE but nothing came up on the LCD.

You do know that my code doesn't use LCD, but the serial monitor, do you?

sorry have been busy with work and all. yup i found out the problem. i initialized the LCD at the start of the program but forgot to change all the serial print to LCD print instead.

Could i ask why didnt you implement DHCP? I have a library that i grabbed off the net but i'm not too sure how to implement it. Could you possibly point me in the right direction? cheers!

Could i ask why didnt you implement DHCP?

Well:

  • using dhcp makes your code bigger when you upload the sketch
  • sometimes it doesn't pick up an IP
  • this way you know exactly what ip, subnet, gateway and DNS you are using

But:

  • if you want, you can just erase this:
byte ip[] =  { 192,168,1,20}; //change this
byte subnet[] = {255,255,255,0}; //change this
byte gateway[] = {192,168,0,1}; //change this
byte dns[] = {192,168,0,1}; //change this

and replace this:

Ethernet.begin(mac, ip, dns, gateway, subnet);

with this:

Ethernet.begin(mac);

Arduino IDE will then auto include dhcp and your Arduino will use dhcp when started (or it should)

brilliant! got it working but i'm stuck with cut-off tweets. i believe you create your program so that the tweets will be in a string form and sent to the microcontroller as arrays. how do i split the tweet into half so that i can display a certain amount of characters in a line and point the next string to the second line?

eg(point tweet to line):

lcd.setCursor(0, 0); //where first number is column number and second is line number

lcd.print("Tweet line 1"); 

lcd.setCursor(0, 1);

lcd.print("Tweet line 2");

cheers!

Hi kenneth87,

I could just give you the code, but what is the fun in that. Arduino is about learning and discovering :wink:
So what you need to learn more about is this:

you'll have to copy every part (piece by piece) from the char to an other char, by doing something like:

string1[0] = tweet[0]

now if you replace the 0 by i and let it repeat for let's say 70 times

for (byte i = 0; i < 71; i++){
string1[i] = tweet[i];
}

and you'll have to empty those chars every time before copying them, by doing something like:

memset (strin1,0,sizeof(string1));

at some point, you'll have to do that for "char tweet" too.

don't forget you'll need something like char string1[71] and char string2[71] before void setup().

So may I also ask, to submit any further questions on coding in the appropriate forum sections, because those or not directly related with this project.

Good luck using Arduino and Twitter.

Kenneth87,

I might have overlooked something. When the tweet gets pulled and is been put into a char, it will stay in there. So the next time if it pulls a shorter tweet, the old one will partly stay in there too. So extualy the char should be cleared before filling it.

good day,

I realised once i run the code, when i update twitter while the code is running, it will not get updated to the latest tweet.

edit: got a fix to it! do you want me to share the code i have when i'm done? also fixed the part with the tweets broken into 16chars per line in a string like what you suggested.

I did see your previous post, but I didn't had the time to answer yet. Very nice you solved this yourself.

I would love to see your code, but you should get some credit yourself. Make a new post, showing off your own project (try to include a youtube movie or some pictures), just make a quick reference to this post, explaining you started using this code and adapted it, for you own project.

Good day JO3RI,

I am able to post the code soon as it is due for submission by start november. also my twitter client stopped working due to the recent API updates. do you have any idea what changes i have to make to enable it to start working again?

Twitter api version changed from v1.0 to v1.1

bump

When I past this in my browser:

http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=JO3RI&count=1%20HTTP/1.1

replace JO3RI with your own twitter name if you like.

and if I try the same thing with hashtag search,

http://search.twitter.com/search.atom?q=%23arduino

I still get to see the last tweets, so mine is still working

yup mine is working too but when you use a code on Arduino IDE that uses GET HTTP, it doesn't seem to get tweets off twitter with that exact same line. any ideas?

also is there a way to implement oauth without going thru a PHP server?