Exploring Arduino: Arduino + Ethernet + DHCP with EtherTen

by Amit


In the last post on Arduino, I briefly wrote about my experiments with setting up a wireless communication between a host computer and an Arduino board using XBee. Here, we explore talking to the world of the Internet(s!) using Arduino. Time for giving your Arduino an IP address! Instead of using an Ethernet shield on an Arduino UNO, I thought the EtherTen might be a better idea to try, since it has onboard Ethernet. I am glad, I chose Etherten for various reasons!

EtherTen

Arduino Webserver

Hook up your Arduino to your computer and plug in the Ethernet cable into the board, with the other end connected to a router. If you see the Webserver example (under File -> Examples -> Ethernet) shipped with the Arduino IDE, you will see that it uses the Arduino Ethernet library.

It however requires you to set up a static IP address for your Arduino. However, in a multi-user home/university network, there is a fair chance that the IP addresses are allocated dynamically, hence I would like to use DHCP in my Webserver sketch. Now, that said: using dynamic IP address for a web server isn’t the greatest of ideas technically. But, we shall not go there in this exercise.

I used Georg Kaindl’s Arduino DHCP library to obtain the IP address dynamically and integrated with the Web server example. Here is the complete sketch. Once, you compile and load the sketch to your board, and open the Serial Monitor, you should see something like this:


Attempting to obtain a DHCP lease...
A DHCP lease has been obtained.
My IP address is 10.0.0.97
Gateway IP address is 10.0.0.138
DNS IP address is 10.0.0.138

Now, go to your web browser, and type in: 10.0.0.97:8080 and you should see:

Arduino sends the sensor readings from the Analog pins 0-5 (I don't have any sensor connected to this pins, so they are just random readings)

Now, let us use the telnet  program to send a request to our Arduino:

Telnet session

Resources and misc.

That’s it for this time. (My previous posts on Arduino.)

Advertisements