8
8
* Ethernet shield attached to pins 10, 11, 12, 13
9
9
10
10
created 18 Dec 2009
11
- modified 9 Apr 2012
12
11
by David A. Mellis
12
+ modified 9 Apr 2012
13
+ by Tom Igoe, based on work by Adrian McEwen
13
14
14
15
*/
15
16
18
19
19
20
// Enter a MAC address for your controller below.
20
21
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
21
- byte mac[] = { 0xDE , 0xAD , 0xBE , 0xEF , 0xFE , 0xED };
22
- IPAddress server (173 ,194 ,33 ,104 ); // Google
22
+ byte mac[] = { 0xDE , 0xAD , 0xBE , 0xEF , 0xFE , 0xED };
23
+ // if you don't want to use DNS (and reduce your sketch size)
24
+ // use the numeric IP instead of the name for the server:
25
+ // IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
26
+ char server[] = " www.google.com" ; // name address for Google (using DNS)
27
+
28
+ // Set the static IP address to use if the DHCP fails to assign
29
+ IPAddress ip (192 ,168 ,0 ,177 );
23
30
24
31
// Initialize the Ethernet client library
25
32
// with the IP address and port of the server
@@ -37,8 +44,8 @@ void setup() {
37
44
if (Ethernet.begin (mac) == 0 ) {
38
45
Serial.println (" Failed to configure Ethernet using DHCP" );
39
46
// no point in carrying on, so do nothing forevermore:
40
- for (;;)
41
- ;
47
+ // try to congifure using IP address instead of DHCP:
48
+ Ethernet. begin (mac, ip) ;
42
49
}
43
50
// give the Ethernet shield a second to initialize:
44
51
delay (1000 );
@@ -48,7 +55,9 @@ void setup() {
48
55
if (client.connect (server, 80 )) {
49
56
Serial.println (" connected" );
50
57
// Make a HTTP request:
51
- client.println (" GET /search?q=arduino HTTP/1.0" );
58
+ client.println (" GET /search?q=arduino HTTP/1.1" );
59
+ client.println (" Host: www.google.com" );
60
+ client.println (" Connection: close" );
52
61
client.println ();
53
62
}
54
63
else {
@@ -73,8 +82,7 @@ void loop()
73
82
client.stop ();
74
83
75
84
// do nothing forevermore:
76
- for (;;)
77
- ;
85
+ while (true );
78
86
}
79
87
}
80
88
0 commit comments