02. ์„ค๊ณ„

2022. 8. 28. 12:40

๐Ÿ“RFID ํฐ์ง€ํŒก์ด

โœ”๏ธ์„ผ์„œ

- RFID ๋ฆฌ๋”๊ธฐ

๊ฐ ์ขŒ์„์˜ ํ•˜๋‹จ์˜ RFID ํƒœ๊ทธ๊ฐ’์„ ์ฝ์–ด ๋“ค์—ฌ ํ•ด๋‹น ์ขŒ์„์˜ ๋ฒˆํ˜ธ๋ฅผ ์–ป๊ธฐ ์œ„ํ•œ ์žฅ์น˜์ด๋‹ค. ESP32 ์—์„œ ๋นˆ ์ขŒ์„ ์—ฌ๋ถ€๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ ๋•Œ ๋ช‡ ๋ฒˆ ์ขŒ์„์˜ ์ •๋ณด๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ์ง€ ๊ฒฐ์ •ํ•œ๋‹ค.

- ESP32

DB์— ์ ‘์†ํ•˜๊ณ  RFID ๋ฆฌ๋”๊ธฐ, ์ง„๋™๋ชจํ„ฐ, ์Šคํ”ผ์ปค, ์•ฐํ”„ ์ œ์–ด๋ฅผ ์œ„ํ•œ ๋ฉ”์ธ ์—ฐ์‚ฐ์žฅ์น˜์ด๋‹ค. RFID์˜ ํƒœ๊ทธ๊ฐ’์„ ์ฝ๊ณ  ์ด๋ฅผ DB์™€ ์—ฐ๋™ํ•˜์—ฌ ์Šคํ”ผ์ปค์—๊ฒŒ ์–ด๋–ค ์Œ์„ฑ์„ ์ถœ๋ ฅํ• ์ง€, ์ง„๋™์„ ์šธ๋ฆด์ง€ ํŒ๋‹จํ•œ๋‹ค.

- ์Šคํ”ผ์ปค&์•ฐํ”„

ESP32์—์„œ ์ „๋‹ฌ๋ฐ›์€ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ ์Œ์„ฑ์„ ์ถœ๋ ฅํ•œ๋‹ค. WAV ์Œ์„ฑ ํŒŒ์ผ์„ ์ตœ์ข…์ ์œผ๋กœ byte ๋ณ€ํ™˜์„ ํ•˜๊ณ  ์•„๋‘์ด๋…ธ์˜ talkie ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Œ์„ฑ์„ ์ถœ๋ ฅํ•œ๋‹ค.

- ์ง„๋™ ๋ชจํ„ฐ

ESP32์—์„œ ์ „๋‹ฌ๋ฐ›์€ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ ์ง„๋™์„ ์šธ๋ฆฐ๋‹ค. ํ•ด๋‹น ์ขŒ์„ ๋ฒˆํ˜ธ์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๋ฐ์ดํ„ฐ๋“ค ์ค‘ ๊ฐ€์žฅ ์ตœ์‹  ๋ฐ์ดํ„ฐ๊ฐ€ ๋นˆ์ž๋ฆฌ์ผ ๊ฒฝ์šฐ ์ง„๋™๋ชจํ„ฐ ๋ฅผ ์ž‘๋™ํ•œ๋‹ค์ง„๋™๋ชจํ„ฐ๊ฐ€ ์—„์ง€์†๊ฐ€๋ฝ์ด ๋‹ฟ๋„๋ก ์žก๋Š” ๊ฒƒ์„ ์˜ฌ๋ฐ”๋ฅธ ์ œํ’ˆ์‚ฌ์šฉ์˜ ๊ฐ€์ด๋“œ๋ผ์ธ์œผ๋กœ ์žก์•˜๋‹ค. ์ด๋Š” RFID ๋ฆฌ๋”๊ธฐ์˜ ์ธ์‹ ๋ฒ”์œ„๊ฐ€ ๋ฆฌ๋”๊ธฐ ์ •๋ฉด๊ณผ ํ›„๋ฉด์ด๊ณ  (์ธก๋ฉดX) ๊ตฌ๊ฐ„์ด ์งง์€ ๊ฒƒ์„ ๊ณ ๋ คํ•œ ๊ฒƒ์ด๋‹ค.

 

โœ”๏ธ์ˆœ์„œ๋„

 

โœ”๏ธํšŒ๋กœ ๊ตฌ์„ฑ

 

โœ”๏ธ์•„๋‘์ด๋…ธ ์ฝ”๋“œ

#include <Arduino.h>
#include <MFRC522.h>
#include <SPI.h> 
#include <WiFi.h>              
#include <HTTPClient.h>   

//์Œ์„ฑ ์ถœ๋ ฅ
#include "Talkie.h"

//์ง„๋™ ๋ชจํ„ฐ 
#define SS_PIN 5
#define RST_PIN 27

const int vibPin = 16;

const int freq = 5000;
const int vibChannel = 0;
const int resolution = 8;

const char WIFI_SSID [ ] = "";
const char WIFI_PASSWORD [ ] = "";

//select.php๋ฅผ ํ†ตํ•ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ๋˜์–ด ์žˆ๋Š” ๊ฐ’์„ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
String avalue = "http://192.168.xx.xx/select_data1.php?";
String bvalue = "http://192.168.xx.xx/select_data2.php?";
String cvalue = "http://192.168.xx.xx/select_data3.php?";

HTTPClient http;
Talkie voice;

//MP3 ํŒŒ์ผ ์† ์Œ์„ฑ์„ byte๋กœ ๋ณ€ํ™˜ํ•œ ๊ฐ’
uint8_t num1[] PROGMEM = {}
uint8_t num2[] PROGMEM = {}
uint8_t num3[] PROGMEM = {}

MFRC522 rfid(SS_PIN, RST_PIN);

//-------------------------------------------------------

void setup() {
  Serial.begin(9600);

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());

  SPI.begin(); 
  rfid.PCD_Init(); 
  Serial.println("Tap an RFID/NFC tag on the RFID-RC522 reader");

 
  ledcSetup(vibChannel, freq, resolution);
  

  ledcAttachPin(vibPin, vibChannel);
  
}

//-------------------------------------------------------

