Just trying to make sense of things...

Arduino DHCP Library: Trying To Submit to Arduino

Monday, 18 May 2009 10:15 by jordan.terrell

I want to submit the Arduino DHCP Library that I created to be included in the main Arduino distribution.  I tried asking what the process was on the developer’s mailing list, but I got no response.

Anyone listening out there who can clue me in on how to start the process?

RFID Lock Prototype: Ethernet Enabled

Saturday, 2 May 2009 09:09 by jordan.terrell

Now that the Arduino DHCP library is fairly stable, I’m turning my attention back to my RFID Lock prototype.  I’ve integrated the DHCP library and it’s working perfectly for me.  The next step is to work out a protocol that the lock will respond to.  I’ve decided to use connection-less UDP messages.  I’ve already hacked in the ability to lock and unlock the deadbolt by sending a simple UDP packet – this was just to test connectivity.  I’m working through the protocol in my head (e.g. the data format, different commands, etc).  I think that I want to use the Open Sound Control (OSC) protocol as the format of the messages.  The nice thing about OSC is that it doesn’t tie me to lower level protocols (HTTP, SOAP, REST, TCP, UDP, etc).  As long as I can send and receive OSC messages, I can abstract away the communication details from the RFID Lock firmware.

Once the first draft of the protocol is finalized, I’ll begin working on a secure ASP.NET MVC application that will let me interact with the RFID Lock.  I’ll also be looking for secure ways to have it interact with my cell phone.

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.


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.