Go Down

Topic: Failed to configure Ethernet using DHCP (Read 194 times) previous topic - next topic

kaustubh012

Hello,

"Failed to configure Ethernet using DHCP" this is output I get when I try the WebClient code from the library. I know this topic has been raised by many but I couldn't find any solution.

Here is some info about my setup. Also I have mentioned some points which I have tried to resolve this problem but failed.

1. I am using W5100 Ethernet Shield.
2. I am connecting it to router's Ethernet port. Router has DHCP server enabled. I am using Beetle 450C3 router.
3. I have tried using different cables and there is no change in error message. Also If I connect my laptop using Ethernet cable then laptop gets the IP address and internet works fine.
4. I have tried several codes to get the IP address etc from other forums but nothing is helping me out here.
5. I do not have any SD card in the SD card slot of Ethernet Shield. Also I have tried flashing the code with and without mounting the Ethernet Shield.
6. I have tried changing the MAC address also.


I am not posting the code since I am using the same code "WebClient" from library. I have changed and tried with IP addresses like 192.168.1.10/9/5.

I have tried adding default gateway and subnet mask. Also passed them through begin function.

I hope some one would help me out to solve this problem. My Ethernet Shield is new and I rarely doubt it is not working. I should work. It has all to do with some network setting and router configurations.

I suspect
1. Is there anything to do with Port forwarding in the router?
2. Is there anything to do with IPv4 and IPv6 ?

 
Thanks.
Sorry for the big post but if we could resolve it then it ll help lot of beginners. 

SurferTim

Try this sketch. If the serial monitor shows 192.168.0.2, then the SPI bus and the SPI side of the w5100 is working.
Code: [Select]
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,2);

void setup() {
  Serial.begin(9600);

  // disable SD card if one in the slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.println("Starting w5100");
  Ethernet.begin(mac,ip);

  Serial.println(Ethernet.localIP());
}

void loop() {
}

kaustubh012

Hi SurferTim,
I have tried the similar code and it worked.
I'll try this sketch as well.

SurferTim

Then you might have an ethernet shield with the incorrect resistors between the w5100 and the RJ45 connector.

kaustubh012

Hi TimSurfer,
I have tried the code given by you and that works fine.

Also today I have tried to connect the uno with ethernet shield to my laptop instead of a router. I have enabled the Internet sharing option in my laptop. Here is the result.

It says connected but nothing printed after that.

Failed to configure Ethernet using DHCP
connecting...
connected

disconnecting.


I am using the WebClient code and this time I am assigning the IP,Subnet and Gatway manually.


Here is my code.

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0x03, 0x80, 0x1B, 0xFE, 0xEE };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.google.com";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress  ip(192, 168, 1, 10);
byte subnet(255,255,255,0);
byte gateway(192,168,1,1);


// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection:
 // if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip, subnet, gateway);
  //}
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    Serial.println("Available");
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while (true);
  }
}

kaustubh012

Hello All,

This has nothing to do with router or any code.
If you are using Ethernet Shield Clone HanRun with W5100 HR911105A then there is a problem with the hardware. I am happy to say that it is easy to solve. We need to solder some additional resistors.

Please refer https://forum.arduino.cc/index.php?topic=351477.15

Thanks all for your contribution.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy