#include #include boolean reading = false; // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x49, 0xD6 }; byte ip[] = { 169,254,63,178 }; static char baseurl[]="http://169.254.63.178/"; Server server = Server(80); //port 80 void setup(){ //Pins 10,11,12 & 13 are used by the ethernet shield pinMode(9, OUTPUT); Ethernet.begin(mac, ip); server.begin(); } void loop(){ // listen for incoming clients, and process qequest. checkForClient(); } void checkForClient(){ Client client = server.available(); if (client) { // an http request ends with a blank line boolean currentLineIsBlank = true; boolean sentHeader = false; while (client.connected()) { if (client.available()) { if(!sentHeader){ // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); client.println("LED switch"); client.println("
"); client.println(""); client.println("
"); client.println("
"); client.println(""); client.println("
"); sentHeader = true; } char c = client.read(); if(reading && c == ' ') reading = false; if(c == '?') reading = true; //found the ?, begin reading the info if(reading){ Serial.print(c); if(c == '0') { digitalWrite(9, LOW); } if(c == '1') { digitalWrite(9, HIGH); } } if (c == '\n' && currentLineIsBlank) break; if (c == '\n') { currentLineIsBlank = true; }else if (c != '\r') { currentLineIsBlank = false; } } } delay(1); // give the web browser time to receive the data client.stop(); // close the connection: } }