Skip to content

Commit c018a2b

Browse files
committed
edited some ethernet ad wifi examples
1 parent dbacb69 commit c018a2b

File tree

3 files changed

+17
-89
lines changed

3 files changed

+17
-89
lines changed

examples/DnsWebClient/DnsWebClient.ino

Lines changed: 0 additions & 81 deletions
This file was deleted.

examples/TwitterClient/TwitterClient.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ void connectToServer() {
127127
// make HTTP GET request to twitter:
128128
client.println("GET /1/statuses/user_timeline.xml?screen_name=arduino&count=1 HTTP/1.1");
129129
client.println("HOST: api.twitter.com");
130+
client.println("Connection: close");
130131
client.println();
131132
}
132133
// note the time of this connect attempt:

examples/WebClient/WebClient.ino

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
* Ethernet shield attached to pins 10, 11, 12, 13
99
1010
created 18 Dec 2009
11-
modified 9 Apr 2012
1211
by David A. Mellis
12+
modified 9 Apr 2012
13+
by Tom Igoe, based on work by Adrian McEwen
1314
1415
*/
1516

@@ -18,8 +19,14 @@
1819

1920
// Enter a MAC address for your controller below.
2021
// 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);
2330

2431
// Initialize the Ethernet client library
2532
// with the IP address and port of the server
@@ -37,8 +44,8 @@ void setup() {
3744
if (Ethernet.begin(mac) == 0) {
3845
Serial.println("Failed to configure Ethernet using DHCP");
3946
// 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);
4249
}
4350
// give the Ethernet shield a second to initialize:
4451
delay(1000);
@@ -48,7 +55,9 @@ void setup() {
4855
if (client.connect(server, 80)) {
4956
Serial.println("connected");
5057
// 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");
5261
client.println();
5362
}
5463
else {
@@ -73,8 +82,7 @@ void loop()
7382
client.stop();
7483

7584
// do nothing forevermore:
76-
for(;;)
77-
;
85+
while(true);
7886
}
7987
}
8088

0 commit comments

Comments
 (0)