Go Down

Topic: It's possible to connect / ping / find Arduino by DHCP ? (Read 925 times) previous topic - next topic

saormart

Hello everyone,

I would like to know if it's possible to connect / ping or find the arduino on the network by the hostname or other way instead use a static IP address.
I'm performing some tests with the follow code, but without sucess.

Code: [Select]

/*
  DHCP-based IP printer

This sketch uses the DHCP extensions to the Ethernet library
to get an IP address via DHCP and print the address obtained.
using an Arduino Wiznet Ethernet shield.

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

created 12 April 2011
modified 9 Apr 2012
by Tom Igoe

*/

#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 };

// 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);
  // this check is only needed on the Leonardo:
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // 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:
    for(;;)
      ;
  }
  // print your local IP address:
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print(".");
  }
  Serial.println();
}

void loop() {

}


PaulS

That code looks a lot like the lousy DHCP Printer example, which I can't see how can possibly work.

That code is going to allow the Arduino to get a dynamic IP address that is in the range served up by the DHCP server that you tell it to connect to. Which one are you telling it to connect to? None that I can see.

Where are you telling it to use DHCP to get an IP address?

Even if you succeed in getting a dynamic IP address, how is the rest of the world supposed to know it's name? Even if there was a name, the only DHCP server that would know its name vs. IP relationship is the one that served the IP address to start with.

saormart

Hello Paul, sorry to take that printer example to perform some tests...

Actually I'm looking  for a code that allow the Arduino to get a dynamic IP address, and I would like to know how to find the arduino by the hostname or something like that...
Is that possible ? how ?

Thanks in Advance!

PaulS

Quote
I would like to know how to find the arduino by the hostname or something like that...

If you expect that the Arduino is going to be found, by name, regardless of where you plug it in, I'm afraid that you have some fundamental misconceptions about what DHCP is all about, or how it works.

But, the first thing you need to do is change the code to actually point to a DHCP server that is going to serve up an IP address for the Arduino. Until then, the Arduino will not get an IP address.

robtillaart


interesting read - http://gkaindl.com/software/arduino-ethernet -

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

PeterH


But, the first thing you need to do is change the code to actually point to a DHCP server that is going to serve up an IP address for the Arduino. Until then, the Arduino will not get an IP address.


Although it is possible to address a specific DHCP server, it would be more usual to locate the local server/relay via a broadcast.
I only provide help via the forum - please do not contact me for private consultancy.

Go Up