#include #include byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(10, 10, 10, 29); // IP address, EthernetServer server(80); // create a server at port 80 String HTTP_req; // stores the HTTP request boolean LED_status = 0; // state of LED, off by default void setup() { Ethernet.begin(mac, ip); // initialize Ethernet device server.begin(); // start to listen for clients Serial.begin(9600); pinMode(2, OUTPUT); // LED on pin 2 pinMode(3, OUTPUT); // LED on pin 3 pinMode(4, OUTPUT); // LED on pin 4 } void loop() { EthernetClient client = server.available(); if (client) { // got client? boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); HTTP_req += c; if (c == '\n' && currentLineIsBlank) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); client.println(); // send web page client.println(""); client.println("");client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println(""); client.println("");client.println(""); if (HTTP_req.indexOf("r=1") > -1) { digitalWrite(2, HIGH); } if (HTTP_req.indexOf("r=0") > -1) { digitalWrite(2, LOW); } if (HTTP_req.indexOf("g=1") > -1) { digitalWrite(3, HIGH); } if (HTTP_req.indexOf("g=0") > -1) { digitalWrite(3, LOW); } if (HTTP_req.indexOf("b=1") > -1) { digitalWrite(4, HIGH); } if (HTTP_req.indexOf("b=0") > -1) { digitalWrite(4, LOW); } Serial.print(HTTP_req); HTTP_req = ""; // finished with request, empty string break; } // every line of text received from the client ends with \r\n if (c == '\n') { // last character on line of received text // starting new line with next character read currentLineIsBlank = true; } else if (c != '\r') { // a text character was received from client currentLineIsBlank = false; } } // end if (client.available()) } // end while (client.connected()) delay(1); // give the web browser time to receive the data client.stop(); // close the connection } // end if (client) }