WiFi Web Server LED Blink
WiFi Web Server LED Blink
A simple web server that lets you blink an LED via the web.
This sketch will print the IP address of your WiFi Shield (once connected)
to the Serial monitor. From there, you can open that address in a web browser
Circuit:
by Tom Igoe
*/
#include <SPI.h>
#include <WiFi.h>
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
if (WiFi.status() == WL_NO_SHIELD) {
String fv = WiFi.firmwareVersion();
if (fv != "1.1.0") {
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
delay(10000);
void loop() {
String currentLine = ""; // make a String to hold incoming data from the client
// if the current line is blank, you got two newline characters in a row.
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("Content-type:text/html");
client.println();
client.println();
break;
currentLine = "";
} else if (c != '\r') { // if you got anything else but a carriage return character,
// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /H")) {
if (currentLine.endsWith("GET /L")) {
client.stop();
Serial.println("client disonnected");
void printWifiStatus() {
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.println(ip);
Serial.print(rssi);
Serial.println(" dBm");
Serial.println(ip);