Go Down

Topic: Problem with DHCP on ethernet shield v1.1 (Read 1 time) previous topic - next topic

kkeepp

Hi.

I have an Arduino 2009 and ethernet shield v1.1.

I have it connected on a mac through ethernet and configured my mac
to share internet on this. Always worked and shared internet with any regular
computer.

It just dont work the basic example of DnsWebClient.
Code: [Select]

/*
  DNS and DHCP-based Web client

This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield.

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13

created 18 Dec 2009
by David A. Mellis
modified 12 April 2011
by Tom Igoe, based on work by Adrian McEwen

*/

#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[] = {  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
char serverName[] = "www.google.com";

// 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() {
  // start the serial library:
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }
  // 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(serverName, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  }
  else {
    // kf 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()) {
    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);
  }
}


On the serial terminal it just print "hello" and nothing else happens.
Anyone already had this problem and/or know what i can do to have this working?

Thanks.

kkeepp

ajofscott

Disable MAC filtering on your router, see if it will issue an address, then jot down the reported MAC and add it to the filter's allow list.

kkeepp

Hi, i'll try but i don't think this is a problem.
What i'm curious is that
Code: [Select]

Ethernet.begin(mac)

never ends, the program stuck there and never go on.

I think that some misconfiguration would result in a false return,
and not in stuck there. Is there something wrong with my logic?


ajofscott

A DHCP request can last a while if no DHCP server responds. Specifying an address in the scope of your private network would allow you to see if you had connectivity. If your computers autoconfigure I suspect the router has mac filtering enabled and it will refuse addresses to any ethernet device not in the mac table.

ajofscott

Quote
mac: the MAC (Media access control) address for the device (array of 6 bytes). this is the Ethernet hardware address of your shield. Newer Arduino Ethernet Shields include a sticker with the device's MAC address. For older shields, choose your own.

You may not be able to arbitrarily set a MAC, it may be hard coded.

zoomkat

Quote
It just dont work the basic example of DnsWebClient.


Does hard coded client code work? If not, then you may have issues beyond just the code itself.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

kmpm

There are some outstanding issues with UDP and DHCP that won't be fixed unti 1.0.1 and perhaps not event then.
http://code.google.com/p/arduino/issues/detail?id=669 and http://code.google.com/p/arduino/issues/detail?id=742 are commited and have a huge chance of getting in the next release.

http://code.google.com/p/arduino/issues/detail?id=716 ,which is about maintaining a lease might not get there.

I don't know if these affect you but I and others have seen some strange issues without these fixes

Go Up