Just trying to make sense of things...

Arduino DHCP Library: Version 0.4

Thursday, 30 April 2009 20:48 by jordan.terrell

Update 7/3/2011: This library no longer works with current builds of Arduino.  At some point in the future I *may* decide to create a new revision, but my current focus is not on Arduino development.  I believe there are one or more DHCP stacks based on my initial work.  If you need DHCP support for your Arduino project, I would recommend you search for one of those libraries.

I made a small update to the Arduino DHCP library to calculate the “seconds elapsed” field in the DHCP packet based on when the Arduino starts sending DHCP packets.  This may fix some issues with using a Mac as a DHCP server.  Special thanks to Arduino forum member smartperson for the suggestion.

      Download here: Arduino DHCP Library v0.4
      Previous Versions: v0.3, v0.2, v0.1

Additional instructions can be found on the original DHCP library post.

Arduino DHCP Library: Version 0.3

Saturday, 25 April 2009 08:45 by jordan.terrell

I just finished implementing some improvements to the Arduino DHCP Library as suggested by members of the Arduino forums.  Special thanks to Arduino forum members Nebster, smartperson, and thomsen for their feedback and suggestions.

      Download here: Arduino DHCP Library v0.3
      Previous Versions: v0.2, v0.1

Additional instructions can be found on the original DHCP library post.

Here is a list of the improvements in the v0.3 release:

  • Transaction ID is correctly incremented on DHCP discovery retries
  • Elapsed Seconds is now calculated and transmitted, instead of always being zero
  • You can now retrieve the following data elements:
    • Local MAC Address
    • Local IP Address
    • Subnet Mask
    • Gateway IP Address
    • DHCP Server IP Address
    • DNS Server IP Address
  • The example Arduino sketch has been updated to show:
    • How to determine if an IP address was successfully acquired
    • How to retrieve data elements acquired from the DHCP server (e.g. Local IP Address)

Arduino DHCP Library: Version 0.2

Wednesday, 22 April 2009 22:19 by jordan.terrell

I just finished adding retry capability to the DHCP library.  It will, by default, resend DHCP requests every 2 seconds, and timeout after 60 seconds.  I've also removed the need to declare a Dhcp variable. Take a look at the included example to see how to use the new library.

       Download here: Arduino DHCP Library v0.2

I hope this release solves the outstanding issues I know about.  I'm also looking for feedback on additional enhancements - ARP conflict detection, lease renewal, etc.  If you know of something that doesn't work or you would like to see added, please let me know.


Arduino DHCP Library: A Life of its Own

Wednesday, 22 April 2009 07:38 by jordan.terrell

There has been a good amount of interest in the DHCP library I made public on Sunday night.  So far I've registered almost 1200 page hits and over 140 downloads.  Not a huge following, but larger than I expected.  As a result going forward I will be treating the DHCP library as a separate project - separate from my RFID lock.

A number of people have indicated that the library is working just fine for them.  However, I know of one case where the lack of retry logic is preventing someone from using the library without making changes.  The goal with the next release is to add retry logic and hopefully trim the program size of the library.

Thanks to everyone giving their feedback and please continue to do so!

RFID Lock Prototype: DHCP Library v0.1

Sunday, 19 April 2009 22:11 by jordan.terrell

Update: This has been blogged about on the Makezine Blog – excellent!  Thanks to John Park for making this happen.

Well, I now have a version of the Arduino DHCP library that I feel moderately comfortable releasing to the wild. If you're interested in the background story, check out these posts.

       Download here: Arduino DHCP Library v0.1

I've tested it with an Arduino Duemilanove (ATMega168), but I'm positive that there will be bugs in the code and that for some (hopefully not many) people it will just plain not work.  If you do try to use it and find that it doesn't work, try using Wireshark to see what packets (if any) are flying across the wire.  Even if you can't figure it out, sending Wireshark capture logs to me will be helpful for me to debug.

In order to use the library, you need to drop the contents of the zip file into your "Arduino\hardware\libraries\Ethernet" folder.  There is a sample in the zip file called "WebClientWithDHCP" that is a modification of the standard Ethernet "WebClient" example.  There are the basic steps to get it working.

1) Add "#include "Dhcp.h" to the beginning of your Arduino sketch
2) Declare a variable of type Dhcp (e.g. "Dhcp dhcp;")
3) Call the beginWithDHCP() method, while providing it a MAC address

It has been a challenge writing this library, and I've just scratched the surface.  I don't have IP lease renewal, retry, cable detection, or even much error handling/reporting.  I'm just interested in getting feedback from the Arduino community to see if they find this useful and where to take the library next.


I Still Work With Software

Thursday, 16 April 2009 10:51 by jordan.terrell

I wanted to take a moment to assure my handful of readers that I am still very much involved/interested in software development on the .NET platform.  I’m actively learning jQuery, ASP.NET MVC, and I’m looking forward to spending some serious time in Visual Studio 2010 (and related releases) when they make Beta 1 available (I’m not dealing with the VPCs).  I’m just a little more inclined to write about my hardware escapades because such things seem to get less coverage in the blogosphere.  However, if I do come across something novel or interesting in the software-only space, I’ll be sure to write about it.

RFID Lock Prototype: DHCP Enabling - Follow Up #2

Wednesday, 15 April 2009 09:35 by jordan.terrell

