Skip to content

Commit 2e6023b

Browse files
committed
edited some ethernet ad wifi examples
1 parent afc9ad2 commit 2e6023b

File tree

11 files changed

+23
-95
lines changed

11 files changed

+23
-95
lines changed

libraries/Ethernet/examples/DnsWebClient/DnsWebClient.ino

-81
This file was deleted.

libraries/Ethernet/examples/TwitterClient/TwitterClient.ino

+1
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:

libraries/Ethernet/examples/WebClient/WebClient.ino

+16-8
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

libraries/WiFi/examples/WifiTwitterClient/WifiTwitterClient.ino renamed to libraries/WiFi/examples/WiFiTwitterClient/WiFiTwitterClient.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ void connectToServer() {
132132
Serial.println("making HTTP request...");
133133
// make HTTP GET request to twitter:
134134
client.println("GET /1/statuses/user_timeline.xml?screen_name=arduino HTTP/1.1");
135-
client.println("Host:api.twitter.com");
136-
client.println("Connection:close");
135+
client.println("Host: api.twitter.com");
136+
client.println("Connection: close");
137137
client.println();
138138
}
139139
// note the time of this connect attempt:

libraries/WiFi/examples/WifiWebClient/WifiWebClient.ino renamed to libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ int keyIndex = 0; // your network key Index number (needed only for W
3131
int status = WL_IDLE_STATUS;
3232
// if you don't want to use DNS (and reduce your sketch size)
3333
// use the numeric IP instead of the name for the server:
34-
IPAddress server(173,194,73,105); // numeric IP for Google (no DNS)
35-
//char server[] = "www.google.com"; // name address for Google (using DNS)
34+
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
35+
char server[] = "www.google.com"; // name address for Google (using DNS)
3636

3737
// Initialize the Ethernet client library
3838
// with the IP address and port of the server
@@ -54,7 +54,7 @@ void setup() {
5454
}
5555

5656
// attempt to connect to Wifi network:
57-
while ( status != WL_CONNECTED) {
57+
while (status != WL_CONNECTED) {
5858
Serial.print("Attempting to connect to SSID: ");
5959
Serial.println(ssid);
6060
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
@@ -72,7 +72,7 @@ void setup() {
7272
Serial.println("connected to server");
7373
// Make a HTTP request:
7474
client.println("GET /search?q=arduino HTTP/1.1");
75-
client.println("Host:www.google.com");
75+
client.println("Host: www.google.com");
7676
client.println("Connection: close");
7777
client.println();
7878
}

0 commit comments

Comments
 (0)