I have been searching around for this problem for a couple of days but still do not find an answer.
I am trying to make a simple Webclient connection with the arduino shield based on the sample code provided by Arduino IDE. Here is a simplified version of what I am trying to execute:
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte server[] = { 173 ,194, 46, 34 }; // Google
EthernetClient client;
void setup()
{
Ethernet.begin(mac);
Serial.begin(9600);
delay(1000);
Serial.println(Ethernet.localIP());
Serial.println("connecting...");
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
} else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}
}
and always get the answer:
192.168.0.103
connecting...
connection failed
disconnecting.
That means that client.connect(server, 80) is failing. I have tried several IP addresses and same results. The shield is working properly as I have tried the WebServer example and that seems to work flawlessly.
PS on hardware: I am using Arduino UNO R3 and ethernet shield based on W5100
Any suggestions?