@@ -36,7 +36,6 @@ void setup() {
3636
3737 // Open serial communications and wait for port to open:
3838 Serial.begin (9600 );
39- // this check is only needed on the Leonardo:
4039 while (!Serial) {
4140 ; // wait for serial port to connect. Needed for native USB port only
4241 }
@@ -45,12 +44,19 @@ void setup() {
4544 Serial.println (" Initialize Ethernet with DHCP:" );
4645 if (Ethernet.begin (mac) == 0 ) {
4746 Serial.println (" Failed to configure Ethernet using DHCP" );
47+ if (Ethernet.hardwareStatus () == EthernetNoHardware) {
48+ Serial.println (" Ethernet shield was not found. Sorry, can't run without hardware. :(" );
49+ } else if (Ethernet.linkStatus () == LinkOFF) {
50+ Serial.println (" Ethernet cable is not connected." );
51+ }
4852 // no point in carrying on, so do nothing forevermore:
49- for (;;)
50- ;
53+ while (true ) {
54+ delay (1 );
55+ }
5156 }
5257 // print your local IP address:
53- printIPAddress ();
58+ Serial.print (" My IP address: " );
59+ Serial.println (Ethernet.localIP ());
5460}
5561
5662void loop () {
@@ -64,7 +70,8 @@ void loop() {
6470 // renewed success
6571 Serial.println (" Renewed success" );
6672 // print your local IP address:
67- printIPAddress ();
73+ Serial.print (" My IP address: " );
74+ Serial.println (Ethernet.localIP ());
6875 break ;
6976
7077 case 3 :
@@ -76,7 +83,8 @@ void loop() {
7683 // rebind success
7784 Serial.println (" Rebind success" );
7885 // print your local IP address:
79- printIPAddress ();
86+ Serial.print (" My IP address: " );
87+ Serial.println (Ethernet.localIP ());
8088 break ;
8189
8290 default :
@@ -85,7 +93,3 @@ void loop() {
8593 }
8694}
8795
88- void printIPAddress () {
89- Serial.print (" My IP address: " );
90- Serial.println (Ethernet.localIP ());
91- }
0 commit comments