void loop() {

  int httpCode;
  String payload;
  

  String tag_uid = "";
  String rfid123;

  if (rfid.PICC_IsNewCardPresent()) {
    if (rfid.PICC_ReadCardSerial()) {
      MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
      Serial.print("RFID/NFC Tag Type: ");
      Serial.println(rfid.PICC_GetTypeName(piccType));

      // print UID in Serial Monitor in the hex format
      Serial.print("UID:");
      for (int i = 0; i < rfid.uid.size; i++) {
        Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
        Serial.print(rfid.uid.uidByte[i], HEX);
        tag_uid.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
        tag_uid.concat(String(rfid.uid.uidByte[i], HEX));
      }
      Serial.println();
      tag_uid.toUpperCase();

      rfid.PICC_HaltA(); // halt PICC
      rfid.PCD_StopCrypto1(); // stop encryption on PCD
    
    }

  }

  //-------------------------------------------------------
  //๊ฐ RFID ํƒœ๊ทธ์˜ ๊ณ ์œ ๋ฒˆํ˜ธ์™€ ์ขŒ์„ ๋ฒˆํ˜ธ๋ฅผ ๋งค์นญ
  
  if (tag_uid.substring(1) == "99 EE 59 B3")
  {
    Serial.println("1๋ฒˆ");
    rfid123 = "1";
    Serial.println(rfid123);
  }
  else if (tag_uid.substring(1) == "A0 9E 59 B3")
  {
    Serial.println("1๋ฒˆ");
    rfid123 = "1";
    Serial.println(rfid123);
  }
  else if (tag_uid.substring(1) == "C2 1F 59 B3")
  {
    Serial.println("1๋ฒˆ");
    rfid123 = "1";
    Serial.println(rfid123);
  }
 
  //--------------------------------------------
  else if (tag_uid.substring(1) == "5A 88 CE AD")
  {
    Serial.println("2๋ฒˆ");
    rfid123 = "2";
    Serial.println(rfid123);
  }
  else if (tag_uid.substring(1) == "52 7E 76 2F")
  {
    Serial.println("2๋ฒˆ");
    rfid123 = "2";
    Serial.println(rfid123);
  }
  else if (tag_uid.substring(1) == "52 B7 72 2F")
  {
    Serial.println("2๋ฒˆ");
    rfid123 = "2";
    Serial.println(rfid123);
  }
 
  //--------------------------------------------
   else if (tag_uid.substring(1) == "AB AD 5D B3")
  {
    Serial.println("3๋ฒˆ");
    rfid123 = "3";
    Serial.println(rfid123);
  }
  else if (tag_uid.substring(1) == "F0 A9 2B B3")
  {
    Serial.println("3๋ฒˆ");
    rfid123 = "3";
    Serial.println(rfid123);
  }
  else if (tag_uid.substring(1) == "13 66 A2 1C")
  {
    Serial.println("3๋ฒˆ");
    rfid123 = "3";
    Serial.println(rfid123);
  }
  
 //--------------------------------------------------------------- 
 //์ขŒ์„ ๋ฒˆํ˜ธ์™€ ์Œ์„ฑ ํŒŒ์ผ ๋งค์นญ(์ขŒ์„ ๋ฒˆํ˜ธ๊ฐ€ 1๋ฒˆ์ผ ๊ฒฝ์šฐ 1๋ฒˆ MP3ํŒŒ์ผ ์žฌ์ƒ)
  
  if ((rfid123 == "1") || (rfid123 == "2") || (rfid123 == "3"))
  {
     if (rfid123 == "1") {
         http.begin(avalue);
         Serial.println(avalue);
         voice.say(num1);
     }
     else if (rfid123 == "2") {
         http.begin(bvalue);
         Serial.println(bvalue);
         voice.say(num2);
     }
     else if (rfid123 == "3") {
         http.begin(cvalue);
         Serial.println(cvalue);
         voice.say(num3);
     }

  //-----------------------------------------------------
         
     httpCode = http.GET();
     
     if(httpCode > 0) 
     {
     
     if(httpCode == HTTP_CODE_OK) 
     {
      payload = http.getString();
      payload = payload.substring(0, 1);
      Serial.print("payload:");
      Serial.println(payload);
      
     if (payload == "0")
     {
      Serial.println("Seat");
      ledcWrite(vibChannel, 255);
      delay(1000);
      ledcWrite(vibChannel, 0);
     }
     else
     { 
      Serial.println("No seat");
     }
    } 
    
    else 
    {
      Serial.printf("[HTTP] GET… code: %d\n", httpCode);
    }
    
   }
 }

  http.end();
  delay(100);
}

 

๐Ÿ“Database: MySQL

https://m.blog.naver.com/jungha3071/222574019949

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ๋Š” MySQL์„ ์‚ฌ์šฉํ•˜์˜€๊ณ , ๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด4๋ฅผ ์„œ๋ฒ„๋กœ ๋‘์—ˆ๋‹ค. ์ˆœ์„œ๋Œ€๋กœ Apache, PHP, MySQL์„ ์„ค์น˜ํ•ด์ฃผ์—ˆ๊ณ , ์›น ์ƒ์—์„œ๋Š” phpmyadmin์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ด€๋ฆฌํ•ด์ฃผ์—ˆ๋‹ค.

