411 lines
18 KiB
Typst
411 lines
18 KiB
Typst
#import "PageTemplate.typ": *
|
|
#import "@preview/fletcher:0.5.8" as fletcher: diagram, edge, node
|
|
#import fletcher.shapes: circle, diamond, pill
|
|
#show: chapter-page
|
|
#set heading(numbering: "บทที่ 1")
|
|
|
|
#heading([#linebreak()วิธีการดำเนินโครงงาน])
|
|
#set heading(numbering: "1.1")
|
|
|
|
#i ในการดำเนินการศึกษาครั้งนี้
|
|
คณะผู้จัดทำโครงงานได้ศึกษาข้อมูลเบื้องต้นในการสร้างเครื่องยืนยันตัวตนด้วย NFC
|
|
และได้ดำเนินการตามขั้นตอนนี้
|
|
|
|
+ วางแผนการดำเนินงาน
|
|
+ การออกแบบ
|
|
+ วัสดุอุปกรณ์
|
|
+ ขั้นตอนการประกอบ
|
|
+ การทดลอง
|
|
+ การวิเคราะห์ข้อมูล
|
|
|
|
== วางแผนการดำเนินงาน
|
|
|
|
#show table.cell.where(y: 1): strong
|
|
#set par(leading: 0.5em)
|
|
|
|
#let arrow = [
|
|
#place(
|
|
left + horizon,
|
|
text(weight: "bold", size: 14pt)[#sym.arrow.l],
|
|
dx: -5pt,
|
|
dy: -0.7pt,
|
|
)
|
|
#place(
|
|
horizon,
|
|
line(length: 100%, stroke: (thickness: 1pt)),
|
|
dx: 0pt,
|
|
dy: 0pt,
|
|
)
|
|
#place(
|
|
right + horizon,
|
|
text(weight: "bold", size: 14pt)[#sym.arrow.r],
|
|
dx: 5pt,
|
|
dy: -0.7pt,
|
|
)
|
|
]
|
|
|
|
=== แผนขั้นตอนและวิธีการดำเนินงาน
|
|
|
|
#table(
|
|
columns: 12,
|
|
align: (
|
|
left + horizon,
|
|
center,
|
|
center,
|
|
center,
|
|
center,
|
|
center,
|
|
center,
|
|
center,
|
|
center,
|
|
center,
|
|
center,
|
|
center,
|
|
),
|
|
table.header(
|
|
table.cell(
|
|
[ขั้นตอนการ\ ดำเนินการ],
|
|
rowspan: 2,
|
|
),
|
|
table.cell(
|
|
[พ.ศ.2568],
|
|
colspan: 3,
|
|
),
|
|
table.cell(
|
|
[พ.ศ.2569],
|
|
colspan: 8,
|
|
),
|
|
[ต.ค.],
|
|
[พ.ย.],
|
|
[ธ.ค.],
|
|
[ม.ค.],
|
|
[ก.พ.],
|
|
[มี.ค],
|
|
[เม.ย],
|
|
[พ.ค.],
|
|
[มิ.ย.],
|
|
[ก.ค.],
|
|
[ส.ค.],
|
|
),
|
|
[ศึกษาค้นคว้าข้อมูล],
|
|
table.cell(arrow, colspan: 3),
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[เสนอหัวข้อ], arrow, [], [], [], [], [], [], [], [], [], [],
|
|
[เสนอครั้งที่ 1], [], arrow, [], [], [], [], [], [], [], [], [],
|
|
[ออกแบบและสร้าง], [], table.cell(arrow, colspan: 5), [], [], [], [], [],
|
|
[จัดซื้ออุปกรณ์ทดลอง],
|
|
[],
|
|
table.cell(arrow, colspan: 3),
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[ทดลองการทำงาน], [], [], table.cell(arrow, colspan: 4), [], [], [], [], [],
|
|
[ปรับปรุงแก้ไข], [], [], [], [], table.cell(arrow, colspan: 5), [], [],
|
|
[เสนอครั้งที่ 2], [], [], [], arrow, [], [], [], [], [], [], [],
|
|
[จัดทำรูปเล่ม], table.cell(arrow, colspan: 11),
|
|
[นำเสนอโครงงาน], [], [], [], [], [], [], [], [], [], [], [],
|
|
)
|
|
|
|
=== ผังการดำเนินงาน
|
|
|
|
#diagram(
|
|
node-stroke: 1pt,
|
|
spacing: 2em,
|
|
node((0, 0), [เริ่มต้น], shape: pill),
|
|
edge("-|>"),
|
|
node((0, 1), shape: circle, radius: 1em),
|
|
edge("-|>"),
|
|
node((0, 2), [ศึกษาข้อมูลและทฤษฏีที่เกี่ยวข้อง], width: 2.5in),
|
|
edge("-|>"),
|
|
node((0, 3), [ออกแบบและวางแผนการดําเนินงาน], width: 2.5in),
|
|
edge("-|>"),
|
|
node((0, 4), [เครื่องยืนยันตัวตนด้วย NFC], width: 2.5in),
|
|
edge("-|>"),
|
|
node((0, 5), [ทดสอบประสิทธิภาพ], shape: diamond),
|
|
edge("r,u,u,u,u,l", "-|>", [ไม่ผ่าน]),
|
|
edge("-|>", [ผ่าน]),
|
|
node((0, 6), [จัดทำเอกสาร], width: 2.5in),
|
|
edge("-|>"),
|
|
node((0, 7), [นำเสนอ], width: 2.5in),
|
|
edge("-|>"),
|
|
node((0, 8), [สิ้นสุด], shape: pill),
|
|
)
|
|
|
|
#pagebreak()
|
|
|
|
=== ผังการทำงาน
|
|
|
|
#diagram(
|
|
node-stroke: 1pt,
|
|
spacing: 2em,
|
|
node([เริ่มต้น], shape: pill),
|
|
edge("-|>"),
|
|
node((1, 0), [ตั้งค่า LittleFS]),
|
|
edge("-|>"),
|
|
|
|
node((1, 2), [มี Wi-Fi บันทึก\ ไว้อยู่หรือไม่], shape: diamond),
|
|
edge("l", "-|>", [ไม่มี]),
|
|
edge((1, 2), (1, 3), "-|>", [มี]),
|
|
|
|
node((0, 2), [รอรับรายละเอียดเครือข่าย\ (ESP-Touch)]),
|
|
edge("d,r", "-|>"),
|
|
node((1, 3), [เชื่อมต่อเครือข่าย]),
|
|
edge("-|>"),
|
|
|
|
node((0, 4), [มีอุปกรณ์ควบคุม\ หลักแล้วหรือไม่], shape: diamond),
|
|
edge("-|>", [ไม่มี]),
|
|
edge("d", "-|>", [มี]),
|
|
|
|
node((1, 4), [สร้างโทเค็นสำหรับการยืนยัน\ อุปกรณ์ควบคุมหลัก]),
|
|
edge("-|>"),
|
|
|
|
node((1, 5), [รออุปกรณ์ควบคุมหลัก\ แตะเซนเซอร์ NFC]),
|
|
edge("-|>"),
|
|
|
|
node((0, 5), [ตั้งค่าเซิร์ฟเวอร์ HTTPS]),
|
|
edge("-|>"),
|
|
|
|
node((0, 6), shape: circle, radius: 1em),
|
|
edge("-|>"),
|
|
|
|
node((0, 7), [มีการแตะเซนเซอร์\ NFC ขาเข้าหรือไม่], shape: diamond),
|
|
edge("-|>", [ไม่มี]),
|
|
|
|
node((0, 9), [มีคนผ่านเซนเซอร์ PIR\ โดยไม่ได้รับอนุญาตหรือไม่], shape: diamond),
|
|
edge((0, 9), (0, 10), [ไม่มี]),
|
|
edge((0, 7), (1, 6), "-|>", [มี]),
|
|
|
|
node((1, 6), [อยู่ในโหมดลงทะเบียน\ หรือไม่], shape: diamond),
|
|
edge("-|>", [ใช่]),
|
|
edge((1, 6), (2, 7), [ไม่]),
|
|
|
|
node((1, 7), [นำ ID อุปกรณ์เข้า\ สู่รายการทะเบียน]),
|
|
edge((1, 7), (0.6, 7), (0, 9), "-|>"),
|
|
|
|
node((2, 7), [ID ของอุปกรณ์อยู่\ ในทะเบียนหรือไม่], shape: diamond),
|
|
edge("-|>", [อยู่]),
|
|
edge((2, 7), (1, 8), "-|>", [ไม่อยู่], label-sep: -5pt),
|
|
|
|
node((2, 8), [ส่งเสียงคอนเฟิร์ม]),
|
|
edge((2, 8), (2, 8.5), (0.4, 8.5), (0, 9), "-|>"),
|
|
|
|
node((1, 8), [ส่งเสียงแสดงความผิดพลาด]),
|
|
edge((1, 8), (0.5, 8), (0, 9), "-|>"),
|
|
|
|
node((1, 9), [แจ้งเตือนทางเสียง\ และแอพลิเคชัน]),
|
|
edge((1, 9), (0, 10), "-|>"),
|
|
edge((0, 10), (1, 10), "-|>", [มี]),
|
|
|
|
node((0, 10), [มีคำขอ HTTPS\ ใหม่หรือไม่], shape: diamond),
|
|
edge((0, 10), (-2, 10), "-|>", [ไม่มี], label-pos: 10%),
|
|
edge((0, 9), (1, 9), "-|>", [มี], label-anchor: "center", label-sep: -8pt),
|
|
|
|
node((1, 10), [ประมวลผลคำขอ HTTPS]),
|
|
edge((1, 10), (1, 11), (-2, 11), (-2, 10), "-|>"),
|
|
|
|
node((-2, 10), shape: circle, radius: 1em),
|
|
edge((-2, 10), (-2, 6), (0, 6), "-|>"),
|
|
)
|
|
|
|
#pagebreak()
|
|
#set par(leading: 1em)
|
|
|
|
== การออกแบบ
|
|
|
|
== วัสดุอุปกรณ์
|
|
|
|
+ บอร์ด ESP32 (NodeMCU)
|
|
+ กล่องพลาสติก
|
|
+ Buzzer
|
|
+ เซนเซอร์ PIR
|
|
+ เซนเซอร์ NFC 2 ชิ้น
|
|
|
|
== ขั้นตอนการประกอบ
|
|
|
|
=== การติดตั้งอุปกรณ์
|
|
|
|
=== การเขียนเฟิร์มแวร์
|
|
|
|
โครงงานนี้ใช้ซอฟต์แวร์ PlatformIO ในการสร้างและจัดการโปรเจกต์เฟิร์มแวร์
|
|
โดยหากต้องการเพียงแค่เขียนเฟิร์มแวร์ลงไปยังบอร์ด ESP32 คุณจำเป็นต้องใช้ซอฟต์แวร์หลัก ๆ คือ
|
|
PlatformIO Core และ Git (ไม่จำเป็น แต่เพื่อความสะดวกสบาย)
|
|
|
|
อย่างไรก็ตาม PlatformIO จำเป็นต้องใช้ Python เวอร์ชัน 3.6 ขึ้นไปด้วยเช่นกัน
|
|
ดังนั้นคุณจำเป็นต้องติดตั้ง Python ด้วยหากคุณยังไม่มี
|
|
|
|
ในขั้นตอนแรก โปรดเปิดเทอร์มินัลของคุณ ซึ่งโดยทั่วไปแล้วคุณสามารถค้นหาแอพลิเคชัน "Terminal" ได้เลย
|
|
โดยบน Windows 10 เวอร์ชั่นใหม่ ๆ และ Windows 11 จะมาพร้อมกับแอพลิเคชัน Windows Terminal
|
|
อย่างไรก็ตาม เมื่อเปิดแล้ว โปรดตรวจสอบให้แน่ใจว่าคุณกำลังใช้ PowerShell และไม่ใช่ Command
|
|
Prompt
|
|
|
|
โดยในปัจจุบัน Python เวอร์ชันล่าสุดคือ Python 3.14.2 โดยคุณสามารถติดตั้ง Python และ Git บน
|
|
Windows ได้ด้วยการใช้คำสั่งต่อไปนี้
|
|
|
|
```sh
|
|
winget install Python.Python.3.14 Git.Git -e -s winget
|
|
```
|
|
|
|
สำหรับระบบปฏิบัติการอื่นนั้น โดยปกติแล้วจะไม่ต้องติดตั้ง Python
|
|
เพิ่มเนื่องจากมีติดมากับระบบปฏิบัติการอยู่แล้ว อย่างไรก็ตาม บน Linux อาจต้องมีการติดตั้งการรองรับ
|
|
Virtual Environment แยก โดยแต่ละระบบจะมีชื่อแพคเกจไม่เหมือนกัน โดยบน Debian, Fedora,
|
|
และ Arch สามารถใช้คำสั่งต่อไปนี้ในการติดตั้งทั้ง Python Virtual Environment และ Git
|
|
พร้อมกันได้
|
|
|
|
```sh
|
|
# Debian
|
|
sudo apt install python3-venv git
|
|
# Fedora
|
|
sudo dnf install python3-virtualenv git
|
|
# Arch
|
|
sudo pacman -S python-virtualenv git
|
|
```
|
|
|
|
#pagebreak()
|
|
|
|
#show raw.where(block: true): set block(below: 2em)
|
|
|
|
==== การติดตั้ง PlatformIO Core ผ่านแพคเกจ
|
|
|
|
หากคุณใช้ Fedora Linux หรือ Arch Linux (หรือลูก ๆ ของมัน) คุณสามารถติดตั้งแพคเกจ
|
|
PlatformIO ได้โดยตรง โดยมีคำสั่งดังนี้:
|
|
|
|
```sh
|
|
# Fedora Linux
|
|
sudo dnf install platformio
|
|
# Arch Linux
|
|
sudo pacman -S platformio-core
|
|
```
|
|
|
|
หากคุณติดตั้งแพคเกจ Fedora นั้นแล้ว คุณไม่จำเป็นที่จะต้องติดตั้งกฎ udev ด้วยตนเอง
|
|
(ที่จะถูกกล่าวถึงใน@pioudev)
|
|
|
|
หากคุณใช้ Arch คุณสามารถติดตั้งแพคเกจกฎ udev ได้โดยตรงโดยไม่ต้องดาวน์โหลดเอง
|
|
|
|
```sh
|
|
sudo pacman -S --asdeps platformio-core-udev
|
|
```
|
|
|
|
==== การติดตั้ง PlatformIO Core ผ่านสคริปต์
|
|
|
|
ถัดไป ในการติดตั้ง PlatformIO Core สามารถทำได้โดยการใช้สคริปต์ติดตั้ง โดยสำหรับ `curl`
|
|
สามารถใช้คำสั่งนี้ได้:
|
|
|
|
```sh
|
|
curl -fsSL -o get-platformio.py https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py
|
|
```
|
|
|
|
หรือหากต้องการใช้ `wget`:
|
|
|
|
```sh
|
|
wget -O get-platformio.py https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py
|
|
```
|
|
|
|
หรือสำหรับ PowerShell, สามารถใช้ `iwr` (หรือชื่อเต็มคือ `Invoke-WebRequest`) ได้:
|
|
|
|
```sh
|
|
iwr -OutFile get-platformio.py -Uri https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py
|
|
```
|
|
|
|
(มีการเว้นบรรทัดใหม่เนื่องจากพื้นที่ไม่เพียงพอ โปรดอย่าเว้นบรรทัดเมื่อพิมพ์คำสั่งจริง)
|
|
|
|
แล้วดังนั้นจึงใช้คำสั่ง `python3 get-platformio.py` ในการรันสคริปต์ติดตั้งที่ได้ทำการดาวน์โหลดมา
|
|
|
|
โดยค่าเริ่มต้นแล้ว PlatformIO จะไม่เพิ่มตนเองเข้าไปยังตัวแปรสิ่งแวดล้อม PATH
|
|
ซึ่งจำเป็นในการใช้คำสั่งจากที่ใหนก็ได้โดยไม่ต้องกล่าวถึงไฟล์พาธ
|
|
|
|
โดยสำหรับ Linux แล้วนั้น คุณต้องเพิ่ม `$HOME/.local/bin/` เข้าไปยัง PATH ของคุณ โดยหากคุณใช้
|
|
Bash คุณสามารถแก้ไข `~/.bash_profile` และเพิ่มบรรทัดนี้เข้าไปได้:
|
|
|
|
```sh
|
|
export PATH=$PATH:$HOME/.local/bin
|
|
```
|
|
|
|
หากคุณใช้ Zsh สามารถใช้โคดเดียวกันได้ เพียงแต่คุณต้องแก้ไขไฟล์ `~/.zprofile` หรือ `~/.zshrc`
|
|
แทน
|
|
|
|
โดยบน Windows มีขั้นตอนดังนี้:
|
|
|
|
+ กด Windows + R
|
|
+ พิมพ์ `sysdm.cpl` และกด Enter
|
|
+ ในหน้าต่าง *System Properties* คลิกไปยังแท็บ *Advanced*
|
|
+ คลิกปุ่ม *Environment Variables*
|
|
|
|
หลังจากนั้น เลือกตัวแปร *Path* ในส่วน *User variables* แล้วจึงกด *Edit* แล้วเพิ่ม
|
|
`%USERPROFILE%\.platformio\penv\Scripts\` เข้าไปในรายการ
|
|
|
|
==== 99-platformio-udev.rules <pioudev>
|
|
|
|
ผู้ใช้ Linux จำเป็นที่จะต้องติดตั้งกฎ udev โดยสามารถดูไฟล์กฎ udev เวอร์ชันล่าสุดได้ที่\
|
|
https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/system/99-platformio-udev.rules
|
|
|
|
*หมายเหตุ:* โปรดตรวจสอบว่า PID และ VID ของบอร์ดคุณอยู่ในไฟล์กฎนั้น โดยคุณสามารถดู PID/VID
|
|
ของบอร์ดคุณได้ผ่านคำสั่ง `pio device list`
|
|
|
|
โดยไฟล์นั้นต้องถูกวางอยู่ที่ `/etc/udev/rules.d/99-platformio-udev.rules` (ตำแหน่งที่ดีที่สุด)
|
|
หรือ `/lib/udev/rules.d/99-platformio-udev.rules` (อาจจำเป็นสำหรับบางระบบที่พัง)
|
|
|
|
โปรดใช้คำสั่งต่อไปนี้ในการดาวน์โหลดและวางไฟล์นั้นไว้ในสถานที่ที่ถูกต้อง:
|
|
|
|
```sh
|
|
curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/system/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules
|
|
```
|
|
|
|
หรือคุณก็สามารถดาวน์โหลดไฟล์นั้นด้วยตัวเองและคัดลอกมันไปในโฟลเดอร์ที่หมายได้เช่นกัน
|
|
|
|
```sh
|
|
sudo cp 99-platformio-udev.rules /etc/udev/rules.d/99-platformio-udev.rules
|
|
```
|
|
|
|
หลังจากนั้น รีสตาร์ทบริการ udev:
|
|
|
|
```sh
|
|
sudo service udev restart
|
|
```
|
|
หรือ:
|
|
```sh
|
|
sudo udevadm control --reload-rules
|
|
sudo udevadm trigger
|
|
```
|
|
|
|
หลังจากติดตั้งไฟล์นี้แล้ว ถอดสายที่เชื่อมต่อระหว่างบอร์ดและคอมพิวเตอร์ของคุณแล้วเสียบมันใหม่
|
|
|
|
==== การดาวน์โหลดโปรเจกต์
|
|
|
|
สามารถใช้ Git ในการ clone โปรเจกต์ได้ด้วยคำสั่งต่อไปนี้:
|
|
|
|
```sh
|
|
git clone https://gitskette.dailitation.xyz/linesofcodes/liteauth-firmware32.git
|
|
```
|
|
|
|
โดย Git นั้นจะทำการโคลนโปรเจกต์ไปที่โฟลเดอร์ `liteauth-firmware32` เนื่องจากเป็นชื่อของ Git
|
|
repository
|
|
|
|
หรือไปที่ https://gitskette.dailitation.xyz/linesofcodes/liteauth-firmware32
|
|
และทำการคลิกปุ่ม *Code* แล้วกด *Download ZIP* หรือ *Download TAR.GZ*
|
|
แล้วทำการแตกไฟล์ได้ตามปกติ
|
|
|
|
หลังจากนั้น ไปที่โฟลเดอร์ของคุณในเทอร์มินัลโดยใช้คำสั่ง `cd`
|
|
|
|
==== คำสั่ง PlatformIO เบื้องต้น
|
|
|
|
- `pio run --list-targets`: ดูรายการเป้าหมายคำสั่งรัน
|
|
- `pio run upload`: รันเป้าหมายอัพโหลด ซึ่งนี่คือคำสั่งที่คุณควรจะใช้ในการเขียนเฟิร์มแวร์ลงบนบอร์ด
|
|
- `pio device monitor`: เปิด Serial Monitor
|
|
|
|
*หมายเหตุ:* โปรดใช้คำสั่งประเภท `pio run` ในโฟลเดอร์ของโปรเจกต์
|
|
|
|
== การทดสอบ
|
|
|
|
== การวิเคราะห์ข้อมูล
|