To me one of the biggest nuisances with Arduino is the blocking behavior of their standard Ethernet library. I use Ethernet a lot in my projects, not to say constantly, and with the default library my application would just be sitting there doing nothing while the Ethernet connection is being set up. This can even take up to a full minute (standard time-out) if no DHCP lease can be obtained.

A pull request from 2013 extended the default library with a non-blocking method. Not-so-surprisingly this was not committed into the official release. Guess the Arduino team was too busy developing bloated products that fill up the inventories of Sparkfun and the likes.

I moved away from AVR hardware quite some time ago and nowadays the Teensy is my development platform of choice. Teensy user Headroom modified said non-blocking library to work with this platform. However, DNS resolving did not work for me. I dug into the library to find the cause and implemented a small workaround. Adding a small delay in the DNS processing function seemed to fix it (line #273 in Dns.cpp). I am by no means a seasoned programmer, so I will leave finding the root cause of the problem to someone else.

The exact use of the library was not readily apparent. It took some time figuring out how to use it, because between the initially provided example and Headrooms modification some functions changed name.

Below I provide an example sketch to show you how to use it. I also incorporated macadress.h discussed here, which automatically uses the Teensys built-in MAC address for setting up the Ethernet connection. It is tested with Arduino 1.6.8, Teensyduino 1-28b, Teensy 3.1 and 3.2 and the Wiz820io Ethernet shield. It should work with any W5100/5200 based shield.

The library launches a DHCP request to the router and periodically checks to see if a lease has been obtained or is still valid. Meanwhile your sketch can do other stuff. Just keep on calling doEthernet() in your main loop(). The example sketch launches a DNS resolve request (also non-blocking) once a valid lease has been obtained and then makes a HTTP GET request to the server.