Skip to content

Commit eabc471

Browse files
committed
Updated DHCP Address printer for Ethernet library
1 parent 2f0d9d6 commit eabc471

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
DHCP-based IP printer
3+
4+
This sketch uses the DHCP extensions to the Ethernet library
5+
to get an IP address via DHCP and print the address obtained.
6+
using an Arduino Wiznet Ethernet shield.
7+
8+
Circuit:
9+
* Ethernet shield attached to pins 10, 11, 12, 13
10+
11+
created 12 April 2011
12+
by Tom Igoe
13+
14+
*/
15+
16+
#include <SPI.h>
17+
#include <Ethernet.h>
18+
19+
// Enter a MAC address for your controller below.
20+
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
21+
byte mac[] = {
22+
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
23+
24+
// Initialize the Ethernet client library
25+
// with the IP address and port of the server
26+
// that you want to connect to (port 80 is default for HTTP):
27+
Client client;
28+
29+
void setup() {
30+
// start the serial library:
31+
Serial.begin(9600);
32+
// start the Ethernet connection:
33+
Serial.println("Trying to get an IP address using DHCP");z
34+
if (Ethernet.begin(mac) == 0) {
35+
Serial.println("Failed to configure Ethernet using DHCP");
36+
// no point in carrying on, so do nothing forevermore:
37+
while(true);
38+
}
39+
// print your local IP address:
40+
Serial.print("My IP address: ");
41+
IPAddress myIPAddress = Ethernet.localIP();
42+
for (byte thisByte = 0; thisByte < 4; thisByte++) {
43+
// print the value of each byte of the IP address:
44+
Serial.print(myIPAddress[thisByte], DEC);
45+
Serial.print(".");
46+
}
47+
Serial.println();
48+
}
49+
50+
void loop() {
51+
52+
}
53+
54+

0 commit comments

Comments
 (0)