Skip to content

Commit ef15667

Browse files
chaveirocmaglie
authored andcommitted
Expose optional DHCP timout parameters to Ethernet:begin()
A no brainer update. Expose optional timeout parameter values of dhcp for user to adjust on their code. Currently if dhcp server is not available, code will block inside DhcpClass::request_DHCP_lease() for 60s. Having this parameters exposed user can specify their timeout requirements without changing the lib code. Change is backward compatible as parameters are optional and defaults to existing values.
1 parent aa92165 commit ef15667

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

libraries/Ethernet/src/Ethernet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ uint8_t EthernetClass::_state[MAX_SOCK_NUM] = {
88
uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = {
99
0, 0, 0, 0 };
1010

11-
int EthernetClass::begin(uint8_t *mac_address)
11+
int EthernetClass::begin(uint8_t *mac_address, unsigned long timeout, unsigned long responseTimeout)
1212
{
1313
static DhcpClass s_dhcp;
1414
_dhcp = &s_dhcp;
@@ -22,7 +22,7 @@ int EthernetClass::begin(uint8_t *mac_address)
2222
SPI.endTransaction();
2323

2424
// Now try to get our config info from a DHCP server
25-
int ret = _dhcp->beginWithDHCP(mac_address);
25+
int ret = _dhcp->beginWithDHCP(mac_address, timeout, responseTimeout);
2626
if(ret == 1)
2727
{
2828
// We've successfully found a DHCP server and got our configuration info, so set things

libraries/Ethernet/src/Ethernet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class EthernetClass {
2020
// Initialise the Ethernet shield to use the provided MAC address and gain the rest of the
2121
// configuration through DHCP.
2222
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded
23-
int begin(uint8_t *mac_address);
23+
int begin(uint8_t *mac_address, unsigned long timeout = 60000, unsigned long responseTimeout = 4000);
2424
void begin(uint8_t *mac_address, IPAddress local_ip);
2525
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server);
2626
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);

0 commit comments

Comments
 (0)