-
Notifications
You must be signed in to change notification settings - Fork 0
/
Wifi.ino
38 lines (34 loc) · 895 Bytes
/
Wifi.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <WiFi.h>
const char* ssid = "Shruti-ESP"; //Enter name to be displayed
const char* Password = "Shruti123";
WiFiServer server(80);
String html ="<!DOCTYPE html>\
<html>\
<body>\
<form>\
<button name=\"LED\" button value=\"ON\" type=\"submit\">LED ON</button> \
<button name=\"LED\" button value=\"OFF\" type=\"submit\">LED OFF</button> \
</form> \
</body \
</html>";
void setup() {
Serial.begin(115200);
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
WiFi.softAP(ssid, Password);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP Address: ");
Serial.print(IP);
server.begin();
}
void loop() {
WiFiClient client = server.available();
if(client)
{
String request = client.readStringUntil('\r');
if (request.indexOf("LED=ON")>=0)digitalWrite(2, HIGH);
if (request.indexOf("LED=OFF")>=0)digitalWrite(2, LOW);
client.print(html);
request="";
}
}