Best practices for using DHCP

Now that I’ve got the ENC28J60 working with the Cerb40 (thanks, Aron!), I’m wondering what might be the best way to initialize the network upon boot. For my first pass, I simply called EnableStaticIP() with a random APIPA address (see RFC 3927: Dynamic Configuration of IPv4 Link-Local Addresses ), and then immediately called EnableDhcp(). Is this necessary, or should I simply check to see if DHCP is enabled (.IsDhcpEnabled) and leave it alone if it is? If the DHCP lease has expired, will it be automatically renewed, or do I need to manually call RenewDhcpLease()? Is there any way for me to know when the lease expires? Is this all taken care of automatically?

Lease Expiry is not something exposed in the framework today. I don’t think it’s “handled” at all, if your IP expires the device will retain it and it could potentially be reallocated by the DHCP server. There’s no way around this except to be explicit in your own code and renew the lease periodically and hope the period you decide on is small enough to cater for the network you’re connected to.

or you could simply do a periodic ping to a known IP or domain and if the ping fails, reinitialize the network.
also take a look here. the lease time should be in the Ack DHCPREQUEST. not sure if NETMF handles that info or not.

Good Luck.

netmf hides that, there’s no method or property to get to it

not sure why they would do that, i mean if one is not going to handle a feature, one would at least expect the developer to leave the RAW data available for those who want to handle it and parse it on their own…

i guess that’s just me…and my way of thinking.

its something we need - I’m sure we all intend to have long-running devices network connected, right? You can, as I said, just blindly refresh or reboot periodically (hourly refresh with nightly reboot or similar) and hope it all is OK…

I created an issue if anyone wants to vote:



1 Like

me too


I voted as well