Exploring Arduino: Arduino + Ethernet + DHCP with EtherTen
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!
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:
Now, let us use the telnet program to send a request to our Arduino:
Resources and misc.
- Webserver DHCP sketch
- Tweet from your Arduino board: This sketch builds upon the example here by obtaining the IP address using DHCP
- Arduino Ethernet
- DHCP with Arduino
- Moving forward with Arduino: Ethernet
- O’Reilly’s Arduino Cookbook has some Ethernet + Networking recipes in Chapter 15.
That’s it for this time. (My previous posts on Arduino.)
[…] well. So don’t take our word for it – visit gene’s site for his experience here. And to keep up with other developments – we’re on twitter, so follow […]
Hello Amit, I am currently working on a project for my university, and I need to be able to connect on the schools network with an arduino through wireless. So i need DHCP support, do you have any recommendations ?
Hi Fenx, do you mean to say you want to use the Arduino to connect the school network via a wireless connection? What do you mean by connect: what do you want to do?
I will have an aruidno + gps + wifi module to be able to track the school golf carts. The gps will send the coordinates through the wifi and to a server in the school. But i need a wifi shield that can connect via DHCP.
Are you the poster here: http://www.reddit.com/r/arduino/comments/110drk/wifi_shield_with_dhcp_support/ ? If not, then certainly he/she has the same problem as you. I am not sure what shield you have, but a bit of Googling led me to this one: https://github.com/watterott/RedFly-Shield. It seems to have DHCP support.. Hope that helps you.
Also, have you considered other methods of wireless communication? For example, XBee? Isn’t that suitable for you?
Hi, thanks for this post. I am now able to read the digital signals in my browser when the pc is connected to the same net, i.e. arduino ethernet connected to the router and pc connected wirelessly to the same router. What’s the next step to access these readings from outside this local net? If I try to connect to IP:8080 from my mobile phone over 3G I get an error message (“this webpage is not available” in chrome).
Thanks for your help
[…] Source URL: http://echorand.me/2011/09/24/exploring-arduino-arduino-ethernet-dhcp-with-etherten/ […]
While Evil Zone didn’t do anything groundbreaking in terms of its mechanics
as a fighting game, it definitely has a permanent spot as one
of the most unique ones out there. So if you have boxes of old
Amiga disks, NES cartridges, or other old gaming programs stored
away somewhere, you’re in luck, otherwise you’re treading on legally shifty ground.
It almost felt like playing a Nintendo console (the fact an NES emulator can be
found in the marketplace made it feel even more so).