#include #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 }; const int LED = A2; long laundryIsDoneSince = -1; boolean LEDon; Server server(80); void setup() { Ethernet.begin(mac, ip, gateway, subnet); server.begin(); Serial.begin(9600); pinMode(LED, INPUT); } void loop() { // listen for incoming clients Client client = server.available(); // Signal from washing machine (LED) is unstable // so we have to watch it for some time LEDon = false; long start = millis(); while ((start+100)>millis()){ if(!digitalRead(LED)) { LEDon = true; break; } } if (LEDon) { if (laundryIsDoneSince==-1){ laundryIsDoneSince = millis(); } Serial.println("LED is on"); } else { laundryIsDoneSince=-1; Serial.println("LED is off"); } if (client) { // Some code is taken frpm the official HTTPServer example boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); if (c == '\n' && currentLineIsBlank) { client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); client.println("







"); client.println("
"); if (LEDon) { long minutesDone = ((millis()-laundryIsDoneSince)/1000/60)+1; client.print(""); // Smiley :) client.print("

"); Serial.println(minutesDone); if (minutesDone > 1) { client.print("...since "); client.print(minutesDone); client.print(" minutes!"); } } else { client.print("Nope, not yet..."); } client.println("
"); break; } if (c == '\n') { currentLineIsBlank = true; } else if (c != '\r') { currentLineIsBlank = false; } } } // close the connection: client.stop(); } delay(2000); }