Hello,
I am trying to get some experience with the Ethernet shield, specifically having the shield connected to the laptop rather than router. I need this to be done for my application.
My IPv4 configuration is set to ip(192.168.0.1), subnet(255.255.255.0).
Here is the how the Arduino is configured.
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x56, 0xAE };
byte ip[] = { 192, 168, 0, 2 };
byte server[] = { 64, 233, 187, 99 }; // Google
EthernetClient client;
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
Serial.print("IP: "); Serial.print('\t'); Serial.println(Ethernet.localIP());
Serial.print("Gateway: "); Serial.print('\t'); Serial.println(Ethernet.gatewayIP());
Serial.print("Subnet: "); Serial.print('\t'); Serial.println(Ethernet.subnetMask());
Serial.print("DNS: "); Serial.print('\t'); Serial.println(Ethernet.dnsServerIP());
delay(1000);
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 (;;)
;
}
}
I am getting a connection failed at the output. I can ping the shield just fine. The W5100 on the shield has autodetect and does not need a cross-over cable (I double checked this).
Output:
IP: 192.168.0.2
Gateway: 192.168.0.1
Subnet: 255.255.255.0
DNS: 192.168.0.1
connecting...
connection failed
disconnecting.