Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed DHCP timeout in DHCP function as an optional parameter #361

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "EtherCard",
"version": "1.1.0",
"version": "1.1.1",
"keywords": "http, web, server, client, ethernet",
"description": "EtherCard is an IPv4 driver for the ENC28J60 chip.",
"homepage": "https://github.com/njh/EtherCard",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=EtherCard
version=1.1.0
version=1.1.1
author=Jean-Claude Wippler
maintainer=Nicholas Humfrey
sentence=EtherCard is an IPv4 driver for the ENC28J60 chip.
Expand Down
4 changes: 2 additions & 2 deletions src/EtherCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ class EtherCard : public Ethernet {
/** @brief Configure network interface with DHCP
* @param hname The hostname to pass to the DHCP server
* @param fromRam Set true to indicate whether hname is in RAM or in program space. Default = false
* @param timeout Time to wait before failing (default is 60 seconds)
* @return <i>bool</i> True if DHCP successful
* @note Blocks until DHCP complete or timeout after 60 seconds
*/
static bool dhcpSetup (const char *hname = NULL, bool fromRam =false);
static bool dhcpSetup (const char *hname = NULL, bool fromRam = false, uint16_t timeout = 60000);

/** @brief Register a callback for a specific DHCP option number
* @param option The option number to request from the DHCP server
Expand Down
4 changes: 2 additions & 2 deletions src/dhcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ static char toAsciiHex(byte b) {
return c;
}

bool EtherCard::dhcpSetup (const char *hname, bool fromRam) {
bool EtherCard::dhcpSetup (const char *hname, bool fromRam, uint16_t timeout) {
// Use during setup, as this discards all incoming requests until it returns.
// That shouldn't be a problem, because we don't have an IPaddress yet.
// Will try 60 secs to obtain DHCP-lease.
Expand All @@ -356,7 +356,7 @@ bool EtherCard::dhcpSetup (const char *hname, bool fromRam) {
dhcpState = DHCP_STATE_INIT;
uint16_t start = millis();

while (dhcpState != DHCP_STATE_BOUND && uint16_t(millis()) - start < 60000) {
while (dhcpState != DHCP_STATE_BOUND && uint16_t(millis()) - start < timeout) {
if (isLinkUp()) DhcpStateMachine(packetReceive());
}
updateBroadcastAddress();
Expand Down