0% found this document useful (0 votes)
12 views

Wi Fi Access Point

Uploaded by

himanshu.228302
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)
12 views

Wi Fi Access Point

Uploaded by

himanshu.228302
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/ 7

#include <ESP8266WiFiMulti.

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);

/* Set these to your desired credentials. */


const char *ssid = APSSID;
const char *password = APPSK;

String Wifi[2] = {".", "qazxswqx"};


char User_Name[50];
char Code[50];

String Response;
String check = "";
String msg;

const int l1 = 2;
const int l2 = 5;
const int m1 = 4;
const int pwr = 14;

int cbit[3] = {0,0,0};


int rbit[3];
unsigned long x;
unsigned long boot_time = 6*60*60*1000;
int boot = 0;
int power = 0;

unsigned long previousMillis_1 = 0;


const long interval_1 = 1000;
unsigned long previousMillis_2 = 0;
const long interval_2 = 2000;

ESP8266WiFiMulti WiFiMulti;
ESP8266WebServer server(80);

String main_page = R"htm(


<!DOCTYPE html>
<html>
<style>

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;
}

body{ font-family:"Segoe UI", Tahoma, Geneva, Verdana, sans-serif;


text-align:left;
font-size: 1rem; }

</style>
<body>

<h2 style="text-align:center;">Access_Point Credentials</h2>

<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 message = "Connected to "+ server.arg(0);


server.send(200, "text/html", message);
}

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);

String msg = "";


msg += String(rbit[0]);
msg += String(rbit[1]);
msg += String(rbit[2]);

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);
}
}

String httpGETRequest(String serverName) {


WiFiClient client;
HTTPClient http;

// Your IP address with path or Domain name with URL path


http.begin(client, serverName);

// Send HTTP POST request


int httpResponseCode = http.GET();

String payload = "--";

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;

unsigned long currentMillis_2 = millis();

if(currentMillis_2 - previousMillis_2 >= interval_2) {


if ((WiFiMulti.run() == WL_CONNECTED)) {
Response = httpGETRequest(status);
// Serial.println(Response);

// save the last HTTP GET Request


previousMillis_2 = currentMillis_2;
}
else {
Serial.println("WiFi Disconnected");
}
}

check = msg;
}
}

void Download() {
String info= "http://192.168.43.207:8000/CONTROL_PANEL_1/ESP";

unsigned long currentMillis_1 = millis();

if(currentMillis_1 - previousMillis_1 >= interval_1) {


if ((WiFiMulti.run() == WL_CONNECTED)) {
Response = httpGETRequest(info);
// Serial.println(Response);

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();
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy