Why is this code not reporting the error more quickly?

60 seconds does look like a preset timeout time.

I think I found the solution in the EtherCard.h library which the sketch is also using and which can be found here.

In the zip folder, there is a file called EtherCard.h, which contains the following on lines 368-374:

    /**   @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
    *     @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);

The timeout of 60 seconds can be changed in the file dhcp.cpp, at line 346:

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

At least it’s clear why one has to wait exactly one minute for the error to appear.

Thanks everyone for your input!

1 Like