Sophisticated security is a necessity in the digital era, supported by the increasingly affordable digital ready to use microcontroller modules. In this project series, i will design a digital key system based on the ESP8266 - which is the most favorite IOT module of the 8-bit AVR microcontroller with the advantage of a buit in wifi module.
This project is a combination of various libraries of esp8266 hardware that you can use directly or combined with various development kit modules that you can buy online, such as node mcu, wemos, esp32 and so on. In this project includes the following discussion:
- EspAsyncWebserver (from Me-No-Dev)
This is a popular and very powerful library for creating Asynchronous HTTP and WebSocket Servers on an Arduino or ESP8266. With this library, it is easier for servers that work mainly outside the main loop so that they are reliable in serving access from several users at once time.
For ESP8266 requires ESPAsyncTCP to use this library, you may need to have the latest git version of ESP8266 Arduino Core
This example is a simple form, where my wemos d1 works as SoftAP.
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <WiFiClient.h>
AsyncWebServer server(80);
const char* PARAM_INPUT = "input";
const char *ssid = "trial";
const char* password = "niceproject";
String SendHTML()
{
String ptr = " <!DOCTYPE HTML><html><head> ";
ptr +="<title>CONTOH INPUTAN</title> ";
ptr +="<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> ";
ptr +=" </head><body> ";
ptr +=" Enter Text Here .. ";
ptr +=" <br> ";
ptr +="<form action=\"/get\"> ";
ptr +=" Challenge: <input type=\"text\" name=\"input\"> ";
ptr +=" <input type=\"submit\" value=\"Submit\"> ";
ptr +="</form><br><br>";
ptr +="</body> ";
ptr +="</html> ";
return ptr;
}
void notFound(AsyncWebServerRequest *request) {
request->send(404, "text/plain", "Not found");
}
void setup(){
Serial.begin(9600);
WiFi.softAP(ssid, password );//AP
IPAddress apip = WiFi.softAPIP(); //alamat IP
Serial.print("Please connect to wifi and open in browser : \n"); //ip address
Serial.println(apip);
// Send web page with text input
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/html", SendHTML() );
});
// Send a GET request to <ESP_IP>/get?input=<inputMessage>
server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
String inputMessage;
String inputParam;
// GET input1 value on <ESP_IP>/get?input=<inputMessage>
if (request->hasParam(PARAM_INPUT) ) {
inputMessage = request->getParam(PARAM_INPUT)->value();
inputParam = PARAM_INPUT;
}
else {
inputMessage = "No challenge ";
inputParam = "none";
}
Serial.print("param : ");
Serial.println(inputParam );
Serial.print("pesan : ");
Serial.println(inputMessage);
request->send(200, "text/html", "Send with Param ("
+ inputParam + ") and message : " + inputMessage +
"<br><a href=\"/\">Return to Home Page</a>");
});
server.onNotFound(notFound);
server.begin();
}
void loop() {
// empty
}
The result is when I connect my smartphone to the wifi which is emitted by Wemos / ESP8266 and enter the address http://192.168.4.1 as follows:
- Read SD card
To be continued in the next article : https://www.aisi555.com/2021/07/esp-8266-wireless-key-via-wifi-part-2.html
0 komentar:
Posting Komentar