Offline
Newbie
Karma: 0
Posts: 7
|
 |
« on: May 06, 2012, 05:12:41 pm » |
Hi, i am trying to connect arduino to twitter using ethernet sheild. But i am unable to connect to the website. I think the arduino is getting an IP assigned , but i think the problem is at client.connect() function. pls help me. here is my code #include <SPI.h> #include <Ethernet.h> byte mac[] = { 0x90, 0xA2, 0xDF, 0xC4, 0x70, 0x69 }; // MAC Address of Arduino Ethernet Shield byte ip[] = { 192,168,1,177 }; // IP assigned to arduino byte gateway[] = { 192,168,1,1 }; // Gateway address byte subnet[] = { 255,255,255,0 }; // Subnet Mask address byte server[] = {199, 59, 148, 10 }; // IP address of Twitter
EthernetClient client;
void setup() { Serial.begin(9600); Serial.println("Program Initailising..."); delay(2000); Ethernet.begin(mac, ip, subnet, gateway); delay(1000); Serial.println("connecting..."); }
void loop() { if(client.connect(server,80)) { client.println("GET http://www.twitter.com/statuses/user_timeline/HAutomation.rss HTTP/1.0"); // Senting an GET request to Twitter client.println(); } else { Serial.println("Unable to connect to Twitter"); } // if there are incoming bytes available // from the server, read them and print them: if (client.available()) { char c = client.read(); Serial.print(c); }
// if the server's disconnected, stop the client: if (!client.connected()) { Serial.println(); Serial.println("disconnecting."); client.flush(); client.stop(); }
}
|
|
|
|
|
Logged
|
|
|
|
|
Massachusetts, USA
Offline
Tesla Member
Karma: 96
Posts: 6368
|
 |
« Reply #1 on: May 06, 2012, 10:24:13 pm » |
If you are using Arduino 1.0 then the arguments to Ethernet.begin() have changed. Your best bet is to pass only the MAC address and let DHCP assign everything else.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #2 on: May 07, 2012, 12:37:00 am » |
i tried that, when ethernet.begin() has only mac as its argument, it took a little more time to disconnect, otherwise it disconnects fast
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #3 on: May 07, 2012, 05:56:31 am » |
Do not send the URL in the GET, just the file. if(client.connect(server,80)) { client.println("GET /statuses/user_timeline/HAutomation.rss HTTP/1.0"); client.println(); } else { Serial.println("Unable to connect to Twitter"); }
|
|
|
|
|
Logged
|
|
|
|
|
Massachusetts, USA
Offline
Tesla Member
Karma: 96
Posts: 6368
|
 |
« Reply #4 on: May 07, 2012, 08:06:11 am » |
Perhaps File->Examples->Ethernet->TwitterClient would be a good starting point.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #5 on: May 16, 2012, 01:53:27 am » |
thaks guys. But the problem is with the client.connect(server,80). Its always returning false no matter what
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #6 on: May 16, 2012, 12:22:16 pm » |
Can you ping the shield ip from a localnet computer? ping 192.168.1.177
edit: The correct format for the begin function is: Ethernet.begin(mac, ip, dns, gateway, subnet); or if you do not use dns, you can use the gateway for the dns server ip Ethernet.begin(mac, ip, gateway, gateway, subnet);
|
|
|
|
« Last Edit: May 16, 2012, 12:36:15 pm by SurferTim »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #7 on: May 25, 2012, 12:24:32 pm » |
ya, i can ping the arduino. But the exection of of client.connect() is not working correctly. Its always returning a FALSE no matter what
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #8 on: May 25, 2012, 12:33:05 pm » |
What is the ip address (edit: and subnet/gateway) of the localnet computer you used to ping the Arduino? Does it have internet access?
Do you have a localnet web server you can test with? Maybe that would help get the bugs out.
|
|
|
|
« Last Edit: May 25, 2012, 12:35:01 pm by SurferTim »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #9 on: May 25, 2012, 12:42:19 pm » |
i havent set up a local server in my computer. How can i do it and how can i filter the bugs with the server??
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #10 on: May 25, 2012, 01:33:27 pm » |
If you use Windows, then IIS is the web server software. I use WinXP, and install it using Control panel - Add or Remove Programs - Add/Remove Windows Components - Internet Information Services
If you use Linux, then Apache is the web server. Usually, your distro will have a pre-compiled version in the repository for your flavor of Linux.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #11 on: May 26, 2012, 04:36:34 am » |
ok, after that i have to change the web address to localhost and then check whether i got the connection or not??
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #12 on: May 26, 2012, 06:27:37 am » |
ok, after that i have to change the web address to localhost and then check whether i got the connection or not??
You need to change the server address on the Arduino to the localnet ip of your new server. You did not answer the question about the localnet computer you are using (your new server now?). What ip/subnet/gateway does it have?
|
|
|
|
« Last Edit: May 26, 2012, 07:36:16 am by SurferTim »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #13 on: May 31, 2012, 02:12:38 pm » |
i am using ubuntu, so am planned to install an apache server,
is there anyway i can communicate with the arduino through the ethernet port of my system, using a C, C++ or any other languages. I am trying to read and respond to the arduino from the computer now
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #14 on: May 31, 2012, 03:03:27 pm » |
I modified Linux telnet server code written in C that I found on the internet. It wasn't easy. The Arduino end was the easy part.
|
|
|
|
|
Logged
|
|
|
|
|
|