@@ -14,7 +14,6 @@ int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long
14
14
_dhcpLeaseTime=0 ;
15
15
_dhcpT1=0 ;
16
16
_dhcpT2=0 ;
17
- _lastCheck=0 ;
18
17
_timeout = timeout;
19
18
_responseTimeout = responseTimeout;
20
19
@@ -125,6 +124,7 @@ int DhcpClass::request_DHCP_lease(){
125
124
_dhcpUdpSocket.stop ();
126
125
_dhcpTransactionId++;
127
126
127
+ _secTimeout = millis () + 1000 ;
128
128
return result;
129
129
}
130
130
@@ -396,51 +396,45 @@ int DhcpClass::checkLease(){
396
396
unsigned long now = millis ();
397
397
signed long snow = (long )now;
398
398
int rc=DHCP_CHECK_NONE;
399
- if (_lastCheck != 0 ){
400
- signed long factor;
401
- // calc how many ms past the timeout we are
402
- factor = snow - (long )_secTimeout;
403
- // if on or passed the timeout, reduce the counters
404
- if ( factor >= 0 ){
405
- // next timeout should be now plus 1000 ms minus parts of second in factor
406
- _secTimeout = snow + 1000 - factor % 1000 ;
407
- // how many seconds late are we, minimum 1
408
- factor = factor / 1000 +1 ;
409
-
410
- // reduce the counters by that mouch
411
- // if we can assume that the cycle time (factor) is fairly constant
412
- // and if the remainder is less than cycle time * 2
413
- // do it early instead of late
414
- if (_renewInSec < factor*2 )
415
- _renewInSec = 0 ;
416
- else
417
- _renewInSec -= factor;
418
-
419
- if (_rebindInSec < factor*2 )
420
- _rebindInSec = 0 ;
421
- else
422
- _rebindInSec -= factor;
423
- }
424
399
425
- // if we have a lease but should renew, do it
426
- if (_dhcp_state == STATE_DHCP_LEASED && _renewInSec <=0 ){
427
- _dhcp_state = STATE_DHCP_REREQUEST;
428
- rc = 1 + request_DHCP_lease ();
429
- }
430
-
431
- // if we have a lease or is renewing but should bind, do it
432
- if ( (_dhcp_state == STATE_DHCP_LEASED || _dhcp_state == STATE_DHCP_START) && _rebindInSec <=0 ){
433
- // this should basically restart completely
434
- _dhcp_state = STATE_DHCP_START;
435
- reset_DHCP_lease ();
436
- rc = 3 + request_DHCP_lease ();
437
- }
400
+ signed long factor;
401
+ // calc how many ms past the timeout we are
402
+ factor = snow - (long )_secTimeout;
403
+ // if on or passed the timeout, reduce the counters
404
+ if ( factor >= 0 ){
405
+ // next timeout should be now plus 1000 ms minus parts of second in factor
406
+ _secTimeout = snow + 1000 - factor % 1000 ;
407
+ // how many seconds late are we, minimum 1
408
+ factor = factor / 1000 +1 ;
409
+
410
+ // reduce the counters by that mouch
411
+ // if we can assume that the cycle time (factor) is fairly constant
412
+ // and if the remainder is less than cycle time * 2
413
+ // do it early instead of late
414
+ if (_renewInSec < factor*2 )
415
+ _renewInSec = 0 ;
416
+ else
417
+ _renewInSec -= factor;
418
+
419
+ if (_rebindInSec < factor*2 )
420
+ _rebindInSec = 0 ;
421
+ else
422
+ _rebindInSec -= factor;
438
423
}
439
- else {
440
- _secTimeout = snow + 1000 ;
424
+
425
+ // if we have a lease but should renew, do it
426
+ if (_dhcp_state == STATE_DHCP_LEASED && _renewInSec <=0 ){
427
+ _dhcp_state = STATE_DHCP_REREQUEST;
428
+ rc = 1 + request_DHCP_lease ();
441
429
}
442
430
443
- _lastCheck = now;
431
+ // if we have a lease or is renewing but should bind, do it
432
+ if ( (_dhcp_state == STATE_DHCP_LEASED || _dhcp_state == STATE_DHCP_START) && _rebindInSec <=0 ){
433
+ // this should basically restart completely
434
+ _dhcp_state = STATE_DHCP_START;
435
+ reset_DHCP_lease ();
436
+ rc = 3 + request_DHCP_lease ();
437
+ }
444
438
return rc;
445
439
}
446
440
0 commit comments