#include #include byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = { 192, 168, 1, 177 }; byte gateway[] = { 192, 168, 1, 1 }; byte subnet[] = { 255, 255, 255, 0 }; EthernetServer server(80); String readString; String stav="vypnuto"; void setup(){ pinMode(6, OUTPUT); Ethernet.begin(mac, ip, gateway, subnet); server.begin(); Serial.begin(9600); } void loop() { listenForEthernetClients(); } void listenForEthernetClients() { EthernetClient client = server.available(); if (client) { Serial.println("Got a client"); boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); if (readString.length() < 100) { readString += c; } if (c == '\n') { currentLineIsBlank = true; if(readString.indexOf("on") >0) { digitalWrite(6, HIGH); stav="zapnuto"; } else if(readString.indexOf("off") >0) { digitalWrite(6, LOW); stav="vypnuto"; } else if(readString.indexOf("read") >0) { int sensorValue = analogRead(A0); stav=(String)sensorValue; } readString=""; } 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(); // print the current readings, in HTML format: client.print("Stav LED: "); client.print(stav); client.println(); break; } else if (c != '\r') { currentLineIsBlank = false; } } } delay(1); client.stop(); } }