Semua Tentang Belajar Teknologi Digital Dalam Kehidupan Sehari - Hari

Sabtu, 03 Juli 2021

[ ESP 8266 ] Wireless Key Via Wifi - Part 1 - Asynchronous Web Server

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

Share:

0 komentar:

Posting Komentar

Kontak Penulis



12179018.png (60×60)
+628155737755

Mail : ahocool@gmail.com

Site View

Categories

555 (8) 7 segmen (3) adc (4) amplifier (2) analog (19) android (14) antares (11) arduino (27) artikel (11) attiny (3) attiny2313 (19) audio (5) baterai (5) blog (1) bluetooth (1) chatgpt (2) cmos (2) crypto (2) dasar (46) digital (11) dimmer (5) display (3) esp8266 (26) euro2020 (13) gcc (1) gsm (1) iklan (1) infrared (2) Input Output (3) iot (75) jam (7) jualan (12) kereta api (1) keyboard (1) keypad (3) kios pulsa (2) kit (6) komponen (17) komputer (3) komunikasi (1) kontrol (8) lain-lain (8) lcd (2) led (14) led matrix (6) line tracer (1) lm35 (1) lora (11) lorawan (2) MATV (1) memory (1) metal detector (4) microcontroller (70) micropython (6) mikrokontroler (2) mikrokontroller (14) mikrotik (5) modbus (9) mqtt (3) ninmedia (5) ntp (1) paket belajar (19) palang pintu otomatis (1) parabola (88) pcb (2) power (1) praktek (2) project (33) proyek (1) python (8) radio (28) raspberry pi (9) remote (1) revisi (1) rfid (1) robot (1) rpm (2) rs232 (1) script break down (3) sdcard (3) sensor (2) sharing (3) signage (1) sinyal (1) sms (6) software (18) solar (1) solusi (1) tachometer (2) technology (1) teknologi (2) telegram (2) telepon (9) televisi (167) television (28) telkomiot (5) transistor (2) troubleshoot (3) tulisan (94) tutorial (108) tv digital (6) tvri (2) vu meter (2) vumeter (2) wav player (3) wayang (1) wifi (3) yolo (7)

Arsip Blog

Diskusi


kaskus
Forum Hobby Elektronika