DB๋Š” ์••๋ ฅ์„ผ์„œ์˜ ๊ฐ’์„ ๋ฐ›์•„์˜ค๊ณ  ์ด ๊ฐ’์„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ์ง„๋™๋ชจํ„ฐ์— ์ „๋‹ฌํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. ์ด ๋•Œ, ๊ฐ’์„ ๋ฐ›์•„์˜ฌ ๋•Œ์—๋Š” insert ํ˜•์‹์˜ php ํŒŒ์ผ์„, ๊ฐ’์„ ์ „์†กํ•  ๋•Œ๋Š” select ํ˜•์‹์˜ php ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์ฃผ์—ˆ๋‹ค. ์—ฐ๋™์„ ํ•  ๋•Œ์—๋Š” ์ด์— ํ•ด๋‹นํ•˜๋Š” url์„ ํ™œ์šฉํ•˜์˜€๊ณ , ๊ฐ’์„ ๊ฐ€์ ธ์˜ฌ ๋•Œ์—๋Š” ํ•ด๋‹น ์ขŒ์„์˜ ์ตœ์‹  ์ขŒ์„ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๋„๋ก ์„ค์ •ํ•˜์˜€๋‹ค. ํ•œ ์ขŒ์„๋‹น ํ•˜๋‚˜์˜ ํ…Œ์ด๋ธ”์„ ํ• ๋‹นํ•˜์˜€๊ณ , ๋นˆ์ž๋ฆฌ ์—ฌ๋ถ€๋Š” 0๊ณผ 1์˜ ์ฟผ๋ฆฌ ๊ฐ’์œผ๋กœ ํŒ๋‹จํ•˜์˜€๋‹ค. (๋นˆ์ž๋ฆฌ์ผ ๊ฒฝ์šฐ 0, ๊ทธ๋ ‡์ง€ ์•Š์„ ๊ฒฝ์šฐ 1) ์—…๋ฐ์ดํŠธ๋Š” 1์ดˆ์— 1๋ฒˆ์œผ๋กœ ์„ค์ •ํ•˜์˜€๋‹ค.

โœ”๏ธTable

 

โœ”๏ธinsert.php

<?php

   //GET ๋ฐฉ์‹์„ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ๊ฐ’ ๋ฐ›๊ธฐ
   $bus = $_GET["bus_value"];

   $servername = "127.0.0.1";
   $username = "team4";
   $password = "1234qwer";   
   $dbname = "esp32test";

 $conn = new mysqli($servername, $username, $password, $dbname);

   if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
   }

   //new๋ผ๋Š” ํ…Œ์ด๋ธ”์˜ ์ฟผ๋ฆฌ ๊ฐ’ ์ค‘ bus_value์— ์••๋ ฅ์„ผ์„œ๋กœ๋ถ€ํ„ฐ ๋ฐ›์•„์˜จ ๋ฐ์ดํ„ฐ ๊ฐ’ ๋„ฃ๊ธฐ
   $sql = "INSERT INTO new (bus_value) VALUES ($bus)";
    
   if ($conn->query($sql) === TRUE) {
      echo "New record created successfully";
 } else {
      echo "Error: " . $sql . " => " . $conn->error;
   }

   $conn->close();
   
?>

 

โœ”๏ธselect.php

<?php

   $conn = mysqli_connect("127.0.0.1", "team4", "1234qwer" , "esp32test");
   
   //new๋ผ๋Š” ํ…Œ์ด๋ธ”์˜ ์ฟผ๋ฆฌ ๊ฐ’์ธ ID, bus_value ์ค‘ ๋นˆ์ž๋ฆฌ ์—ฌ๋ถ€์˜ ์ •๋ณด๊ฐ€ ๋“ค์–ด์žˆ๋Š” bus_value์˜ ๊ฐ’๋งŒ ๋ฐ›๊ธฐ
   //ID(1์ดˆ ๊ฐ„๊ฒฉ์˜ ์‹œ๊ฐ„)์˜ ์ˆœ์„œ๋Œ€๋กœ ๊ฐ’ ๋ฐ›๊ธฐ
   $sql = "SELECT ID, bus_value FROM new ORDER BY ID DESC LIMIT 1“;
   $result = mysqli_query($conn, $sql);
   if (mysqli_num_rows($result) > 0) {
   while($row = mysqli_fetch_assoc($result)) {
   echo “๋ฒˆํ˜ธ: " . $row["ID"]. " ์ขŒ์„:" . $row["bus_value"]. "<br>";
   } 
   }
   else{
   echo "ํ…Œ์ด๋ธ”์— ๋ฐ์ดํ„ฐ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.";
   }
   mysqli_close($conn);
   
?>

 

๐Ÿ“์••๋ ฅ์„ผ์„œ ๋ถ€์ฐฉ ์˜์ž

