0% found this document useful (0 votes)
7 views2 pages

Coding Kamis

The document is a code snippet for a Wi-Fi controlled lamp system using an ESP8266 microcontroller. It establishes a server that listens for client requests to turn two lamps on or off via HTTP commands. The code contains several syntax errors and issues that need to be corrected for proper functionality.

Uploaded by

davahakimm07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Coding Kamis

The document is a code snippet for a Wi-Fi controlled lamp system using an ESP8266 microcontroller. It establishes a server that listens for client requests to turn two lamps on or off via HTTP commands. The code contains several syntax errors and issues that need to be corrected for proper functionality.

Uploaded by

davahakimm07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<wifi.

h>
const char*ssid="gtksmkn1katapang";
const char*password="Nekat1ktp";
WifiServer(80);
String header;
String Lamp1State="off";
String Lamp2State="off";
const int Lamp1=D2;
const int Lamp2=D3;
unsigned long current Time=milliss();
unsigned long current Time=0;
const long timeoutTime=2000;
void setup(){
serial.beggin(115200);
pinMode(Lamp1, OUTPUT);
pinMode(Lamp2, OUTPUT);
digitalWrite(Lamp1,LOW);
digitalWrite(Lamp2, LOW);
serial.print("connecting to");
serial.print(ssid);
Wifi.beggin(ssid, password);
while(Wifi.status() !=WL_CONNECTED){
delay(500);
serial.print(".");
}
serial.println(''');
serial..println("Wifi connected.");
serial.println("IP address:");
serial.println(Wifi.locallIP());
server.begin();

void loop(){
WifiClient client= server.available();
if(client){
currentTime=millis();
previousTime=currentTime;
serial.println("New Client");
string currentline=''';
while(client.connected()&&
currentTime-previous<=timeoutTime){
currentTime=millis();
if(client.available(){
char c=client.read();
serial.write(c);
header +=c;
if(c=='\n'){
if(currentLine.Lenght()== 0){
client.println("HTTPS/1.1200 OK");
client.println(content-type:text/html");
client.println("content:close");
client.println();
if(header.indexOf("GET /D2/on")>=0)
{
serial.println("GPIO D2 on";
Lamp1State="on";
digitalWrite(Lamp1,HIGH);
}
else if(header.indexOf("GET/D2/off")>==0){
serialprint("GPIO D2 off");
Lamp1State="off";
digitalWrite(Lamp1,LOW);
}
else if(header.indexOf("GET /D3/off")>==0){
serialprintln("GPIO D3 off");
Lamp2State="off";
digitalWrite(Lamp2,LOW);
}

client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\"
content=\"width=device-width,
initial-scale=1\">");
client.println("<style>html
{font-family:Helvetica:display:inline-block;
margin :0px auto;text-align:center;}");
client.println(".button
{background-color:blue;border:none;
color: black;padding:16px 40px;");
client.println("text-decoration:none;font-size:30px;margin:2px;cursor:pointer;}");

client.println("<body><h1>DAPAAAAAAAA PROJEKKK</1>");
client.println("<p>Lamp1-curent Condition
<b>"+Lamp1State+"</b></p>");
if(Lamp1State=="off"{
client.println("<p><a href=\"\"/D2/on\">
<button class=\"button button2\">OFF</button
><a></p>");
}

client.println("<p>Lamp2-current condition
<b>"+Lamp2State+"</b></p");
if(Lamp2State=="off"){
client.println("<p><a href=\"/D3/
on\"><button\">ON</button></a></p>");
}
else
{
client.println("<p><a href=\"/D3/off\"><button button2\">OFF</button></a></p>");
}
client.println("</body></html>")
client.println();
break;

You might also like