I'm using an Ethernet shield with the built-in Ethernet library. I obtain an IP address using DHCP, and call Ethernet.maintain() periodically to ensure that the DHCP lease is renewed as required. So far I've never seen this fail, but maintain() can return error codes for renew fail and rebind fail and I assume that I should be handling them. What conditions would cause these errors to occur, and what's the best practise for recovering from them? Is it enough to call Ethernet.maintain() repeatedly until it returns cleanly, should I call Ethernet.begin() to reinitialise the Ethernet shield, or would it be best to reset both the Arduino and Ethernet shield using the watchdog timer?

  • You would have to set some requirements. Like, you can only lose connection for +5 minutes. Than you can try 5x once a minute (or smh). And if that won't work, you can call Ethernet.begin();. And if Ethernet.begin keeps failing, ultimately a buzzer sound/red light with diagnostic messages over your USB connection ;). This way you avoid your system being bricked when you never get a renew or new lease. The diagnostics may also prove very useful. – Paul Mar 24 '16 at 13:53

Possible causes:

  • The DHCP server might be down.
  • Or it might have lost its state (but I think they try really hard to preserve the list of leases).
  • Or some other cause which makes the server unavailable/unwilling to renew the lease.


  • If you can wait, you can retry, but otherwise I'd just say try to obtain a new lease, unless for some reason you really want to stick to the IP from the previous lease.

  • If you control the server and your network is kinda stable, you could assign a fixed IP to your device configure the server to associate it with the MAC address you gave to your device. In general, when the network setup is really stable, this might be preferable, since other entities on the network will probably cache the IP of your device and use it, should the DNS fail as well (ex: dnsmasquerade works both as dhcp server and dns). Similarly, your device doesn't have to worry anymore of the DHCP lease, because it's permanent.

  • What you described is not so much Arduino specific. Whenever you have a device in a dynamic network, you can experience the same effects. – Igor Stoppa Mar 23 '16 at 18:31
  • I appreciate that the problem of DHCP errors isn't Arduino-specific, but the best way to recover from them probably is. I wondered whether repeatedly calling Ethernet.maintain() was guaranteed to renew the lease at some point (i.e. whether either the Ethernet library or DHCP server would have the intelligence to begin a new lease, possibly with a different IP address, if the old one couldn't be renewed). However, calling Ethernet.begin() to guarantee starting a new lease seems more sensible, and from the testing I've done it doesn't appear to have any negative side-effects. – Stephen Mitchell Mar 24 '16 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.