โœ”๏ธ์œ„์น˜ ๋ฐ ๊ฐœ์ˆ˜ ์„ ์ •

โ†ณ ์˜์ž ๋์— ๊ฑธํ„ฐ์•‰๋Š” ์ž์„ธ์—์„œ๋Š” ์‹ ์ฒด์™€ ์„ผ์„œ๊ฐ€ ๋‹ฟ์ง€ ์•Š์•„ ๋นˆ์ขŒ์„์œผ๋กœ ํŒ๋‹จ

โ†ณ ๋ฐœ ๋ฐ›์นจ๋Œ€์— ๋ฐœ์„ ์˜ฌ๋ฆฐ ์ž์„ธ์—์„œ ํ—ˆ๋ฒ…์ง€๊ฐ€ ์˜์ž์— ๋‹ฟ์ง€ ์•Š์•„ ๋นˆ์ขŒ์„์œผ๋กœ ํŒ๋‹จ

โ†ณ ๋์— ๊ฑธํ„ฐ ์•‰๋Š” ์ž์„ธ์—์„œ ๋ฌด๊ฒŒ์ค‘์‹ฌ์ด ๋‘”๋ถ€์— ์ ๋ฆฐ๋‹ค๋Š” ์ ์„ ๊ณ ๋ คํ•ด ์••๋ ฅ ์„ผ์„œ 2๊ฐœ๋ฅผ ๋‘”๋ถ€ ์ชฝ์— ์ถ”๊ฐ€

 

โœ”๏ธํšŒ๋กœ ๊ตฌ์„ฑ

 

โœ”๏ธ์•„๋‘์ด๋…ธ ์ฝ”๋“œ

#include <Arduino.h>
#include <WiFi.h>              
#include <HTTPClient.h>        

//์••๋ ฅ์„ผ์„œ 5๊ฐœ
int pressSensor1 = A0;
int pressSensor2 = A3;
int pressSensor3 = A6;
int pressSensor4 = A7;
int pressSensor5 = A4;


const char WIFI_SSID [ ] = "";
const char WIFI_PASSWORD [ ] = "";

//insert.php๋ฅผ ํ†ตํ•ด ์••๋ ฅ์„ผ์„œ์˜ ๊ฐ’์„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ ์ „์†ก
String avalue  = "http://192.168.xx.xx/insert_data1.php?red=";
HTTPClient http;


void setup() {
  Serial.begin(9600);

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());
  
 
}

void loop() {

	//analogRead: ์••๋ ฅ์„ผ์„œ์˜ ์ €ํ•ญ๊ฐ’์„ 0~1023์˜ ๊ฐ’์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ถœ๋ ฅ
    int a = analogRead(pressSensor1);
    int b = analogRead(pressSensor2);
    int c = analogRead(pressSensor3);
    int d = analogRead(pressSensor4);
    int e = analogRead(pressSensor5);

    String dmlwk;
   
    //5๊ฐœ์˜ ์••๋ ฅ์„ผ์„œ ๊ฐ’์˜ ํ•ฉ์ด 0์ธ ๊ฒฝ์šฐ "๋นˆ์ž๋ฆฌ(0)"๋ฅผ ์ถœ๋ ฅ
    //0์ด ์•„๋‹Œ ๊ฒฝ์šฐ ๋น„์–ด์žˆ์ง€ ์•Š์€ ์ž๋ฆฌ(1)"๋ฅผ ์ถœ๋ ฅ
    //์ถœ๋ ฅ๋œ ๊ฐ’์„ ์ฟผ๋ฆฌ์— ๋„ฃ์–ด์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ ์ „์†ก
    if (a+b+c+d+e == 0)
    {
      dmlwk = "0";
    }
    

    else
    {
      dmlwk = "1";
    }
   
   
   
   http.begin(avalue+ dmlwk);
   int httpCode = http.GET();

   
   if(httpCode > 0) {
     
    if(httpCode == HTTP_CODE_OK) {
      String payload = http.getString();
      Serial.println(payload);
    } else {
      
      Serial.printf("[HTTP] GET... code: %d\n", httpCode);
    }
  } else {
    Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
  }

  http.end();
  delay(1000);
}

• ์„ผ์„œ ๊ฐ’์ด "0"์ธ ๊ฒฝ์šฐ "0"์˜ ๊ฐ’ ์ „์†ก → ์ถœ๋ ฅ๊ฐ’๋“ค์˜ "ํ•ฉ์ด 0์ด๋ฉด" ๋นˆ์ž๋ฆฌ

 ์„ผ์„œ ๊ฐ’์ด "0"์ด ์•„๋‹Œ ๊ฒฝ์šฐ "1"์˜ ๊ฐ’ ์ „์†ก → ์ถœ๋ ฅ๊ฐ’๋“ค์˜ "ํ•ฉ์ด 0์ด ์•„๋‹ˆ๋ฉด" ๋นˆ์ž๋ฆฌ ์•„๋‹˜

 

๐Ÿ“์–ดํ”Œ

์Œ์„ฑ์ง€์› ์„œ๋น„์Šค "์Šคํฌ๋ฆฐ๋ฆฌ๋”" ์ด์šฉ

: ์–ดํ”Œ์˜ ๊ฐ์ข… ๊ธ€์”จ, ํŒ์—…์ฐฝ ๋“ฑ์„ ์Œ์„ฑ์œผ๋กœ ์ฝ์–ด์ฃผ๊ณ , ์ง„๋™์„ ํ†ตํ•ด ๋ฒ„ํŠผ์„ ๊ตฌ๋ณ„ํ•˜์—ฌ ์‹œ๊ฐ์žฅ์• ์ธ์˜ ์–ดํ”Œ ์‚ฌ์šฉ์— ๋„์›€์„ ์ฃผ๋Š” ์—ญํ• 

 

โœ”๏ธ์‚ฌ์šฉ๋ฒ•

1. ์–ดํ”Œ ํ™”๋ฉด์„ ์ผœ๊ณ  ์•„๋ฌด ๊ณณ์ด๋‚˜ ํ„ฐ์น˜ํ•œ๋‹ค.

2. ’ํ™”๋ฉด์˜ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ํƒ‘์Šนํ•˜๋ ค๋Š” ๋ฒ„์Šค๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ ํ•˜์„ธ์š”’ ๋ผ๋Š” ์Œ์„ฑ์„ ๋“ฃ๊ณ  ๋‚œ ํ›„ํ™”๋ฉด์„ ํ„ฐ์น˜ํ•˜๊ณ  ๋ฒ„ ์Šค ๋ฒˆํ˜ธ๋ฅผ ๋งํ•œ๋‹ค

3. ํ•ด๋‹น ๋ฒ„์Šค์˜ ์ขŒ์„ ๋ฐฐ์น˜๋„์˜ ํ™”๋ฉด์„ ์†๊ฐ€๋ฝ์œผ๋กœ ์“ธ ์–ด๋‚ด๋ฆฌ๋ฉฐ ์ง„๋™๊ณผ ์Œ์„ฑ์•ˆ๋‚ด๋ฅผ ํ†ตํ•ด ๋ฐฐ์น˜๋„๋ฅผ ์ตํžŒ๋‹ค๋ฒ„์Šค ์˜์ž๊ทธ๋ฆผ์ด ํ„ฐ์น˜๋˜๋ฉด ‘A๋ฒˆ ์ขŒ์„’์ด๋ผ๋Š” ์ง„๋™๊ณผ ํ•จ ๊ป˜ ์Œ์„ฑ์•ˆ๋‚ด๊ฐ€ ๋‚˜์˜จ๋‹ค.

4. ํ™”๋ฉด ํ•˜๋‹จ์˜ ๋ฒ„ํŠผ์„ ํ„ฐ์น˜ํ•˜์—ฌ ๋น„์–ด ์žˆ๋Š” ์ขŒ์„ ์ •๋ณด ๋ฅผ ์•ˆ๋‚ด๋ฐ›๋Š”๋‹ค‘์ฒ˜์Œ์œผ๋กœ’ ๋ฒ„ํŠผ์„ ์ด์šฉํ•˜์—ฌ ๋ฒ„์Šค๋ฒˆํ˜ธ ์ž…๋ ฅ ํ™”๋ฉด์œผ๋กœ ๋Œ์•„๊ฐˆ ์ˆ˜ ์žˆ๋‹ค.

 

