root / arduino-1.0 / libraries / Ethernet / examples / DhcpAddressPrinter / DhcpAddressPrinter.ino @ 58d82c77
History | View | Annotate | Download (1.26 KB)
1 | 58d82c77 | Tom Mullins | /* |
---|---|---|---|
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 | EthernetClient client; |
||
28 | |||
29 | void setup() { |
||
30 | // start the serial library: |
||
31 | Serial.begin(9600); |
||
32 | // start the Ethernet connection: |
||
33 | if (Ethernet.begin(mac) == 0) { |
||
34 | Serial.println("Failed to configure Ethernet using DHCP"); |
||
35 | // no point in carrying on, so do nothing forevermore: |
||
36 | for(;;) |
||
37 | ; |
||
38 | } |
||
39 | // print your local IP address: |
||
40 | Serial.print("My IP address: "); |
||
41 | for (byte thisByte = 0; thisByte < 4; thisByte++) { |
||
42 | // print the value of each byte of the IP address: |
||
43 | Serial.print(Ethernet.localIP()[thisByte], DEC); |
||
44 | Serial.print("."); |
||
45 | } |
||
46 | Serial.println(); |
||
47 | } |
||
48 | |||
49 | void loop() { |
||
50 | |||
51 | } |
||
52 |