Semua Tentang Belajar Teknologi Digital Dalam Kehidupan Sehari - Hari

Sabtu, 03 Juli 2021

[ ESP 8266 ] Wireless Key Via Wifi - Part 3 - Combine Wifi + Sd Card

We have come to the end of my project to design a motorbike wireless key,  based on wifi + sd card, where we will combine the previous discussion, first part is esp8266 as an asynchronous webserver and the second discussion regarding the SD Card. So this 2 parts needs to be understood first so that it is not too confusing for our readers.

Broadly speaking, the objectives to be achieved from this practice series are:

  • Using ESP8266 as an access point and webserver to be accessed by smartphones and then controlling the relay connected to the electric motor lock system
  • The SD card is used as a storage medium for wifi parameters and the answer key / challenge code that the user will solve via a smartphone

The circuit that I designed as follows:

But this time I will focus only on the important part and have never been discussed in the previous 2 series of articles, namely the wifi setting from sd card and questions for passwords, where users can write their own wifi name on the SD card via PC/Laptop and make this device can be changed as desired. 

Here I use a settings file called lock.txt which contains the data:

2,year of purchase,2012
4,your cat name,pussy

The top line of wifi, mybike, iamverycool is the setting for the wifi name and password (at least 8 characters). While the next is a sequence of 5 questions that can be solved to turn on the motor contact relay.

The script for reading the contents of the file per line is then parsed as follows:

dataFile ="lock.txt");

  if (dataFile) {

    while (dataFile.available()) {

    buffer = dataFile.readStringUntil('\r\n');
   //parsing text for wifi and password
    if(getStringPartByNr(buffer,',',0) == "wifi")
    ssid =  getStringPartByNr(buffer,',',1);
    password = getStringPartByNr(buffer,',',2);
    //open the question and answer as the number of sequence
    else if(getStringPartByNr(buffer,',',0) == String(sequ))
    Serial.print("question : ");
    key = getStringPartByNr(buffer,',',1);
    Serial.print(" - answer : ");
    chal =getStringPartByNr(buffer,',',2); 

Meanwhile, to make changes to the questions so that they are not always the same as those asked, it is necessary to carry out a process of adding sequences that are stored in the seq.txt file. It is similar to a random process / choosing questions at randomly order.

SD.remove("seq.txt");  //erase the file then make a new one
  File myFile ="seq.txt", FILE_WRITE);
  if (myFile) // it opened OK
    Serial.println("Writing to seq.txt");
    sequ++; //add sequence
    if(sequ > maxsequ) sequ= 1; //back to start
    //write to SD card for new sequence
    Serial.print("current sequence :");
    Serial.println("Error opening seq.txt");

To compare whether the answer is correct or not, a comparison is made in the input form that is responded to by the form submit asynchronously.

rver.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("Answer : ");

    //if compared and correct
    if(inputMessage == chal)

    request->send(200, "text/html", SendCorrect());

     olkey = key ; 
     request->send(200, "text/html", SendWrong(olkey,inputMessage));

    writeToFile();  // add sequence to sd card


The results are quite satisfactory and the questions can be changed as desired.

Because it's still in the form of a web and the format is a regular GET, then for development it can be wrapped into an Android APK which is quite simple, you only need to change the HTML web to an Android application. Also, if you want to be cool, you can include a second relay to start it via the button on the smartphone screen.


0 komentar:

Posting Komentar

Kontak Penulis

12179018.png (60×60)

HP: 081331339072
Mail :

Site View


555 (8) 7 segmen (3) adc (4) amplifier (2) analog (15) android (12) antares (6) arduino (22) artikel (11) attiny (3) attiny2313 (19) audio (5) baterai (5) blog (1) bluetooth (1) cmos (2) crypto (2) dasar (46) digital (10) display (3) esp8266 (25) euro2020 (13) gcc (1) iklan (1) infrared (2) Input Output (3) iot (46) jam (7) jualan (12) kereta api (1) keyboard (1) keypad (3) kios pulsa (2) kit (6) komponen (17) komputer (3) komunikasi (1) kontrol (7) lain-lain (8) lcd (2) led (14) led matrix (6) line tracer (1) lm35 (1) lora (4) MATV (1) memory (1) metal detector (4) microcontroller (70) micropython (6) mikrokontroller (13) mikrotik (5) mqtt (3) ninmedia (3) ntp (1) paket belajar (19) palang pintu otomatis (1) parabola (85) pcb (2) power (1) praktek (2) project (33) proyek (1) python (5) radio (15) raspberry pi (4) remote (1) revisi (1) rfid (1) robot (1) rpm (2) rs232 (1) script break down (3) sdcard (3) sensor (1) 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 (162) television (28) transistor (2) troubleshoot (3) tulisan (85) tutorial (92) tv digital (3) tvri (2) vu meter (2) vumeter (2) wav player (3) wayang (1) wifi (3)

Arsip Blog


Forum Hobby Elektronika