Go Down

Topic: DHCP server with interactive web server (Read 6661 times) previous topic - next topic


May 12, 2010, 08:36 pm Last Edit: May 13, 2010, 07:07 pm by zaphil Reason: 1
This now a complete working DHCP server and Web server  [smiley=vrolijk_26.gif] so I thought it should have a new thread.

The code is here, but I don't want to leave it there permanently - it's my music website!

Just a small update - I'd left in some duplicate code. It wasn't doing any harm - but wasn't doing any good either, so it's removed and a bit of memory gained. Link above goes to the new code.

The DVCP server is derived from Nebster's code and the web server from the example in the ethernet library.

This might just squeeze into an atmega168. It will comfortably fit into a 328 and beyond. There are a lot of debugging messages available if you uncomment 'debug', but then it probably won't fit in a 128.

Most of what you might need should be there, but there is more than could be added. Please try this out being called from clients on different OSs as I found a few curiosities connected with auto-connect systems :(

I've re-arranged memory handling to correct some errors and reduce the requirements as much as I can, but I'm not a memory guru so there may be things that are technically 'wrong' and/or could be improved.

I've also done things like moving the magic cookie out of the OPT part of the structure. It's still in the same place in the data, but makes stepping through the options easier and less error prone.

I've removed the memory check routine completely. It wasn't giving the correct results (something to do with how flash memory is accessed?) and actually caused some obscure crashes.

Lease time has been set very short (10 minutes) this was just to check that it will re-apply. I don't really know how to test this fully.

Dynamic IP is still not implemented, but I think it shouldn't be too difficult to do a basic version. I think the only info you actually must store over successive calls is the clients mac address and any previous IP you've given it.

Web server
This is now interactive. There are javascript functions and a timer so that the client will refetch the analog data every 200mS (this can of course be changed).

There are also a couple of input buttons, that can be used to make the arduino switch things off and on etc. The way I've done this is a bit of a cheat and doesn't use POST the way your supposed to, but I think it's reasonably error-trapped and sort of legal :)

I've tried it with several different browsers and only Konqueror had a problem - it could send data but wouldn't display the data fetches for some reason.

Almost all the webpage data is held in PROGMEM. Just a few computed values are in 'real' memory. This makes a dramatic difference to how much you can do :)

Again I hope people can try this out with different client browsers and make/suggest improvements. Don't forget to have javascript enabled ::)

Well it isn't there yet but I think the icing on the cake would be to add a basic DNS server so you can just plug in your lappy and call the arduino by name. Anyone want to help with that?


I'm rather disappointed that there have been no replies at all on this.

Is my code so unremittingly bad that everyone is too embarrassed to comment?

I do realise that I have combined elements of two different Ethernet libraries and would like to resolve that, but at present it seems we have several official and unofficial ones that are all slightly different - so which to chose?


You might want to post a link where to find the UdpRaw.h material. The software development area may not be frequented by very many people.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.


Jul 22, 2010, 03:03 am Last Edit: Jul 22, 2010, 03:05 am by lorenzop Reason: 1
awesome! putting it on the arduino website some place permanently?

I'll try it out and hopefully learn a lot from it. I might even come up with a good use for it. long distance ethernet/laser bridge? I was thinking, solar power the receiver end, add wifi, and set it up in the woods some place near home and a camp site. laptop internet access in remote areas. I had a perfect use for this once, before I moved.

btw, I like your music too. metal and screamo is great, but ambient types of music are nice while working long hours at my desk.


Unfortunately I've not had time to make any progress at all with this :(

The udp library is available here :-
You need to copy the file into the existing Ethernet library.

I'd like to put it up permanently eventually, but really would like to have the mixed libraries issue resolved first. Till then it can stay on my site :)

Glad you like the music - thanks ;)


O, but sublime coding!

Wonder if the Sparkfun WiFly or other Arduino flavoured WiFi excitables need some special hurdy-gurdy to mesh with DHCP?


Nov 11, 2010, 08:10 pm Last Edit: Nov 11, 2010, 08:23 pm by zaphil Reason: 1
This now uses just the default ethernet library in arduino-0021.

The only includes needed are:

and for the progmem stuff:

I've given it a run through and everything seems fine.

There are a few minor optimisations but no additional featured yet.

Still no DNS, but I can't get my head round that at the moment. I get the feeling I'll need two UDP ports open, but the library uses a fixed port number so I don't know how this could be resolved.

new url is:


The only includes needed are:

Somehow I can't seem to find the Udp.h file. Is there a link available for it?
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.


What version of the IDE are you using?

It's inside the Ethernet library of version 0021 - it's also in version 0019, but that one doesn't work for some reason  :(

If you don't like version 0021 (I've heard some people are having problems) maybe you could copy just the Ethernet and SPI libraries into the version you use..


Ok, I found it in 0021 in the ethernet library, and code examples in the examples folder. Thanks!
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.


Anyone got any ideas as to ho to get this to also work as a basic dns server? It only has to serve up its own name, so someone can enter something like 'heating' in a browser instead of the dotted quad url.


Hi All,

we've been working to extend the useful DHCP/Web server that Folderol has made available in this thread and published briefly about it at


It now supports multiple IP addresses and an embryonic DNS server.

I'm in bit of a hurry now, but will will monitor the thread and comment on it again.



I tried to read the page the link went to but the dark text on dark background was doing my eyes in.
I had to cut and paste the text to read it.
Maybe its just Firefox?



I tried this (I obviously have an interest) but couldn't get it to work at all. I don't understand what the data table represents and you've made no explanation of anything you've done, not even the UDP library changes.

This is most frustrating, because if you HAVE been able to get this to wotk, I'd very much like to include it in my program and make it a more complete demo.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131