Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aviantotiyo committed Aug 1, 2024
0 parents commit 5d30da9
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
85 changes: 85 additions & 0 deletions ESP_AP.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include <WiFi.h>
#include <ESPAsyncWebServer.h>

// SSID dan Password untuk AP Mode
const char *ssid = "ESP32-Access-Point";
const char *password = "12345678";

// Inisialisasi server di port 80
AsyncWebServer server(80);

// HTML form untuk memasukkan username dan password
const char* loginPage = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
<title>ESP32 Setup</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h2>ESP32 Login</h2>
<form action="/login" method="post">
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
)rawliteral";

// Halaman untuk pengaturan setelah login
const char* settingsPage = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
<title>ESP32 Settings</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h2>ESP32 Settings</h2>
<p>Welcome to the settings page!</p>
</body>
</html>
)rawliteral";

// Function untuk menangani permintaan login
void handleLoginRequest(AsyncWebServerRequest *request) {
if (request->hasParam("username", true) && request->hasParam("password", true)) {
String username = request->getParam("username", true)->value();
String password = request->getParam("password", true)->value();

// Cek username dan password
if (username == "admin" && password == "admin") {
request->send(200, "text/html", settingsPage);
} else {
request->send(401, "text/html", "Login Failed");
}
} else {
request->send(400, "text/html", "Bad Request");
}
}

void setup() {
// Mengatur mode AP
WiFi.softAP(ssid, password);

// Menampilkan IP Address
Serial.begin(115200);
Serial.print("AP IP address: ");
Serial.println(WiFi.softAPIP());

// Mengatur route untuk halaman login
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/html", loginPage);
});

// Mengatur route untuk menangani login request
server.on("/login", HTTP_POST, handleLoginRequest);

// Memulai server
server.begin();
}

void loop() {
// Tidak ada yang dilakukan di loop()
}
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# ESP32 Access Point with Login Page

This project sets up an ESP32 as an Access Point (AP) with a login page. Users can connect to the AP and log in with a username and password to access a settings page.

## Description

This project is designed to help developers set up an ESP32 as an Access Point with a simple login interface. However, there is an important note regarding the ESPAsyncWebServer library. If you download the ESPAsyncWebServer library directly from the Arduino IDE Library Manager, you might encounter errors when compiling the code for the ESP32. These errors are due to some functions in the library that are not compatible with the ESP32.

To resolve this, you can use a pre-modified version of the ESPAsyncWebServer library that has been adjusted for ESP32 compatibility. You can download this modified library directly from the provided link to ensure smooth operation.

## Features

- Creates an AP with a specified SSID and password
- Hosts a web server on the ESP32
- Provides a login page for users to enter their username and password
- Displays a settings page upon successful login

## Prerequisites

- [Arduino IDE](https://www.arduino.cc/en/software)
- [ESP32 Board Package](https://dl.espressif.com/dl/package_esp32_index.json)
- [AsyncTCP Library](https://github.com/me-no-dev/AsyncTCP)
- Modified ESPAsyncWebServer Library (Download from the provided link)

## Installation

1. **Install ESP32 Board Package**

- Open Arduino IDE.
- Go to `File` > `Preferences`.
- Add the following URL to the "Additional Board Manager URLs":
```
https://dl.espressif.com/dl/package_esp32_index.json
```
- Go to `Tools` > `Board` > `Boards Manager`.
- Search for "esp32" and install the latest version.
2. **Install Required Libraries**
- Go to `Sketch` > `Include Library` > `Manage Libraries...`.
- Search for `AsyncTCP` and install it.
3. **Install Modified ESPAsyncWebServer Library**
- Download the modified ESPAsyncWebServer library from the provided link.
- Extract the downloaded file.
- Copy the extracted folder to your Arduino libraries directory (usually located in `Documents/Arduino/libraries`).
## Usage
1. **Upload the Code**
- Open the `ESP32_Access_Point.ino` file in Arduino IDE.
- Select the appropriate ESP32 board from `Tools` > `Board`.
- Connect your ESP32 board to your computer.
- Click the Upload button to upload the code to your ESP32.
2. **Connect to the Access Point**
- Connect to the Wi-Fi network with SSID `ESP32-Access-Point` and password `12345678`.
- Open a web browser and navigate to the IP address displayed in the Serial Monitor (usually `192.168.4.1`).
3. **Login**
- Enter `admin` as both the username and password to access the settings page.
Binary file added login.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added login2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5d30da9

Please sign in to comment.