Go Down

Topic: DNS, DHCP and Bonjour/Zeroconf with Arduino (Read 5762 times) previous topic - next topic

gck

Hello,

I just released a DHCP, DNS and Bonjour/Zeroconf library for Arduino with the Ethernet shield.

The DNS library simply looks up IP addresses by host name, but supports a polling mode for non-blocking operation.

The DHCP library is based on previous work by Jordan Terrell, but I added packet resending, an optional polling mode (rather than blocking operation only), some compatibility fixes and the ability to automatically renew your lease before it expires (and rebind if renewing is not possible for some reason).

The Bonjour/Zeroconf library lets you find your Arduino's IP address by a Bonjour name (such as "arduino.local"), resolve other Bonjour names, discover services on your network and even register services running on your Arduino (For example, you can make a web server that will show up in the "Bonjour" bookmarks in Safari on a Mac). Naturally, you need a Bonjour-enabled operating system (such as MacOS X) for this to make sense.

All the libraries as well as their documentation is available at my website. I've also made some examples to illustrate their usage.

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

If anybody is interested in trying them out, I'd greatly appreciate some feedback.

PS: The libraries are all rather large, but will fit on a Diecimila (DNS and DHCP) or a Duemilanove (Bonjour), even though I personally use them on a MEGA.

Douwe Homans

Haven't got the time to test this yet, but want to thank you a lot in advance! It's great to be able to use the cheaper wiznet chip for DHCP instead of for example the XPort!

Thank you!

CannockBlue

Georg

I've tried compiling the example DNS sketches but I'm getting compilation errors:

undefined reference to `EthernetDNS'

I've checked that EthernetDNS.h is installed in the correct directory.

thanks

CannockBlue


gck

Hmm, are you sure you installed the library correctly? It works fine for me on Arduino 0017/Mac.

CannockBlue

Got it working.

(Had to copy the .cpp file to the same directory as the .h file).

Many thanks

Cannockblue.

Dogsbody

I love this library, it does exactly what I want.  Thank you very very much  :)

milneandfletch

Hi,
Has anyone tried putting the DHCP polling and DNS polling routines together?
I'm getting errors compling and server errors when it does, i think its something to do with how I've put the code together, the DNS routine want the dnsipaddress in the setup before the dhcp rotuine has found this out. Any ideas on how to get around this?
Example code would really help!

Thanks

Pete

Folderol

#7
Apr 29, 2010, 09:51 pm Last Edit: Apr 29, 2010, 09:52 pm by zaphil Reason: 1
Has anyone done any work on a DHCP server?

The situation I want to cover is where my arduino is a server and will send web pages to any ordinary laptop that is directly connected to it.

If I go through a router it works fine, as the router sets up the IP for the laptop, but it'll be a bit silly if I have to hang a router on a tiny arduino :P

P.S.
I'm quite happy to have a fixed address for the arduino

milneandfletch

HI,
FIrstly a small concept thing you may not be aware off, Webpages are Client side driven normally by the web browser.
So the ardunio as a web server is only sitting there waiting to have information requested from it.
But if you want the device to be the same regardless of which network your plugged into, and you say you dont mind a fixed IP. Try running the DNS routine from the link below.
What it will mean is it should register as a device name rather than an IP.
Thus you can tell the browser to always look for \\ardunio.

Does that help?

Pete
http://gkaindl.com/software/arduino-ethernet

Folderol

Thanks for your reply. My (probably patchy) understanding of the situation is as follows:

I want to operate with just any off-the-shelf laptop plugged into the Arduino/Ethernet server with nothing else in the system. As there will be no other server than the Arduino, it must have a fixed address, otherwise where would it get one from?

All the laptops I've seen are, by default, configured to find their IP address via DHCP. They send out a request, and if this goes unanswered assume there is no network/server currently available.

This makes sense I think, as if the laptop hasn't got an IP address there would be no way for the server to know where to send ordinary TCP replies (although I don't understand how the server sends back a DHCP response).

In this situation, I don't see how the server having a DNS name is any help.

If I give the laptop any fixed address (on the same subnet) there is no problem.

Interestingly, if I temporarily plug the laptop into my router, wait till it connects and gains an IP address then unplug it from the router and plug it into the Arduino it works - seemingly it holds onto the IP address the router gave it!

Gregory Brown

I just downloaded the zip file containing the three libraries. I too am getting an error compiling "error: EthernetDNS.h: No such file or directory". The library is located here: \My Documents\Arduino\libraries\EthernetDNS. I am trying the "Kitty Twitty" from Make: magazine. Any suggestions?

Thanks
Greg

milneandfletch

Try compling (the play button)
Sometimes it likes to be fully complied before its uploaded.

Pete

Cullen Jennings


This DNS and DHCP are great thank you. They mostly work but I am having a few problems.

When i power cycle the board,  EthernetDHCP.begin call hangs but when I hit the rest button, or use the USB cable that also does a reset, it does not. So for example, if I upload the following sketch


#include <Ethernet.h>
#include <EthernetDHCP.h>


byte macAddr[] = {
 0xDE, 0xAD, 0xBE, 0xEF, 0x66, 0xED };

byte ip[] = {
 192, 168,0,66 };

int rLed = 7;
int gLed = 6;

void setup()
{

 pinMode( rLed, OUTPUT );
 pinMode( gLed, OUTPUT );

 digitalWrite( rLed, HIGH );  
 digitalWrite( gLed, HIGH );  

 Ethernet.begin(macAddr, ip);

 digitalWrite( rLed, HIGH );  
 digitalWrite( gLed, LOW );  

 EthernetDHCP.begin(macAddr);

 digitalWrite( rLed, LOW );  
 digitalWrite( gLed, HIGH );  
}

void loop()
{
}


and then power cycle the board, the red led goes on but we green one never does. I see no ethernet traffic from the board on an ethernet sniffer. If I then hit the reset button, everything works as one would expect and I get a valid  DHCP transaction and end up with an address. It's 100% repeatable - never works when I power cycle the board.

The only other issue I had was with the DNS. It seems like it only does lookups of A records but lots of times you have a CNAME that points at A record. Would it be possible to extent it to do other record lookups. There is some nice DNS code over on the Contiki project that might be useful to look at.

Thanks for the nice libraries. I really think that some solution to DNS and DHCP need to be included in the Arduino Standard libraries.





Cullen Jennings


It seems my problem was related to the reset on the ethernet shield basically being broken. (See thread http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1258355934) Would be sort of nice if the documentation for the EtherShield pointed this out.

I added a capacitor between reset and ground on shield which fixed the problem.

gdrapp

Great DNS library!  This is a much cleaner implementation than the other options out there.

The only issue I've found is that if the response from the DNS server contains a CNAME instead of an A record, the resolveHostName function errors out with a DNSServerError.  The work around is to use the A record to which the CNAME points.  This generally works OK unless you're dealing with virtual web hosts, since they need the original host name to determine which site to hit.

Go Up