Pages: [1] 2   Go Down
Author Topic: Failed to configure Ethernet using DHCP  (Read 836 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been perusing the forums on this topic but still have yet to find out why my setup won't work, so I thought I'd be a little more direct.

Anyway, I'm fairly new to Arduino in general so forgive my naivete. Here we go:

 I've plugged my ethernet shield (HanRun HR911105A 12/11) into my arduino uno, made all the connections (USB to my Mac OS X laptop, ethernet to the router using a one to one cable) and uploaded the DhcpAddressPrinter sketch. After waiting a while I'll eventually see the "Failed to configure Ethernet using DHCP" message. Also, the RX,100M,FULLD, and LINK LEDs appear to pulse at regular intervals with TX and COLL remaining off.

Also, whenever the ethernet cable has been plugged in for a while the RX, 100M, and FULLD LEDs are lit, with the LINK LED flashing. The rest (TX and COLL) are off

When I check the router the light corresponding to the the plug I'm using for the arduino blinks (which I thought should indicate some sort of interaction).

I then tried the WebServer sketch and assigned the Arduino a static IP. The router light still blinks but if I try to ping the IP address from the router admin section nothing is getting through. It does output the IP I assigned with Serial.println(), but if I navigate to that IP address on my laptop (that is on the same network) it can't find anything.

I'm thinking that anything I do with Ethernet.begin() just isn't connecting... Does anyone have any suggestions? Any help is appreciated
Logged

Offline Offline
Edison Member
*
Karma: 28
Posts: 2037
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

getting an address from the router is only going to work,   if the router is authorised to hand out addresses using dhcp.   Do you know that yours does ?

The blinking light next to the ethernet cable plug doesn't seem to mean very much,   it seems to only mean that the other end of the cable is plugged into something.   Mine blink even when the computers are turned off.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm pretty sure it is authorized, but I could be mistaken. Within the router's settings the Internet Connection Type is set to "Automatic Configuration - DHCP" and the DHCP Server is enabled.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This sketch tests the connection between the Arduino and the ethernet shield. I presume the shield is a w5100, and not an ENC28j60. Don't change anything. It is just a test. Upload it and check the serial monitor. If it shows anything but 192.168.2.2, then you have a problem with the SPI or w5100..
Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2,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() {
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are correct, it is a w5100. Anyway, I ran the code you suggested and the output to the serial monitor was 192.168.2.2.  I'm guessing that means that the problem is elsewhere, but I have no idea what I need to do next to fix it.

Thanks in advance for the help (and for the help you all have already given)
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried a different cable? What make/model router are you connecting it to?

Does your computer connect to the same router? Does it use dhcp to get an ip?

edit: Do you have a SD card in the slot if the shield has one? If so, remove it for a test.
« Last Edit: January 22, 2014, 01:34:07 am by SurferTim » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll have to try a new cable when I get back home,  though I was able to use the same cable for a wired connection on my laptop (if that means anything). As for the router,  it's a linksys E1000, and my computer does use dhcp to get an ip.

And no, I haven't been making use of the SD card slot,  as I remember reading somewhere on these forums that the two cannot operate at the same time. So I haven't had a SD card in the slot.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The ethernet and SD can operate in the same sketch. They just need to be initialized correctly. If you do not disable or initialize the SD, it will cause the dhcp request from the w5100 to fail.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, my mistake, thanks for clearing that up.

So I finally was able to try another cable, while using the WebServer sketch and came up with the same problem. Any attempts to ping the static ip (or load the ip address from my laptop) still failed.
Logged

0
Offline Offline
Tesla Member
***
Karma: 116
Posts: 8936
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can try the below code to see if you get a response from the server. If you get a response your issue may be code related instead of your network/hardware setup.

Code:
//zoomkat 9-22-12
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
//remove SD card if inserted

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

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

char serverName[] = "web.comporium.net"; // zoomkat's 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 test 9/22/12"); // 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 /~shb/arduino.txt HTTP/1.1"); //download text
    client.println("Host: web.comporium.net");
    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

}
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@zoomkat: You are still using this buggy code?
Code:
 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
  }
I pointed this out to you here:
http://forum.arduino.cc/index.php?topic=201186.msg1487043#msg1487043
« Last Edit: January 23, 2014, 05:10:48 am by SurferTim » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried zoomkat's code and didn't get any output to the Serial monitor. So I'm not sure what's up. From what I followed in the code I don't think that my arduino was getting to a point where the discussion between SurferTim and zoomkat came in to play, but I could be mistaken.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried zoomkat's code and didn't get any output to the Serial monitor. So I'm not sure what's up. From what I followed in the code I don't think that my arduino was getting to a point where the discussion between SurferTim and zoomkat came in to play, but I could be mistaken.
You are not there yet. I was bringing that to zoomkat's attention. It caused a problem in a previous topic that caused a bunch of funny ys in the output. Funny y = ÿ = 255 = -1 = no characters available

However, zoomkat's code should have produced the "Failed to configure Ethernet using DHCP" on your serial monitor within a couple minutes if there was no dhcp server or the network connection failed. If it didn't, you have other problems, probably related to the SPI bus. That is why I asked about the SD card earlier.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When I tried zoomkat's code I didn't even get the prompt to type e to run the test. I did send an "e" anyway, but still there was no output to the serial monitor. That seems like it might be a bad omen, especially since I waited a substantial amount of time before throwing in the towel
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this dhcp test sketch. It is stripped down to the basic code. Do you get "failed" or the dhcp IP?
Code:
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

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

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.print(F("Starting ethernet..."));
  if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  else Serial.println(Ethernet.localIP());
}

void loop() {
}

edit: It may take a couple minutes to return "failed" if it fails. That is a dhcp request timeout thing. If you wait more than a few minutes and you still get nothing, then the SPI or the w5100 has failed.
« Last Edit: January 25, 2014, 01:18:16 pm by SurferTim » Logged

Pages: [1] 2   Go Up
Jump to: