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:


wifi,mybike,iamverycool
1,motorbike,suzuki
2,year of purchase,2012
3,city,london
4,your cat name,pussy
5,hobby,fishing


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 = SD.open("lock.txt");

  if (dataFile) {

    while (dataFile.available()) {

    buffer = dataFile.readStringUntil('\r\n');
   //parsing text for wifi and password
    if(getStringPartByNr(buffer,',',0) == "wifi")
    {
    Serial.println(buffer);
    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(key);
    Serial.print(" - answer : ");
    chal =getStringPartByNr(buffer,',',2); 
    Serial.println(chal);
    }
   }
   
    dataFile.close();


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 = SD.open("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
    myFile.print(String(sequ));
    myFile.close(); 
    Serial.print("current sequence :");
    Serial.println(String(sequ));
    }
  else 
    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 : ");
    Serial.println(inputMessage); 

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

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

    else{
     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.




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