we are using Arduino W5100 Ethernet shield. The code is to try DHCP first and if that fails, then try the static IP. we do the Ethernet Initialization and stop every time. The library is Arduino Ethernet library.

  1. when we try with a wireless router, everything works and we are able to contact our web server.
  2. Now the wireless router is connected to a switch. switch <======> router <=====> W5100

if we try to send data using the switch directly, DHCP fails, whereas a laptop using the same cable works.

Question is, even Arduino Library has DHCP functionality, why should a laptop work where the shield is failing? The network and topology and rules should be same for both the laptop and W5100 shield. Anything we can do to debug this issue more?

Edit1 : - Switch which we are using is L3 in nature.

Below is the code which we are using at present.

    while(1) {

        KDEBUG("wait 10 seconds...\r\n");
        // wait 10 seconds
        for(loop = 10; loop > 0 ; loop--) {

        KDEBUG("Try transmitting data on ethernet...\r\n");


    return 0 ;


void wait_millis(uint16_t num) {

    for(; num > 0 ; num-- ) {
        _delay_ms(1) ;


// transmit data using Ethernet
static uint8_t transmit_data() {

    char request[256];
    uint8_t status = 0  ;

    // reset counter
    counter = (counter > 254) ? 0 : counter ;

    memset(&request[0], 0 , sizeof(request));
    memset(&bencode[0], 0 , sizeof(bencode));

    // try DHCP
    if (Ethernet.begin(mac_address) == 0) {
        KDEBUG("Failed to configure Ethernet using DHCP \r\n");
        // use static IP. no return code.
        Ethernet.begin(mac_address, ip_address);

    } else {
        KDEBUG(" Got lease from DHCP \r\n");

    // wait for ethernet to initialize:

    // we got a connection?
    status = client.connect(server, port) ;
    KDEBUGF("ethernet client  status= %d \r\n", status);
    if(!status) {
        goto quit ;

        KDEBUG("connected \n");
    // create an HTTP request
    strcat(request, "GET /api/gl868.php?data=");
    // 12 chars
    strcat(request," HTTP/1.1 \r\n");
    // 25 chars
    strcat(request,"Host: ");
    strcat(request," \r\n");

    // send GET request
    client.println() ;


    if(client.connected()) {

    return 1 ;


    if(client.connected()) {

    return 0 ;

  • What Arduino board? Commented Jan 8, 2016 at 9:28
  • @MikaelPatel - We are using Arduino Mega.
    – srj0408
    Commented Jan 8, 2016 at 9:58
  • I have exactly the same problem with an arduino uno - it works fine plugged in to the router but not when plugged in via a switch (in fairness, a chain of switches) Fixed IP is fine and laptop DHCP is fine, it's just DHCP on the ethercard that is an issue. I suspect that the ethercard.h library has a bug but I'm not good enough to find it. srj0408 did you ever find a solution? Commented Jun 12, 2017 at 6:27

2 Answers 2


A certain way to debug this is to use tcpdump to capture network packets from both Arduino and your laptop and check the differences. I would start by looking for DHCPDISCOVER packet that Arduino should be sending.

A simpler way would be to check DHCP server logs to see how the communication looks like from server's perspective. Here, you should be looking for lines which have the MAC address of your Arduino shield. The success of this approach will depend of the verbosity of the DHCP server you're using.


If I understand your connection...

  • Device over wifi to router works.
  • Wired, via a switch to router does not?

DHCP is clearly switched on for WLAN, is it switched on for LAN?

Personally I always use fixed IP for such projects, with a default value that can be reset so that I can always find my device. I change the IP (and/or MAC) via a serial monitor.

  • The poster specifically says that a laptop connected via the same cable works (which I assume means "gets a configuration via DHCP"). Commented Jan 8, 2016 at 11:28
  • Even though i am using a static or fix IP for my ethernet shield, it is unable to send data to server. Of that, our switch is L3 in nature.
    – srj0408
    Commented Jan 8, 2016 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.