0

I'm working on a project, but just for testing, I haven't connected it to the internet yet, even though the code SHOULD be ready to roll out.

When trying to test some of my code with the serial console, I realized my program was locking up and I traced it down to here. Now my arduino uno and ethernet shield isn't currently connected to the internet, so my question is, how could I timeout this function so that I can keep my program running when there's no internet to connect it too.

Here's my code in the setup function

if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }

If anyone has any thoughts or suggestions, I'd definitely appreciate it.

2

The default timeout is 1 minute for DHCP. There is also a response timeout, and in the library millis is used for timeouts. I don't know if there is a timeout for everything, but I suppose there is.

If it stops working when no ethernet cable is connected, that would be a bug. If something like that is in the library, then you have no way to bypass the Ethernet.begin when it took too long. How long did you wait ?

This is the source code for Ethernet.begin: Ethernet.cpp

2
  • Thanks, this is good to know. I don't know for certain how long I gave it, I'm guessing the customary 30 seconds so I'll need to give this another run and double my patience, lol
    – John Sly
    Jul 17 '17 at 13:16
  • The code can actually hang up in W5100Class::execCmdSn function. It waits for command to complete by reading a register and waiting for read to return 0. If it returns non-zero for some reason (poor contact, etc.), the function will hang up. Jun 26 '18 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.