-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode
145 lines (116 loc) · 5 KB
/
Code
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
/* Put your SSID & Password */
const char* ssid = "NodeMCU"; // Enter SSID here
const char* password = "12345678"; //Enter Password here
/* Put IP Address details */
IPAddress local_ip(192,168,1,1);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
ESP8266WebServer server(80);
uint8_t LED1pin = D1;
bool LED1status = LOW;
uint8_t LED2pin = D2;
bool LED2status = LOW;
void setup() {
Serial.begin(115200);
pinMode(LED1pin, OUTPUT);
pinMode(LED2pin, OUTPUT);
WiFi.softAP(ssid, password);
WiFi.softAPConfig(local_ip, gateway, subnet);
delay(100);
server.on("/", handle_OnConnect);
server.on("/led1on", handle_led1on);
server.on("/led1off", handle_led1off);
server.on("/led2on", handle_led2on);
server.on("/led2off", handle_led2off);
server.onNotFound(handle_NotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
if(LED1status) {
digitalWrite(LED1pin, HIGH);
} else {
digitalWrite(LED1pin, LOW);
}
if(LED2status) {
digitalWrite(LED2pin, HIGH);
} else {
digitalWrite(LED2pin, LOW);
}
}
void handle_OnConnect() {
LED1status = LOW;
LED2status = LOW;
Serial.println("GPIO7 Status: OFF | GPIO6 Status: OFF");
server.send(200, "text/html", SendHTML(LED1status, LED2status));
}
void handle_led1on() {
LED1status = HIGH;
Serial.println("GPIO7 Status: ON");
server.send(200, "text/html", SendHTML(true, LED2status));
}
void handle_led1off() {
LED1status = LOW;
Serial.println("GPIO7 Status: OFF");
server.send(200, "text/html", SendHTML(false, LED2status));
}
void handle_led2on() {
LED2status = HIGH;
Serial.println("GPIO6 Status: ON");
server.send(200, "text/html", SendHTML(LED1status, true));
}
void handle_led2off() {
LED2status = LOW;
Serial.println("GPIO6 Status: OFF");
server.send(200, "text/html", SendHTML(LED1status, false));
}
void handle_NotFound() {
server.send(404, "text/plain", "Not found");
}
String SendHTML(uint8_t led1stat, uint8_t led2stat) {
String ptr = "<!DOCTYPE html> <html>\n";
ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
ptr +="<title>LED Control</title>\n";
ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
ptr +="body{margin-top: 20px;} h1 {color:#000080;margin: 0px auto 0px;} h2 {color: white;margin:50px auto 30px;} h3 {color: white;margin-bottom: 50px;} h4 {color: #444444;style=position: fixed; bottom: 0; width:100%; text-align: center} h6 {color: BLACK;margin: 0px auto 0px;font-size: 14px;}\n";
ptr +=".button {display: block;width: 80px;background-color: #1abc9c;border: black;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto 35px;cursor: pointer;border-radius: 4px;}\n";
ptr +=".button-on {background-color: green;}\n";
ptr +=".button-on:active {background-color: green;}\n";
ptr +=".button-off {background-color: red;}\n";
ptr +=".button-off:active {background-color: red;}\n";
ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n";
ptr +="body {margin-bottom:20px;background-color:ptr += #f8f8ff;}\n";
ptr +="</style>\n";
ptr +="</head>\n";
ptr +="<body>\n";
ptr +="<h1 style=\"font-size: 50px;\">INVERTIS</h1>";
ptr +="<h6><span style=\"color: #000080;font-size: 20px;\">UNIVERSITY</span><span style=\"color: red;font-size: 20px;\">BAREILLY</span></h6>\n";
//ptr +="<h6 style=\"font-size: 12px;\">UNIVERSITY BAREILLY</h6>\n";
// ptr +="<h6 style=\"font-size: 12px;\">power to design the desired</h6>\n"; // Next line with smaller font size
ptr +="<br>";
ptr +="<br>";
ptr +="<br>";
ptr +="<br>";
ptr +="<br>";
ptr +="<br>";
ptr +="<br>";
if(led1stat)
{ptr +="<p>LED1 Status: ON</p><a class=\"button button-off\" href=\"/led1off\">OFF</a>\n";}
else
{ptr +="<p>LED1 Status: OFF</p><a class=\"button button-on\" href=\"/led1on\">ON</a>\n";}
if(led2stat)
{ptr +="<p>LED2 Status: ON</p><a class=\"button button-off\" href=\"/led2off\">OFF</a>\n";}
else
{ptr +="<p>LED2 Status: OFF</p><a class=\"button button-on\" href=\"/led2on\">ON</a>\n";}
//ptr +="<h4 style=\"font-size: 10px;\">BY:- Harsh and Kunal <br> B.Tech Section:-'E'</h4>\n";
ptr +="<h4>BY:- Harsh <br> B.Tech Section:-'E'</h4>\n";
//ptr +="<h1 style=\"text-decoration: underline; font-style: italic; color: white;font-size: 35px;\">DCS</h1>"; // DCS with underline, italic, and white color
ptr +="<h1 style=\" margin: 0;text-decoration: underline;position: fixed; bottom: 30PX; width:100%; text-align: center\"><span style=\" font-style: italic;color: red;font-size:60px;\">D</span><span style=\"color: black;font-size: 60px;font-style: italic;color: black;\">CS</span></h1>\n";
ptr +="<h6 style=\"margin: 0;font-size: 9px;position: fixed; bottom: 25px; width:100%; text-align: center\">power to design the desired</h6>"; // Next line with no margin
ptr +="</body>\n";
ptr +="</html>\n";
return ptr;
}