Commit c74b7ba0 authored by B.Nagasuman's avatar B.Nagasuman

Upload New File

parent 6a448f46
#include <ESP8266WiFi.h>
#include <dht.h>
#define LED D1
const char* ssid = "MVS";
const char* password = "Welcome12#";
WiFiServer server(80);
void setup() {
wifi_connect();
pinMode(LED,OUTPUT);
server.begin();
Serial.println("Web Server Started");
Serial.print("Connect to the Server: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println();
Serial.println();
}
void loop() {
// put your main code here, to run repeatedly:
WiFiClient client = server.available();
if (!client) {
return;
}
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
int STATUS;
if (request.indexOf("/LED=0") != -1){
digitalWrite(LED,LOW);
STATUS=0;
}
if (request.indexOf("/LED=1") != -1){
digitalWrite(LED,HIGH);
STATUS=1;
}
client.flush();
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("");
client.println("<!DOCTYPE HTML>");
client.println("<style>");
client.println("body {background-color: #8baee8;}");
client.println("</style>");
client.print("<h1><b>&nbspLED STATUS </b></h1>");
client.println("<br><br><br>");
if (!STATUS) {
client.println("<a href=\"/LED=1\"\"><button style='height:1000px;width:1000px;font-size:13pt;background-color:lightgreen'><h1><b>LED OFF</b></h1> </button></a>");
}
else {
client.println("<a href=\"/LED=0\"\"><button style='height:1000px;width:1000px;font-size:13pt;background-color:red'><h1><b>LED ON</b></h1> </button></a>");
}
client.println("</html>");
delay(10);
}/*-----------------------void loop ends here------------------------------------*/
void wifi_connect(void){
Serial.begin(115200);
delay(10);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment