DHCP Lease renewal

Hi,

I couldn't find in documentation what happens when DHCP lease expires. Is it renewed automatically by Ethernet library, or do I need to take care of it myself?

Is it renewed automatically by Ethernet library

No.

or do I need to take care of it myself?

Yes.

Thanks for quick response.
In this case:
Is the end of lease signaled in any way? If not - how can I detect that it has ended?

Is the end of lease signaled in any way?

Good question.

If not - how can I detect that it has ended?

You can no longer communicate with the same server that you were communicating with.

You can no longer communicate with the same server that you were communicating with.

In my application my Arduino is a 'server'. It sends the messages out, and there is acknowledgment system (at the moment).

So I guess, in my case I have to add some 'heart beat' messages to confirm that I'm still connected, right?

So I guess, in my case I have to add some 'heart beat' messages to confirm that I'm still connected, right?

I'm sure SurferTim will be along sometime today, to tell us all about renewing DHCP leases. Give him time.

You must call Ethernet.maintain() in the loop function. You can call it as often as you want, like every iteration of the loop because it does nothing until half the lease time has expired.

edit: I use this. Ethernet.maintain() returns 0 if no action was taken, so nothing is printed for a zero return value.

      byte rtnVal = Ethernet.maintain();
      switch(rtnVal) {
        case 1: Serial.println(F("\r\nDHCP renew fail"));        
                break;
        case 2: Serial.println(F("\r\nDHCP renew ok"));        
                break;
        case 3: Serial.println(F("\r\nDHCP rebind fail"));        
                break;
        case 4: Serial.println(F("\r\nDHCP rebind ok"));        
                break;
      }

Thank you SurferTim,

Am I right to interpret he return code 1 and 3 of maintain() as basically the same (no IP address assigned)?

And if the return code is 4 - does it mean that my IP address is the same as it was?

Return values 1 and 3 indicate the renew failed, and the lease was not renewed. As I recall, maintain will reattempt to renew the lease at 3/4 the lease time, and again when the lease expires. edit: In the mean time, it will continue to use the ip it was last assigned.

Normally return values 2 or 4 indicate the lease was renewed successfully, usually indicating your device got the same ip as before, but not guaranteed you got the same ip. That depends on the router running the dhcp server.

Hallo, people
Please, can you help me: i thought all questions about leasing time and dhcp - my device was connected to mikrotik, and i've got all test with lease time as 1min 10min 1h 3h and 12h
BUT!

*** There is a problem
if device-client of dhcp is primary in router all things are fine

if device-client is under switch or router and dhcp server in another subnet then with lease time 12hours my client is going down and lost ip in 6 hours period if no activity on port :frowning:

So, i see in library dhcp.cpp and .h but i don't see what to do.