Continuing on my work to build a DHCP client for my RFID Lock Prototype, I’ve read through the datasheet for the W5100 Ethernet chip (in use on the Arduino Ethernet shield) and I’ve studied the source code for the existing Arduino Ethernet library, and now I know how to work more directly with the transmit and receive buffers (16K shared across 4 sockets) on the W5100 chip.  Hopefully over the next few days I can carve out some time to refactor the DHCP library I’ve built so far to make use of this technique.  Once I do, I will release it publicly – hopefully I will find some willing beta testers.  If all goes well, perhaps it might be included in a future Arduino software release!

RFID Lock Prototype: DHCP Enabling - Follow Up

Sunday, 12 April 2009 22:02 by jordan.terrell

I've got a first pass at a DHCP library that works on the Arduino with an Atmega168 MCU.  It's working and I'm able to get an IP address, and then connect to Google.  It is still really memory intensive - I think I have less than 10 bytes of memory remaining while I'm acquiring the IP address.  I've got some ideas on how to lower the memory requirements, but that will require working with the W5100 IC at a lower level.  That's my next step, but in the meantime check out this video!


RFID Lock Prototype: DHCP Enabling

Sunday, 12 April 2009 12:15 by jordan.terrell

Last time I mentioned my RFID Lock prototype, I said that I was going to work on enabling Ethernet connectivity.  I knew that the Arduino Ethernet hardware and supporting library didn't directly support getting an IP address (and other supporting information) via DHCP.  I began to look around to see if someone had developed a library that would handle the DHCP handshake, and unfortunately I could find no such library - only comments of people wishing someone would develop such a library.  Well, I've started just that - a DHCP library for the Arduino Ethernet shield.

I found an DHCP Application Note on the W5100 (Ethernet IC used on the Ethernet shield) manufacture's web site.  It contained an entire application designed for an Atmel ATMega128 that would acquire an IP address via DHCP.  Although much of the code was written for already, I had to do a LOT of refactoring to get it to work as an Arduino library.  Good news is, I just accomplished my first DHCP handshake and acquired and IP address with it. However, it wasn't easy.  I kept experiencing some really strange behavior - random garbage being sent in the DHCP packets (I used Wireshark to monitor the traffic), the MCU would appear to freeze, and it would restart itself.

Finally, I had a hunch that I might be seeing the results of memory corruption or memory boundary violations - after all, I'm coding in the "Arduino language", which is essentially C++ under the covers.  I found a little code snippet that would check for available memory and found that I didn't have enough memory to allocate the structure I used for sending DHCP packets.  The provided Client class in the Ethernet library apparently takes up a lot of memory and I was allocating it right at the start of the Arduino program; I was using a modified version of the sample program that queries Google for sites containing "Arduino".  Once I removed the code that allocated the Client object, I saw that I had ~630 bytes of memory remaining, and I knew that the DHCP packet takes ~550 bytes of memory.  I ran the program again, and it acquired the IP address successfully.

I'm going to try and refactor a few things so that the DHCP packet memory is only used when it is needed - however, since it takes up more than half of the memory available on an Atmega168 chip, I'm thinking that it will be difficult to support on that chip.  I'm going to have to switch to the Atmega328 chip - TWICE the memory!  I plan to test it on an Arduino Duemilanove (both Atmega168 & Atmega328), and Arduino Mini (Atmega168-20AU), and the Arduino MEGA (although I read something that said the Ethernet shield might not work with the MEGA yet).

Once I get a little more polish on the library, I'll submit a patch to Arduino and publish it myself.  I'll be sure to note any memory issues or other concerns that I come across.

Magazine Subscriptions via

Thursday, 9 April 2009 10:28 by jordan.terrell

In late December and early January I subscribed to a few magazines related to building electronics/embedded hardware and I did so via  My experience has been --- less than ideal.

Upon placing the order, Amazon said that it would take roughly 2 months to receive my first issues.  Pretty standard for subscribing to periodicals.  However, for 3 (SERVO Magazine, Nuts and Volts, and Everyday Practical Electronics) of the 4 subscriptions I have still not received them.  The one subscription (Circuit Cellar) that I have started received has already missed sending me my March issue – I have the February and April issue.  I contacted Circuit Cellar customer support about this and they said they would get the March issue out to me immediately.  No big deal.

For the other subscriptions, I contacted Amazon Customer Service and they informed me that I could not deal directly with them to resolve these issues and proactively gave me contact information for the magazine distributors.  I didn’t like that fact that I couldn’t deal with Amazon, but at least I didn’t have to go hunting down phone numbers and email addresses for the distributors.

I contacted the two distributors via email and I did not get a response for a couple days.  The first one for Everyday Practical Electronics asked me to confirm my address.  Once I did, the next day I got an email saying that they are looking into it and they should get back to me in the next 5 to 7 days!  And that’s business days!  Not the response I expect.  The other distributor for SERVO Magazine and Nuts and Volts never even knew about my subscription and said that it would take another 6 to 8 weeks to receive my first copies.

This strikes me as a poorly setup and run operation between Amazon and these distributors.  I don’t know if by some random convergence of events I was the one person who was affected by this, if this is endemic to these few magazine distributors, or if this affects the entire network of distributors that sell magazines through Amazon.  All I know is I was looking for a simple way to subscribe to some magazines – so much for that!

Caveat emptor!

Tags:   ,
Categories:   General
Actions:   E-mail | | Permalink | Comments (1) | Comment RSSRSS comment feed