Arduino Ethernet Shield. Issues with Lighttpd and/or router. How to get the example code running. 5

A few days ago i tried to get the WebClient example in Arduino working. After some hours of frustration I finally stopped working and googled for a solution. Soon I realized that I was not the only person having this problem. The example code does not work behind a router.

(UPDATE: It does also has issues with Lighttpd – Fix in the second example)

Arduino with Ethernet Shield (Matt Biddulph / Flickr)

Arduino with Ethernet Shield (Matt Biddulph / Flickr)

The solution was easy. I found it in the german book „Arduino – Physical Computing für Bastler, Designer & Geeks“. The Ethernet.beginn() method takes 2 more optional parameters:

Ethernet.begin(mac, ip, gateway, subnet);

That was not mentioned in the example code and obviously i was not the only person that had troubles because of this little mistake.

I propose to add a hint to the example or to change it, since a router is the normal case for an Arduino.

Here is my slightly modified version of the example code that finally worked 🙂

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 178, 25 };
byte gateway[] = { 192, 168, 178, 1 };
byte server[] = { 74, 125, 77, 104 }; // Google

Client client(server, 80);

void setup()
Ethernet.begin(mac, ip, gateway);



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

void loop()
if (client.available()) {
char c =;

if (!client.connected()) {


The Ethernet Library does not work with Lighttpd. You can however easily circumvent this if you use a HTTP-proxy server.
You have to set server variable to the IP of the proxy and send something like the following example to the proxy. The rest works pretty much the same then..

client.println("GET HTTP/1.0");
client.println("host:"); // You have to send a host-header for many domains

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.

5 Gedanken zu “Arduino Ethernet Shield. Issues with Lighttpd and/or router. How to get the example code running.