/******************************************************************* Written by Marco Schwartz for Open Home Automation. BSD license, all text above must be included in any redistribution Based on the original sketches supplied with the ESP8266/Arduino implementation written by Ivan Grokhotkov Modified by bsp.embed@gmail.com. Check our YouTube channel BSPEmbed\ ******************************************************************/ /* Required libraries */ #include /* WiFi Parameters of Your Router */ const char* ssid = "SKY0****"; const char* password = "HHYX****"; /* Create an instance of the server */ WiFiServer server(80); /* Port Pins */ //int output_pin = 2; int output_pin = 5; int Indicator_pin = 2; void setup() { Serial.begin(115200); delay(10); pinMode(output_pin, OUTPUT); pinMode(Indicator_pin, OUTPUT); digitalWrite(output_pin, 0); Serial.println(); /* For debug console */ Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); /* Connect to WiFi network */ while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); server.begin(); /* Start the server */ Serial.println("Server started"); Serial.println(WiFi.localIP()); /* Print the IP address */ digitalWrite(Indicator_pin, 0); /* Indicate by LED */ delay (500); digitalWrite(Indicator_pin, 1); /* Indicate by LED off */ } void loop() { WiFiClient client = server.available(); /* Check if a client has connected */ if (!client) return; Serial.println("new client"); /* Wait until the client sends some data */ while(!client.available()) delay(1); String req = client.readStringUntil('\r'); /* Read the first line of the request */ Serial.println(req); client.flush(); if (req.indexOf("/on") != -1) /* check the request */ {digitalWrite(output_pin, 1); /* set high for opto to "press button" */ digitalWrite(Indicator_pin, 0); /* turn LED on to indicate action*/ delay (500); /* wait half a second for "press button" to be seen by kettle*/ digitalWrite(output_pin, 0); /* set low to opto to release "button press" */ digitalWrite(Indicator_pin, 1); /* turn LED off again */ } else if (req.indexOf("/off") != -1) /* remnant of original code */ digitalWrite(output_pin, 1); /* remnant of original code */ client.flush(); /* Prepare the response */ String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"; s += ""; s += ""; s += ""; s += ""; s += ""; s += "
"; s += "

Kettle Control V1.1

"; s += "
"; s += "
"; // s += "
"; s += "
"; s += ""; s += ""; client.print(s); /* Send the response to the client */ delay(1); Serial.println("Client disconnected"); /* The client will actually be disconnected */ /* when the function returns and 'client' object is detroyed */ }