/* Web Server A simple web server that shows the value of the analog input pins. using a WiFi shield. Circuit: * WiFi shield attached * Analog inputs attached to pins A0 through A5 (optional) created 13 July 2010 by Domenico La Fauci modified 5 June 2011 by Tom Igoe */ #include #include char ssid[] = "yourNetwork"; char pass[] = "secretpassword"; int status = WL_IDLE_STATUS; Server server(80); void setup() { // initialize serial: 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"); while(true); } else { server.begin(); Serial.print("Connected to wifi. My address:"); IPAddress myAddress = WiFi.localIp(); Serial.print(myAddress[0]); Serial.print("."); Serial.print(myAddress[1]); Serial.print("."); Serial.print(myAddress[2]); Serial.print("."); Serial.println(myAddress[3]); } } void loop() { // listen for incoming clients Client client = server.available(); if (client) { // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); client.println(""); // output the value of each analog input pin for (int analogChannel = 0; analogChannel < 6; analogChannel++) { client.print("analog input "); client.print(analogChannel); client.print(" is "); client.print(analogRead(analogChannel)); client.println("
"); } client.println(""); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(1); // close the connection: client.stop(); } }