#include #include #include const char *ssid = "YOUR WIFI NAME HERE"; const char *password = "WIFI PASSWORD HERE"; char wiFiHostname[] = "Home Dynamic"; ESP8266WebServer server(80); const char* www_username = "homedynamic"; const char* www_password = "homedynamic"; const int led = 2; //GPIO2 void handleRoot() { if(!server.authenticate(www_username, www_password)) return server.requestAuthentication(); int size=1000; char temp[size]; int sec = millis() / 1000; int min = sec / 60; int hr = min / 60; snprintf ( temp, size, "

Wifi Enabled Switch_On:switch|on_Off:switch|on

"); server.send ( 200, "text/html", temp ); } void setup() { Serial.begin(9600); delay(1000); WiFi.softAP(ssid, password); IPAddress myIP = WiFi.softAPIP(); pinMode(led, OUTPUT); digitalWrite ( led, HIGH ); //URLs available to query while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } server.on("/info", handleRoot); server.on ( "/switch/on", turnON ); server.on ( "/switch/off", turnOFF ); server.begin(); Serial.println("Home Dynamic server started"); Serial.println(WiFi.localIP()); } void turnON(){ if(!server.authenticate(www_username, www_password)) return server.requestAuthentication(); digitalWrite ( led, HIGH ); int size=1000; char temp[size]; int sec = millis() / 1000; int min = sec / 60; int hr = min / 60; snprintf ( temp, size, "

ESP-1 is now on

"); server.send ( 200, "text/html", temp); } void turnOFF(){ if(!server.authenticate(www_username, www_password)) return server.requestAuthentication(); digitalWrite ( led, LOW ); int size=1000; char temp[size]; int sec = millis() / 1000; int min = sec / 60; int hr = min / 60; snprintf ( temp, size, "

ESP-1 is now off

" ); server.send ( 200, "text/html", temp); } void loop() { server.handleClient(); }