Help with ethernet shield!

I purchased an Ethernet shield, and yesterday I got it. But I still have troubles getting it up and running...
I'll give as much details as possible.

Code: I use a slightly edited version of the 'WebClient' example:

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // standard MAC
byte ip[] = { 192,168,1,172 }; // unused IP, I pinged it
byte server[] = { 192,168,1,100 }; // desktop, 192.168.1.100
byte gateway[] = { 192, 168, 1, 1 }; //router's IP
byte subnet[] = { 255, 255, 255, 0 }; //subnetmask

Client client(server, 80);

void setup()
{
pinMode(14, OUTPUT);
pinMode(15, OUTPUT);
Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(9600);

delay(1000);

Serial.println("connecting...");
Serial.println(client.connect());
Serial.println(client.connected());
//Serial.println

if (client.connect()) {
Serial.println("connected");
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
digitalWrite(15, HIGH);
} else {
Serial.println("connection failed");
digitalWrite(16, HIGH);
}
}

void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}

if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for( ; ; )
;
}
}

Router: the router we've got is a LinkSys WAG200G. It has four ethernet ports and WiFi.
(such a thing:
)
Specs:

  • Supports 802.11g and 802.11b wireless LAN
  • Built-in ADSL modem with G.lite, g.992.3,g.992.5, G.dmt & T1. 413 supp
  • Supports 4 10/100 Auto MDI/MDI-X LAN switch ports
  • Enhanced security mgmt functions: Port Filtering, MAC & IP Add Filtering,
    DMZ Hosting & NAT Technology
  • Build-in web graphical user i/face for easy config from any web browser
  • Support for RFC1483, PPPoE and PPPoA connections
  • Statefull Packet Inspection (SPI) firewall with DoS prevention
  • Wireless Access Lists to enhance wireless security
  • Supports VPN Passthrough for IPSec, PPTP, and L2TP Protocols
  • Supports Static and Dynamic Routing (RIP1 and 2)
  • Remote administration and remote upgrades available over the Internet

Port 1 is used by the desktop I'm currently working on,http://www.arduino.cc/yabbfiles/Templates/Forum/default/code.gif port 3 is sometimes used by my old laptop, and sometimes by the shield.
I can't get access to it, because my dad forget the username and password... I'm only planning to reset it if there's no other way.

Shield: ethernet shield from DFrobot (WIZnet5100 chip), comptible with the official ethernet library.

IP, subnet, gateway, ...: The IP of my desktop is 192.168.1.100, so I use 192.168.1.172 for my Arduino. As subnet I use 255.255.255.0, and as gateway 192.168.1.1.
Print of the ipconfig command (translated):

C: \ Documents and Settings \ HP_Eigenaar> ipconfig

Windows IP Configuration

Ethernet adapter Wireless Network Connection:

Connection Spec. DNS suffix:
IP address. . . . . . . . . . . . . : 192.168.1.100
Subnet mask. . . . . . . . . . . : 255.255.255.0
Default Gateway. . . . . . . . . : 192.168.1.1

Ethernet adapter LAN:

State. . . . . . . . . . . . . . . . . : Media disconnected

And on my laptop I get the same, except for the IP, of course, there it is 192.168.1.101.

I tried 'shared internet', by enabling it on my desktop and putting the jack from my Arduino to the jack named ethernet. My computer connects through WiFi (I heard that could cause the problem, is that true?). It didn't work... When I put it in a port of the router I can ping, it with my desktop, but now, I couldn't...

Any suggestions?

You have the webclient example loaded, do you have webserver software on your PC ?. The easiest way to check if it works is to start with the Server example and point a web browser at the IP of the arduino.

It shouldn't make any difference using wireless, and you needn't touch the router. You should have the arduino plugged into the router. Connecting ti directly to the PC won't work unless you use a crossover ethernet cable.

Are you trying to just make it pull a webpage? Or make it serve as a server you can open the page on?

For me it sounds like you are trying to do the opposite of what the code does.

do you have webserver software on your PC ?

Yes I have (XAMPP).

I'll now try out the webserver example again...

[edit]Webserver example works!!![/edit]

Webclient example still not working... :cry:

Does it work pointing the arduino at the IP of an external website ?. It takes another unknown out of the equation, or can you access your PC's web page(s) from another PC on your local network ?

I can access the webpage of this PC with another computer (I get a 403, but hey, it's not unexisting :)). I can ping the board when my edited version of the WebClient is loaded. But it always fails...

This might not be the problem but your script is looking for an address and then for a page called search and passing a query string. Is it getting confused by the get request?
Has the web server you are pointing at got a search page able to accept the query string.

From your webclient example.
client.println("GET /search?q=arduino HTTP/1.0");

Try changing the ip address to one of googles servers with the ip adress as returned by pinging google.com
The original address in the example may have changed by now or not be correct for your location.
Or try removing the GET request.
client.println("HTTP/1.0");

Gordon

I'm trying it now. I supposed I would get a 404 if it wouldn't exist.

EDIT: IT WORKS? IT ****** WORKS? I removed some cables from the analog inputs, and now it works ftw! Thanks to all!

EDIT: It's sooo random! I have to press the reset button 5 times before it works!

known problem mate if ethernet shield doesn't work reset for 3 times or so...

have had this problem alot of times in my wifibot project!

P.S. een HP kom op das echt een slecht merk :stuck_out_tongue:

I'm glad you sorted it out, networks can be especially annoying as often you haven't got any method of measuring if something is transmitting or receiving or what its TX/RX ing. WIFI is even worse at least you have the TX/RX LEDs on most Ethernet devices.
I have a question though which is sorta on topic and I'm hopping Arduino.
If I want to control something over Ethernet LAN what is the cheapest way of doing it? If I had say 15 items (nodes) on my LAN that need a digital signal (on/off) and thus only one or possibly two digital outputs needed per node. I want to be able to control them from any PC on the LAN and possibly WAN. I know I can get an Arduino board for £15 on the bay but once you add an Ethernet shield for another £30 things start getting too expensive. Is there something simpler and cheaper out there or is there a cheaper option for the Arduino that I'm missing? The distance between the nodes is max 200m.
Thanks in anticipation.

FWIW- I have the same hardware setup and the same problem. Tried both the Ethernet and Ethernet2 libraries, still no luck.

Works fine on an internal LAN, but can't connect outside gateway.

I suspect there's a problem with the firmware in this particular Ethernet shield. It may not be playing well at the lower protocol layers.

The below code downloads my home page and prints it to the serial monitor when the serial monitor is started.

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 102 };
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
byte server[] = { 208, 104, 244, 29 }; // zoomkat home page

Client client(server, 80);

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  
  delay(1000);
  
  Serial.println("connecting...");
  
  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /~shb/ HTTP/1.0"); //zoomkat home page
    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(;;)
      ;
  }
}

If it works fine on the LAN then it is highly likely your problem is elsewhere. Out of interest a lot of routers won't let you check a wan link on your own LAN. This is called loop back and a lot don't allow it. By this I mean if you correctly port forward your router to pass all traffic received on say port 80 to your Arduino then you may not be able to test this on another PC on the same LAN. You would have to go the other side of the router to test it. Generally if it works on the LAN then it is either a dynamic IP problem, a router problem or a port forwarding/ firewall problem. At least that's what I've found in my experience which I will admit isn't a bill gates type.

Works fine on an internal LAN, but can't connect outside gateway.

Lots of ways... and places... a firewall might be getting in the way. Don't forget there may be one in your router.

One thing I learned when working with the Ethernet shield and with the WebClient, make sure you get your header requests correct! There are a number of websites that wont allow you to access them without a proper header request. I've found this website to be useful for giving the proper header request: http://web-sniffer.net/ but really what you need in that WebClient code is usually

client.println("GET /whatever your URL query is/ HTTP/1.1");
client.println("Host: yourwebpage.com");

Depending on the web page you can use HTTP/1.1 or 1.0 and some webpages don't require a header request. All of this can be checked at the web site.

Another nice utility is the DHCP library that can be synced in with code to provide easier web access. I adapted code from http://gkaindl.com/software/arduino-ethernet/dns

I have the same problem. Ethernet shield works fine on the LAN, for example with the WebServer example. But the WebClient only reports "connection failure".
I don't see how this can be related to settings in the router. Every PC in the house is able to reach random sites on the internet, why should the router treat the Arduino differently?

One difference is that the Arduino does not use DHCP. Is there something that PC's know, and my Arduino does not?

Is there something that PC's know, and my Arduino does not?

Did you setup a default gateway on the arduino?

That could be the thing that the PC's now and not the Arduino.

The arduino won't connect precisely because it doesn't know DHCP if you don't tell it to.

PCs have the capability built in to the OS but Arduino's 30kb memory doesn't have it automatically included. If you want Arduino to automatically connect, you'll have to provide it with the code to do so.