#include // Used for Ethernet // **** ETHERNET SETTING **** byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x78, 0xEE }; IPAddress ip(192, 168, 0, 115); EthernetServer server(80); String readString; String header; String outAState = "vyp"; String outBState = "vyp"; String outCState = "vyp"; String outDState = "vyp"; const int outA = 2; const int outB = 3; const int outC = 4; const int outD = 5; void setup() { Serial.begin(9600); pinMode(outA, OUTPUT); pinMode(outB, OUTPUT); pinMode(outC, OUTPUT); pinMode(outD, OUTPUT); digitalWrite(outA, LOW); digitalWrite(outB, LOW); digitalWrite(outC, LOW); digitalWrite(outD, LOW); // start the Ethernet connection and the server: Ethernet.begin(mac, ip); server.begin(); Serial.print("IP Address: "); Serial.println(Ethernet.localIP()); } void loop(){ EthernetClient client = server.available(); if (client) { // If a new client connects, Serial.println(F("New Client.")); // print a message out in the serial port String currentLine = ""; // make a String to hold incoming data from the client while (client.connected()) { // loop while the client's connected if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // read a byte, then Serial.write(c); // print it out the serial monitor header += c; if (c == '\n') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: 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(F("HTTP/1.1 200 OK")); client.println(F("Content-type:text/html")); client.println(F("Connection: close")); client.println(); // turns the GPIOs on and off if (header.indexOf(F("GET /A/on")) >= 0) { Serial.println("GPIO A on"); outAState = "zap"; digitalWrite(outA, HIGH); } else if (header.indexOf("GET /A/off") >= 0) { Serial.println("GPIO A off"); outAState = "vyp"; digitalWrite(outA, LOW); } else if (header.indexOf("GET /B/on") >= 0) { Serial.println("GPIO B on"); outBState = "zap"; digitalWrite(outB, HIGH); } else if (header.indexOf("GET /B/off") >= 0) { Serial.println("GPIO B off"); outBState = "vyp"; digitalWrite(outB, LOW); } else if (header.indexOf("GET /C/on") >= 0) { Serial.println("GPIO C on"); outCState = "zap"; digitalWrite(outC, HIGH); } else if (header.indexOf("GET /C/off") >= 0) { Serial.println("GPIO C off"); outCState = "vyp"; digitalWrite(outC, LOW); } else if (header.indexOf("GET /D/on") >= 0) { Serial.println("GPIO D on"); outDState = "zap"; digitalWrite(outD, HIGH); } else if (header.indexOf("GET /D/off") >= 0) { Serial.println("GPIO D off"); outDState = "vyp"; digitalWrite(outD, LOW); } // Display the HTML web page client.println(F("")); client.println(F("")); client.println(F("")); // CSS to style the on/off b1s // Feel free to change the background-color and font-size attributes to fit your preferences client.println(F("")); // Web Page Heading client.println(F("

Nano Ethernet 4 relay

")); // GPIO A client.println("

GPIO A " + outAState + " "); if (outAState=="vyp") { client.println(F("0


")); } else { client.println(F("1


")); } // GPIO B client.println("

GPIO B " + outBState + " "); if (outBState=="vyp") { client.println(F("0


")); } else { client.println(F("1


")); } // GPIO C client.println("

GPIO C " + outCState + " "); if (outCState=="vyp") { client.println(F("0


")); } else { client.println(F("1


")); } // GPIO D client.println("

GPIO D " + outDState + " "); if (outDState=="vyp") { client.println(F("0

")); } else { client.println(F("1

")); } client.println(F("")); // The HTTP response ends with another blank line client.println(); // Break out of the while loop break; } else { // if you got a newline, then clear currentLine currentLine = ""; } } else if (c != '\r') { // if you got anything else but a carriage return character, currentLine += c; // add it to the end of the currentLine } } } // Clear the header variable header = ""; // Close the connection client.stop(); Serial.println(F("Client disconnected.")); Serial.println(""); } }