โœ”๏ธ๋ฒ„์Šค ์ขŒ์„ ๋ฐฐ์น˜๋„ ํ˜ธ์ถœ: ์Œ์„ฑ ์ธ์‹

ํƒ‘์Šนํ•˜๋ ค๊ณ  ํ•˜๋Š” ๋ฒ„์Šค ๋ฒˆํ˜ธ๋ฅผ ์Œ์„ฑ์œผ๋กœ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค. 

์ด๋Š” ์•ˆ๋“œ๋กœ์ด๋“œ ์ŠคํŠœ๋””์˜ค ๋‚ด์žฅ API์ธ ‘Google Speech to Text’๋ฅผ ํ†ตํ•ด ๊ตฌํ˜„๋˜์—ˆ๋‹ค.

private RecognitionListener listener = new RecognitionListener() {
	@Override
    public void onReadyForSpeech(Bundle params) {
    	Toast.makeText(getApplicationContext(), text: "์Œ์„ฑ์ธ์‹ ์‹œ์ž‘", Toast.LENGTH_SHORT).show();
    }
    
    @Override
    public void onBeginningOfSpeech() {
    	//๋งํ•˜๊ธฐ ์‹œ์ž‘ํ–ˆ์„ ๋•Œ ํ˜ธ์ถœ
    }
    
    @Override
    public void onRmsChanged(float rmsdB) {
    	//์ž…๋ ฅ๋ฐ›๋Š” ์†Œ๋ฆฌ์˜ ํฌ๊ธฐ๋ฅผ ์•Œ๋ ค์คŒ
    }
    
    @Override
    public void onBufferReceived(byte[] buffer) {
    	//๋ง์„ ์‹œ์ž‘ํ•˜๊ณ  ์ธ์‹์ด ๋œ ๋‹จ์–ด๋ฅผ buffer์— ๋‹ด์Œ
    }
    
    @Override
    public void onEndOfSpeech() {
    	//๋งํ•˜๊ธฐ๋ฅผ ์ค‘์ง€ํ•˜๋ฉด ํ˜ธ์ถœ
    }

 

โœ”๏ธ์ž”์—ฌ ์ขŒ์„ ์•ˆ๋‚ด: ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ˜ธ์ถœ

๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ํ•ด๋‹น ์ขŒ์„์˜ ์ตœ์‹  ์ขŒ์„ ์ •๋ณด๋งŒ์„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ๊ฐ€์ ธ์˜จ๋‹ค.

try {
	String _url3="http://192.168.xx.xx/select_data1.php?"
    URL url3=new URL(_url3);
    HttpURLConnection conn3=(HttpURLConnection) url3.openConnection();
    if (conn3 != null){
    	conn3.setConnectTimeout(10000);
        conn3.setRequestMethod("GET");
        conn3.setDoInput(true);
        conn3.setDoOutput(true);
        
        int resCode3=conn3.getResponseCode();
        if (resCode3 == HttpURLConnection.HTTP_OK) {
        	BufferedReader reader3 = new BufferedReader(new InputStreamReader (conn3.getInputStream()));
            String line3=null;
            while (true) {
            	line3=reader3.readLine();
                if (line3 == null)
                	break;
                if (line3.equals(number)) {
                	line3="์ฐฉ์„๊ฐ€๋Šฅ";
                    count3++;
                }
                else {
                	line3="์ฐฉ์„๋ถˆ๊ฐ€";
                }
                
                print(line3);
            }
            reader3.close();
        }
        conn3.disconnect();
    }

'๐Ÿ’ญ Project > ๐Ÿฆฏ Bus-Helper' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

01. ํ”„๋กœ์ ํŠธ ์†Œ๊ฐœ  (0) 2022.08.28

BELATED ARTICLES

more