From ef15667ae844456aa8232306d59d67d3742f14ee Mon Sep 17 00:00:00 2001 From: chaveiro Date: Fri, 18 Sep 2015 00:50:17 +0100 Subject: [PATCH] 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. --- libraries/Ethernet/src/Ethernet.cpp | 4 ++-- libraries/Ethernet/src/Ethernet.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index 3eea69a2a..54cf8d64c 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -8,7 +8,7 @@ uint8_t EthernetClass::_state[MAX_SOCK_NUM] = { uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = { 0, 0, 0, 0 }; -int EthernetClass::begin(uint8_t *mac_address) +int EthernetClass::begin(uint8_t *mac_address, unsigned long timeout, unsigned long responseTimeout) { static DhcpClass s_dhcp; _dhcp = &s_dhcp; @@ -22,7 +22,7 @@ int EthernetClass::begin(uint8_t *mac_address) SPI.endTransaction(); // Now try to get our config info from a DHCP server - int ret = _dhcp->beginWithDHCP(mac_address); + int ret = _dhcp->beginWithDHCP(mac_address, timeout, responseTimeout); if(ret == 1) { // We've successfully found a DHCP server and got our configuration info, so set things diff --git a/libraries/Ethernet/src/Ethernet.h b/libraries/Ethernet/src/Ethernet.h index 2a07ff35f..083df4427 100644 --- a/libraries/Ethernet/src/Ethernet.h +++ b/libraries/Ethernet/src/Ethernet.h @@ -20,7 +20,7 @@ public: // Initialise the Ethernet shield to use the provided MAC address and gain the rest of the // configuration through DHCP. // Returns 0 if the DHCP configuration failed, and 1 if it succeeded - int begin(uint8_t *mac_address); + int begin(uint8_t *mac_address, unsigned long timeout = 60000, unsigned long responseTimeout = 4000); void begin(uint8_t *mac_address, IPAddress local_ip); void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server); void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);