Wi Fi Access Point
Wi Fi Access Point
h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#ifndef APSSID
#define APSSID "ESPap"
#define APPSK "1234567890"
#endif
IPAddress apIP(192,168,1,1);
IPAddress subnet(255, 255, 255, 0);
String Response;
String check = "";
String msg;
const int l1 = 2;
const int l2 = 5;
const int m1 = 4;
const int pwr = 14;
ESP8266WiFiMulti WiFiMulti;
ESP8266WebServer server(80);
input[type=text], select {
width: 70%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
transition: width 0.4s ease-in-out;
}
input[type=password], select {
width: 70%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
transition: width 0.4s ease-in-out;
}
input[type=submit] {
width: 20%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
div {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
</style>
<body>
<div>
<form action="/End">
<fieldset>
<label for="name">Name:</label><br>
<input type="text" id="username" name="username" placeholder="Access_Point
Name..."><br>
<label for="pwd">Password:</label><br>
<input type="password" id="pwd" name="pwd" placeholder="Access_Point
Code..."><br><br>
<input type="checkbox" onclick="myFunction()">Show Password <br><br>
<input type="submit" value="Submit"">
</fieldset>
</form>
</div>
<script>
function myFunction() {
var x = document.getElementById("pwd");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</script>
</body>
</html>
)htm";
void handleStart() {
server.send(200, "text/html", main_page);
}
void handleEnd() {
for (uint8_t i = 0; i < server.args(); i++) {
Wifi[i] = server.arg(i);
}
String Combination() {
if (cbit[0] == 1) {
digitalWrite(l1, LOW);
}
else if (cbit[0] ==0) {
digitalWrite(l1, HIGH);
}
if (cbit[1] == 1) {
digitalWrite(l2, LOW);
}
else if (cbit[1] ==0) {
digitalWrite(l2, HIGH);
}
if (cbit[2] == 1) {
digitalWrite(m1, LOW);
}
else if (cbit[2] == 0) {
digitalWrite(m1, HIGH);
}
rbit[0] = 1-digitalRead(l1);
rbit[1] = 1-digitalRead(l2);
rbit[2] = 1-digitalRead(m1);
return msg;
}
void Reboot() {
x=millis();
if (x >= boot_time || boot == 1) {
boot = 0;
delay(1000);
ESP.reset();
}
}
void Shutdown() {
if (power == 1) {
power == 0;
delay(1000);
digitalWrite(m1, HIGH);
delay(1000);
digitalWrite(l2, HIGH);
delay(1000);
digitalWrite(l1, HIGH);
delay(1000);
digitalWrite(pwr, HIGH);
}
}
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
return payload;
}
void Upload() {
if(msg != check) {
String status= "http://192.168.43.207:8000/CONTROL_PANEL_1/"+msg;
check = msg;
}
}
void Download() {
String info= "http://192.168.43.207:8000/CONTROL_PANEL_1/ESP";
if (String(Response[0]) == "1") {
cbit[0] = 1;
} else {
cbit[0] = 0;
}
if (String(Response[1]) == "1") {
cbit[1] = 1;
} else {
cbit[1] = 0;
}
if (String(Response[2]) == "1") {
cbit[2] = 1;
} else {
cbit[2] = 0;
}
if (String(Response[3]) == "1") {
boot = 1;
} else {
boot = 0;
}
if (String(Response[4]) == "1") {
power = 1;
} else {
power = 0;
}
msg = Combination();
previousMillis_1 = currentMillis_1;
}
else {
Serial.println("WiFi Disconnected");
}
}
}
void setup() {
Serial.begin(115200);
Serial.println();
pinMode(l1, OUTPUT);
pinMode(l2, OUTPUT);
pinMode(m1, OUTPUT);
pinMode(pwr, OUTPUT);
digitalWrite(l1, HIGH);
digitalWrite(l2, HIGH);
digitalWrite(m1, HIGH);
digitalWrite(pwr, LOW);
WiFi.mode(WIFI_AP_STA);
WiFi.softAPConfig(apIP, apIP, subnet);
WiFi.softAP(ssid, password);
server.on("/Start", handleStart);
server.on("/End", handleEnd);
server.begin();
}
void loop() {
if (WiFiMulti.run() != WL_CONNECTED) {
for(int i=0; i<sizeof(Wifi[0]); i++){
User_Name[i] = Wifi[0][i];
}
for(int i=0; i<sizeof(Wifi[1]); i++){
Code[i] = Wifi[1][i];
}
WiFiMulti.addAP(User_Name, Code);
Serial.println("WiFi not connected!");
}
if (WiFiMulti.run() == WL_CONNECTED) {
Download();
Reboot();
Shutdown();
Upload();
}
server.handleClient();
}