Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
B.Nagasuman
aurdino
Commits
c74b7ba0
Commit
c74b7ba0
authored
Jun 06, 2019
by
B.Nagasuman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
6a448f46
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
LED_Control_Over_WiFi.ino
LED_Control_Over_WiFi.ino
+92
-0
No files found.
LED_Control_Over_WiFi.ino
0 → 100644
View file @
c74b7ba0
#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> LED 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"
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment