Show minor edits - Show changes to markup
[@ /*
Web client
This sketch connects to a website (http://www.google.com)
using a WiFi shield.
Circuit:
* WiFi shield attached
created 13 July 2010 by Domenico La Fauci modified 21 May 2011 by Tom Igoe */
(:source lang=arduino tabwidth=4:)
char ssid[] = "yourNetwork"; char pass[] = "secretPassword";
char ssid[] = "myNetwork"; // your network SSID (name) char pass[] = "myPassword"; // your network password
// Initialize the Ethernet client library // with the IP address and port of the server // that you want to connect to (port 80 is default for HTTP): Client client;
// Initialize the client library WiFiClient client;
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
if (client.available()) {
// if the server's disconnected, stop the client:
// do nothing forevermore:
@]
(:sourceend:)
WiFi : Client class
Whether or not the client is connected. Note that a client is considered connected if the connection has been closed but there is still unread data.
client.connected()
none
Returns true if the client is connected, false if not.
/*
Web client
This sketch connects to a website (http://www.google.com)
using a WiFi shield.
Circuit:
* WiFi shield attached
created 13 July 2010
by Domenico La Fauci
modified 21 May 2011
by Tom Igoe
*/
#include <SPI.h>
#include <WiFi.h>
#include <IPAddress.h>
char ssid[] = "yourNetwork";
char pass[] = "secretPassword";
int status = WL_IDLE_STATUS;
IPAddress server(74,125,115,105); // Google
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
Client client;
void setup() {
Serial.begin(9600);
Serial.println("Attempting to connect to WPA network...");
Serial.print("SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
// don't do anything else:
while(true);
}
else {
Serial.println("Connected to wifi");
Serial.println("\nStarting connection...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
}
}
}
void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for(;;)
;
}
}