Skip to content

Commit 4a64ed3

Browse files
All examples to check hardware & link to help users troubleshoot
1 parent 087765f commit 4a64ed3

File tree

11 files changed

+155
-33
lines changed

11 files changed

+155
-33
lines changed

examples/AdvancedChatServer/AdvancedChatServer.ino

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,26 @@ void setup() {
5050

5151
// initialize the Ethernet device
5252
Ethernet.begin(mac, ip, myDns, gateway, subnet);
53-
// start listening for clients
54-
server.begin();
53+
5554
// Open serial communications and wait for port to open:
5655
Serial.begin(9600);
5756
while (!Serial) {
5857
; // wait for serial port to connect. Needed for native USB port only
5958
}
6059

60+
// Check for Ethernet hardware present
61+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
62+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
63+
while (true) {
64+
delay(1); // do nothing, no point running without Ethernet hardware
65+
}
66+
}
67+
if (Ethernet.linkStatus() == LinkOFF) {
68+
Serial.println("Ethernet cable is not connected.");
69+
}
70+
71+
// start listening for clients
72+
server.begin();
6173

6274
Serial.print("Chat server address:");
6375
Serial.println(Ethernet.localIP());

examples/BarometricPressureWebServer/BarometricPressureWebServer.ino

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,33 @@ void setup() {
6969
// start the SPI library:
7070
SPI.begin();
7171

72-
// start the Ethernet connection and the server:
72+
// start the Ethernet connection
7373
Ethernet.begin(mac, ip);
74+
75+
// Open serial communications and wait for port to open:
76+
Serial.begin(9600);
77+
while (!Serial) {
78+
; // wait for serial port to connect. Needed for native USB port only
79+
}
80+
81+
// Check for Ethernet hardware present
82+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
83+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
84+
while (true) {
85+
delay(1); // do nothing, no point running without Ethernet hardware
86+
}
87+
}
88+
if (Ethernet.linkStatus() == LinkOFF) {
89+
Serial.println("Ethernet cable is not connected.");
90+
}
91+
92+
// start listening for clients
7493
server.begin();
7594

7695
// initalize the data ready and chip select pins:
7796
pinMode(dataReadyPin, INPUT);
7897
pinMode(chipSelectPin, OUTPUT);
7998

80-
Serial.begin(9600);
81-
8299
//Configure SCP1000 for low noise configuration:
83100
writeRegister(0x02, 0x2D);
84101
writeRegister(0x01, 0x03);

examples/ChatServer/ChatServer.ino

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,26 @@ void setup() {
4545

4646
// initialize the ethernet device
4747
Ethernet.begin(mac, ip, myDns, gateway, subnet);
48-
// start listening for clients
49-
server.begin();
48+
5049
// Open serial communications and wait for port to open:
5150
Serial.begin(9600);
5251
while (!Serial) {
5352
; // wait for serial port to connect. Needed for native USB port only
5453
}
5554

55+
// Check for Ethernet hardware present
56+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
57+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
58+
while (true) {
59+
delay(1); // do nothing, no point running without Ethernet hardware
60+
}
61+
}
62+
if (Ethernet.linkStatus() == LinkOFF) {
63+
Serial.println("Ethernet cable is not connected.");
64+
}
65+
66+
// start listening for clients
67+
server.begin();
5668

5769
Serial.print("Chat server address:");
5870
Serial.println(Ethernet.localIP());

examples/DhcpAddressPrinter/DhcpAddressPrinter.ino

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5662
void 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-
}

examples/DhcpChatServer/DhcpChatServer.ino

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,24 @@ void setup() {
4949

5050
// Open serial communications and wait for port to open:
5151
Serial.begin(9600);
52-
// this check is only needed on the Leonardo:
53-
while (!Serial) {
52+
while (!Serial) {
5453
; // wait for serial port to connect. Needed for native USB port only
5554
}
5655

57-
5856
// start the Ethernet connection:
5957
Serial.println("Trying to get an IP address using DHCP");
6058
if (Ethernet.begin(mac) == 0) {
6159
Serial.println("Failed to configure Ethernet using DHCP");
60+
// Check for Ethernet hardware present
61+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
62+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
63+
while (true) {
64+
delay(1); // do nothing, no point running without Ethernet hardware
65+
}
66+
}
67+
if (Ethernet.linkStatus() == LinkOFF) {
68+
Serial.println("Ethernet cable is not connected.");
69+
}
6270
// initialize the Ethernet device not using DHCP:
6371
Ethernet.begin(mac, ip, myDns, gateway, subnet);
6472
}

examples/TelnetClient/TelnetClient.ino

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,24 @@ void setup() {
4747

4848
// start the Ethernet connection:
4949
Ethernet.begin(mac, ip);
50+
5051
// Open serial communications and wait for port to open:
5152
Serial.begin(9600);
5253
while (!Serial) {
5354
; // wait for serial port to connect. Needed for native USB port only
5455
}
5556

57+
// Check for Ethernet hardware present
58+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
59+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
60+
while (true) {
61+
delay(1); // do nothing, no point running without Ethernet hardware
62+
}
63+
}
64+
while (Ethernet.linkStatus() == LinkOFF) {
65+
Serial.println("Ethernet cable is not connected.");
66+
delay(500);
67+
}
5668

5769
// give the Ethernet shield a second to initialize:
5870
delay(1000);
@@ -90,7 +102,9 @@ void loop() {
90102
Serial.println("disconnecting.");
91103
client.stop();
92104
// do nothing:
93-
while (true);
105+
while (true) {
106+
delay(1);
107+
}
94108
}
95109
}
96110

examples/UDPSendReceiveString/UDPSendReceiveString.ino

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
*/
1414

1515

16-
#include <SPI.h> // needed for Arduino versions later than 0018
1716
#include <Ethernet.h>
18-
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
19-
17+
#include <EthernetUdp.h>
2018

2119
// Enter a MAC address and IP address for your controller below.
2220
// The IP address will be dependent on your local network:
@@ -43,11 +41,28 @@ void setup() {
4341
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
4442
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
4543

46-
// start the Ethernet and UDP:
44+
// start the Ethernet
4745
Ethernet.begin(mac, ip);
48-
Udp.begin(localPort);
4946

47+
// Open serial communications and wait for port to open:
5048
Serial.begin(9600);
49+
while (!Serial) {
50+
; // wait for serial port to connect. Needed for native USB port only
51+
}
52+
53+
// Check for Ethernet hardware present
54+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
55+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
56+
while (true) {
57+
delay(1); // do nothing, no point running without Ethernet hardware
58+
}
59+
}
60+
if (Ethernet.linkStatus() == LinkOFF) {
61+
Serial.println("Ethernet cable is not connected.");
62+
}
63+
64+
// start UDP
65+
Udp.begin(localPort);
5166
}
5267

5368
void loop() {

examples/UdpNtpClient/UdpNtpClient.ino

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,19 @@ void setup() {
5454
; // wait for serial port to connect. Needed for native USB port only
5555
}
5656

57-
5857
// start Ethernet and UDP
5958
if (Ethernet.begin(mac) == 0) {
6059
Serial.println("Failed to configure Ethernet using DHCP");
60+
// Check for Ethernet hardware present
61+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
62+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
63+
} else if (Ethernet.linkStatus() == LinkOFF) {
64+
Serial.println("Ethernet cable is not connected.");
65+
}
6166
// no point in carrying on, so do nothing forevermore:
62-
for (;;)
63-
;
67+
while (true) {
68+
delay(1);
69+
}
6470
}
6571
Udp.begin(localPort);
6672
}

examples/WebClient/WebClient.ino

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// Enter a MAC address for your controller below.
2121
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
2222
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
23+
2324
// if you don't want to use DNS (and reduce your sketch size)
2425
// use the numeric IP instead of the name for the server:
2526
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
@@ -58,7 +59,16 @@ void setup() {
5859
Serial.println("Initialize Ethernet with DHCP:");
5960
if (Ethernet.begin(mac) == 0) {
6061
Serial.println("Failed to configure Ethernet using DHCP");
61-
// no point in carrying on, so do nothing forevermore:
62+
// Check for Ethernet hardware present
63+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
64+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
65+
while (true) {
66+
delay(1); // do nothing, no point running without Ethernet hardware
67+
}
68+
}
69+
if (Ethernet.linkStatus() == LinkOFF) {
70+
Serial.println("Ethernet cable is not connected.");
71+
}
6272
// try to congifure using IP address instead of DHCP:
6373
Ethernet.begin(mac, ip, myDns);
6474
} else {
@@ -119,7 +129,9 @@ void loop() {
119129
Serial.println();
120130

121131
// do nothing forevermore:
122-
while (true);
132+
while (true) {
133+
delay(1);
134+
}
123135
}
124136
}
125137

examples/WebClientRepeating/WebClientRepeating.ino

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,16 @@ void setup() {
6262
Serial.println("Initialize Ethernet with DHCP:");
6363
if (Ethernet.begin(mac) == 0) {
6464
Serial.println("Failed to configure Ethernet using DHCP");
65-
// no point in carrying on, so do nothing forevermore:
65+
// Check for Ethernet hardware present
66+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
67+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
68+
while (true) {
69+
delay(1); // do nothing, no point running without Ethernet hardware
70+
}
71+
}
72+
if (Ethernet.linkStatus() == LinkOFF) {
73+
Serial.println("Ethernet cable is not connected.");
74+
}
6675
// try to congifure using IP address instead of DHCP:
6776
Ethernet.begin(mac, ip, myDns);
6877
Serial.print("My IP address: ");

examples/WebServer/WebServer.ino

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,23 @@ void setup() {
4646
while (!Serial) {
4747
; // wait for serial port to connect. Needed for native USB port only
4848
}
49-
49+
Serial.println("Ethernet WebServer Example");
5050

5151
// start the Ethernet connection and the server:
5252
Ethernet.begin(mac, ip);
53+
54+
// Check for Ethernet hardware present
55+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
56+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
57+
while (true) {
58+
delay(1); // do nothing, no point running without Ethernet hardware
59+
}
60+
}
61+
if (Ethernet.linkStatus() == LinkOFF) {
62+
Serial.println("Ethernet cable is not connected.");
63+
}
64+
65+
// start the server
5366
server.begin();
5467
Serial.print("server is at ");
5568
Serial.println(Ethernet.localIP());

0 commit comments

Comments
 (0)