Pages: [1]   Go Down
Author Topic: sketch stays on Ethernet.begin when no ethernet connection  (Read 384 times)
0 Members and 1 Guest are viewing this topic.
New Jersey
Offline Offline
Sr. Member
****
Karma: 1
Posts: 481
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was trying out this Time NTP sketch: (http://arduino.cc/en/Tutorial/UdpNtpClient?action=sourceblock&num=1).   If the ethernet cable is not plugged in, my sketch stays on if (Ethernet.begin(mac) == 0) and never moves on.  I figured this would timeout after a while.
I have Arduino 1.01 with a Leonardo and Ethernet shield R3.

Code:
void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  // start Ethernet and UDP
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  Udp.begin(localPort);
}
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5360
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mine times out ok on a R2 ethernet shield and a Mega 2560. I disconnected the CAT5 and uploaded the sketch. It takes about a minute to print a fail. I checked with UdpNtpClient and DhcpAddressPrinter sketches.

edit: I removed the memory card from the microSD slot for both tests.
Logged

New Jersey
Offline Offline
Sr. Member
****
Karma: 1
Posts: 481
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried it again and it timed out after 62 seconds.  I guess I didn't wait long enough before.
Logged

Pages: [1]   Go Up
Jump to: