DHCP server with interactive web server

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.

DHCP
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 :frowning:

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 :slight_smile:

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 :slight_smile:

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

DNS
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.

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 :frowning:

@zoomkat
The udp library is available here :-
http://bitbucket.org/bjoern/arduino_osc/src/tip/libraries/Ethernet/
You need to copy the file into the existing Ethernet library.

@lorenzop
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 :slight_smile:

Glad you like the music - thanks :wink:

O, but sublime coding!

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

This now uses just the default ethernet library in arduino-0021.

The only includes needed are:
Ethernet.h
SPI.h
Udp.h

and for the progmem stuff:
avr/pgmspace.h

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:
http://www.musically.me.uk/DHCP_Web_Server_12.pde

The only includes needed are:
Ethernet.h
SPI.h
Udp.h

Somehow I can't seem to find the Udp.h file. Is there a link available for it?

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 :frowning:

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!

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

http://www.aether-hemera.com/blog/default.asp?PostId=30

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.

Best,
Claudio

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?

Gordon

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.