DHCP with Arduino
Oct. 23, 2011, 8:01 p.m.
The Ethernet library for Arduino microcontroller boards sadly lacks support for IP address discovery via DHCP. There are libraries around written for this, but many of them are outdated. Beginning with Version 019 of the arduino software, the ethernet library has been reworked to talk to Wiznet W5100 ethernet chip via SPI.
To get it working with 022 I used this library:
http://www.mcqn.com/weblog/dhcp_and_dns_arduino
I built a library containing the "original" arduino ethernet source files (for details on this, have a look here). The library from mcqn has a different UDP class. Therefore I substituted the following files:
- Udp.h
- Udp.cpp
- w5100.h
- w5100.cpp
- socket.h
- socket.cpp
And I added the following new ones for DHCP support:
- Dhcp.h
- Dhcp.cpp
- Dns.h
- Dns.cpp
After that I was able use the following lines in my code for DHCP:
...
while (Dhcp.beginWithDHCP(mac) != 1)
{
doSomeErrorHandlingOrWaitingStuff;
}
start_your_stuff;
...