Pages: 1 [2] 3 4   Go Down
Author Topic: Made my own TwitterClient and I think it's better than the example one  (Read 13225 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey JO3RI,

I've started a similar project that uses a freetronics etherTen board(basically a board similar and compatible with the arduino).

I hooked it up to a 20 by 4 LCD display and everything is going fine. I'm just stuck on coding with the board that is suppose to connect it to the internet to retrieve tweets from my twitter account. do i just run your code and edit what is necessary to get it up and running then edit it?

also how do i get the ip, mac address, subnet mask, gateway and dns? do i just leave it as it is and rely on dhcp or?

appreciate your help. Have a few books on arduino but need a little kick to get this up and running.

cheers!
Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 387
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Quote
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
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 387
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi again,

strange thing:

Quote
'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  smiley-confuse

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.
Logged


Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 387
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi again.

This morning I tried Arduino IDE 1.0.1 and guess what ... yep:
Quote
'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
Logged


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

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ;-)
char tweet[140];
String SearchString ="<title>";
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[] = "</title>";
        SearchString.toCharArray(StartHere,charsize);
        if((finder.find("<item>")&&(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.
}
Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 387
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
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?
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 387
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

yes, you'll have to figure that out.

Quote
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?
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 387
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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:
Code:
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:
Code:
Ethernet.begin(mac, ip, dns, gateway, subnet);
with this:
Code:
Ethernet.begin(mac);

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


Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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):

Code:
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!
Logged

Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 387
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi kenneth87,

I could just give you the code, but what is the fun in that. Arduino is about learning and discovering  smiley-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:

Code:
string1[0] = tweet[0]

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

Code:
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:

Code:
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.

Logged


Hamme, Belgium
Offline Offline
Sr. Member
****
Karma: 4
Posts: 387
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Pages: 1 [2] 3 4   Go Up
Jump to: