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();
}
}
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.
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);
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.
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