W5100 Ethernet shield DHCP fails with a Switch

Hi
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?

Thanks

while(1) {
		
		KDEBUG("wait 10 seconds...\r\n");
		// wait 10 seconds
		for(loop = 10; loop > 0 ; loop--) {
			wait_millis(1000);
		}
		
		KDEBUG("Try transmitting data on ethernet...\r\n");
		transmit_data();
		
	}
	
	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));
	
	
	wait_millis(5000);
	// 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:
	wait_millis(5000);
	
	// 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=");
	strcat(request,bencode);
	// 12 chars
	strcat(request," HTTP/1.1 \r\n");
	// 25 chars
	strcat(request,"Host: ");
	strcat(request,server);
	strcat(request," \r\n");
	
	// send GET request
	client.println(request);
	_delay_ms(1);
	client.println() ;
	
	wait_millis(1000);
	client.stop();
	wait_millis(1000);
	
	if(client.connected()) {
		client.stop();
	}
	
	return 1 ;
	
quit:
	
	wait_millis(100);
	if(client.connected()) {
		client.stop();
	}
	
	return 0 ;
	
}

There has been a switch problem reported in the past, but the resolution was probably to use a wireless router.
You might try the below client test code to see if it will connect to the server thru the switch.

//zoomkat 3-1-13
//simple client checkip test
//for use with IDE 1.0.1 or later
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

char serverName[] = "checkip.dyndns.com"; // test web page server
EthernetClient client;

//////////////////////

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600); 
  Serial.println("Better client ip test 3/1/13"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET / HTTP/1.1"); //download text
    client.println("Host: checkip.dyndns.com");
    client.println("Connection: close");  //close 1.1 persistent connection  
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

Solution for cheap Chinese shield https://forum.arduino.cc/index.php?topic=351477.15