Cov txheej txheem:

Keysorter: 6 Cov kauj ruam
Keysorter: 6 Cov kauj ruam

Video: Keysorter: 6 Cov kauj ruam

Video: Keysorter: 6 Cov kauj ruam
Video: Lil Nas X, Jack Harlow - INDUSTRY BABY (Official Video) 2024, Hlis ntuj nqeg
Anonim
Keysorter
Keysorter
Keysorter
Keysorter

Kuv tab tom kawm NMCT ntawm Howest. Rau peb lub semester kawg peb yuav tsum ua qhov project. Yog li kuv tau ua Keysorter.

Nws ua dab tsi?

Peb muaj ntau lub tsheb yuam sij hauv tsev thiab lawv txhua tus zoo ib yam. Yog li kuv tau ua Keysorter los daws qhov teeb meem no.

Nws yuav tsum luam theej tawm tus yuam sij ntawm RFID thiab muab nws tso rau hauv lub npov. Yog tias kuv luam theej tawm qhov tseem ceeb dua nws yuav qhia nws qhov chaw tau muab yav tas los. Kuj tseem muaj khawm los qhia lub tsheb ntxuav zaum kawg.

Qhov no yuav ua haujlwm ntawm Raspberry Pi uas tseem muaj qhov kev xaiv ntxiv lub vev xaib ntawm Flask.

Ntawm nplooj ntawv kuv yuav tsum tuaj yeem saib txhua tus yuam sij, ntxiv lub npe rau tus yuam sij thiab tshem tus yuam sij.

Kauj Ruam 1: Kauj Ruam 1: Kuv Yuav Xav Li Cas?

Kauj Ruam 1: Kuv Yuav Tau Dab Tsi?
Kauj Ruam 1: Kuv Yuav Tau Dab Tsi?
Kauj Ruam 1: Kuv Yuav Tau Dab Tsi?
Kauj Ruam 1: Kuv Yuav Tau Dab Tsi?

Kuv pib los ntawm kev sau cov npe ntawm cov khoom uas kuv yuav xav ua kom qhov no ua haujlwm.

Cheebtsam:

  • Raspberry pib
  • 2 x Hloov npe (74hc595)
  • 3 x nub
  • 9x coj led
  • RFID scanner (MFRC522)
  • 12 x resistor 220 ohm

Tom qab ntawd kuv muab tag nrho cov no tso rau hauv kuv qhov kev xav tsis zoo.

Thaum kuv ua tiav qhov no kuv tau ua hauv lub neej tiag tiag.

Kauj Ruam 2: Kauj Ruam 2: Ua Database Schematic

Kauj ruam 2: Ua Database Schematic
Kauj ruam 2: Ua Database Schematic

Txhawm rau txuag kuv cov ntaub ntawv Kuv yuav tsum tsim cov ntaub ntawv khaws cia uas tuaj yeem ua haujlwm ntawm kuv Pi.

Kuv ua nws hauv Mysql.

Tsheb rooj:

  • Tsheb ID
  • Tus neeg siv ID
  • Hom (tsheb hom)
  • Hom
  • Xeem ntxuav
  • Ntsiab
  • RFID_ID

Kauj Ruam 3: Kauj Ruam 3: Coding

Kauj ruam 3: Coding
Kauj ruam 3: Coding

Thaum txhua yam no tau npaj txhij kuv tuaj yeem pib coding.

Kuv pib los ntawm kev ua tus lej rau kuv lub ntsuas pa hauv Python 3.5.

Txhawm rau rub cov cai nyem ntawm no.

Siv qhov txuas los clone qhov project.

Kauj Ruam 4: Kauj Ruam 4: Muab Al Code rau Kuv Raspberry Pi

Txhim kho pob khoom

Ua ntej kuv teeb tsa pob uas kuv xav tau los ua txoj haujlwm no.

kuv@kuv-rpi: ~ $ sudo apt hloov tshiab

kuv@kuv-rpi: ~ $ sudo apt install -y python3-venv python3-pip python3-mysqldb mysql-server uwsgi nginx uwsgi-plugin-python3

Ib puag ncig virtual

me@my-rpi: ~ $ python3 -m pip install-upgrade pip setuptools log virtualenvme@my-rpi: ~ $ mkdir project1 && cd project1 me@my-rpi: ~/project1 $ python3 -m venv --system- site-packages env me@my-rpi: ~/project1 $ source env/bin/activate (env) me@my-rpi: ~/project1 $ python -m pip install mysql-connector-python argon2-cffi Flask Flask-HTTPAuth Flask-MySQL mysql-connector-python passlib

Tshaj tawm txoj haujlwm mus rau koj Pi siv pycharm

Qhib Pycharm thiab mus rau VCS> Ntshuam los ntawm Version Control> Github thiab clone kuv cov ntaub ntawv github.

Muab kev teeb tsa xa mus rau cov npe uas koj nyuam qhuav ua. (/tsev/kuv/project1). Nias thov!

Mus rau tus kws txhais lus teeb tsa thiab xaiv ib puag ncig virtual uas koj nyuam qhuav ua. (/tsev/kuv/project1/env/bin/pyhon)

Txheeb xyuas yog tias daim phiaj qhia kev raug.

Tam sim no koj tuaj yeem xa cov cai rau koj phau ntawv teev npe siv Pycharm.

Database

Txheeb xyuas yog tias lub chaw khaws ntaub ntawv khiav haujlwm. Koj yuav tsum tau txais qee yam zoo li no:

kuv@kuv -rpi: ~ $ sudo systemctl xwm txheej mysql ● mariadb.service - MariaDB database server Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled) Active: nquag (khiav) txij hnub 2018-06-03 09:41:18 CEST; 1 hnub 4 teev dhau los Lub ntsiab PID: 781 (mysqld) xwm txheej: "Siv koj li SQL thov tam sim no …" Cov Haujlwm: 28 (txwv: 4915) CGroup: /system.slice/mariadb.service └─781/usr/sbin/mysqld

Jun 03 09:41:13 my-rpi systemd [1]: Pib MariaDB database server… Jun 03 09:41:15 my-rpi mysqld [781]: 2018-06-03 9:41:15 4144859136 [Nco ntsoov] / usr/sbin/mysqld (mysqld 10.1.26-MariaDB-0+deb9u1) Jun 03 09:41:18 my-rpi systemd [1]: Pib MariaDB database server.

kuv@kuv -rpi: ~ $ ss -lt | grep mysql LISTEN 0 80 127.0.0.1:mysql *: *

Tsim cov neeg siv thiab ntxiv cov database

kuv@kuv-rpi: ~ $ sudo mariadb

ib zaug koj nyob hauv cov database ua qhov no.

Tsim tus neeg siv 'project1-admin'@'localhost' IDENTIFIED BY 'adminpassword'; Tsim tus neeg siv 'project1-web'@'localhost' IDENTIFIED BY 'webpassword'; Tsim tus neeg siv 'project1-sensor'@'localhost' IDENTIFIED BY 'sensorpassword';

CREATE DATABASE project1;

ZOO TSHAJ PLAWS YOOJ YIM RAU project1.* Rau 'project1-admin'@'localhost' NROG QHOV ZOO TSHAJ PLAWS; GRANT SELECT, INSERT, Hloov tshiab, Rho tawm ntawm qhov project1.* TO 'project1-web'@'localhost'; GRANT SELECT, INSERT, Hloov tshiab, Rho tawm ntawm qhov project1.* TO 'project1-sensor'@'localhost'; NTSEEG NTAWV QHOV TSEEB;

TABLETABLE `user` (` idUser` int (11) NOT NULL, `Password` varchar (45) DEFAULT NULL, PRIMARY KEY (` idUser`)) ENGINE = InnoDB DEFAULT CHARSET = utf8

CREATE TABLE `tsheb` (`idCar` int (11) NOT NULL AUTO_INCREMENT,` idUser` int (11) TSIS NULL, `Brand` varchar (45) DEFAULT NULL, `Type` varchar (45) DEFAULT NULL, `LastWashed ' datetime DEFAULT NULL, `RFID_Number` varchar (15) DEFAULT NULL,` Key `varchar (5) DEFAULT NULL, PRIMARY KEY (` idCar`, `idUser`), KEY` fk_Car_User1_idx` (`idUser`) KEYEEM KEY (`idUser`) REFERENCES` user` (`idUser`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB AUTO_INCREMENT = 4 DEFAULT CHARSET = utf8

Txuas koj lub database rau Pycharm

Nyem rau ntawm lub database database ntawm sab xis. Yog tias koj tsis muaj lub tab qhib ua qhov no: Saib> Tool Windows> Database.

Nyem ntxiv kev txuas. Xaiv Cov Ntaub Ntawv Qhov Chaw> MySQL (Yog tias muaj lub khawm rub tus tsav tsheb nias nws.)

Mus rau SSH/SSL thiab txheeb xyuas SSH. Sau koj li Raspberry pi cov ntaub ntawv pov thawj (tus tswv/tus siv/tus password). Chaw nres nkoj yuav tsum yog 22 thiab tsis txhob hnov qab txheeb xyuas tus lej cim.

Rov qab mus rau General. Tus tswv yuav tsum yog localhost thiab database yuav tsum yog qhov project1. Ua kom tiav daim ntawv pov thawj los ntawm qhov project1-admin en kuaj qhov txuas.

Yog tias qhov txuas tau zoo ces mus rau ntawm Schemas tab thiab paub tseeb tias qhov project1 raug tshuaj xyuas.

Xyuas seb lub database puas raug

kuv@kuv-rpi: ~ $ echo 'qhia ntxhuav;' | mysql project1 -t -u project1-admin -pEnter password: + --------------------------- + | Tables_in_project1 | + ---------------------------+ | sensor | Cov | cov neeg siv | +------------------------------+

Kho Cov Ntaub Ntawv

Hauv phau ntawv teev npe conf koj yuav pom 4 cov ntaub ntawv. Koj yuav tsum hloov cov npe siv rau koj lub npe siv.

Systemd

Txhawm rau pib txhua yam koj yuav tsum ua cov lus txib no.

kuv@kuv-rpi: ~/project1 $ sudo cp conf/project1-*. service/etc/systemd/system/

kuv@kuv-rpi: ~/project1 $ sudo systemctl daemon-reload kuv@my-rpi: ~/project1 $ sudo systemctl pib project1-* kuv@my-rpi: ~/project1 $ sudo systemctl xwm txheej project1-* ● project1- flask.service-uWSGI piv txwv los ua haujlwm project1 web interface Loaded: loaded (/etc/systemd/system/project1-flask.service; xiam oob qhab; tus muag khoom preset: enabled) Active: nquag (khiav) txij li hnub Monday 2018-06-04 13: 14:56 CEST; 1s dhau los PID tseem ceeb: 6618 (uwsgi) Cov Haujlwm: 6 (txwv: 4915) CGroup: /system.slice/project1-flask.service ├─6618/usr/bin/uwsgi --ini/home/me/project1/conf/ uwsgi-flask.ini ├─6620/usr/bin/uwsgi --ini /home/me/project1/conf/uwsgi-flask.ini ├─6621/usr/bin/uwsgi --ini/tsev/kuv/project1/ conf/uwsgi-flask.ini ├─6622/usr/bin/uwsgi --ini /home/me/project1/conf/uwsgi-flask.ini ├─6623/usr/bin/uwsgi --ini/tsev/kuv/ project1/conf/uwsgi-flask.ini └─6624/usr/bin/uwsgi --ini /home/me/project1/conf/uwsgi-flask.ini

Jun 04 13:14:56 my-rpi uwsgi [6618]: khij 383928 bytes (374 KB) rau 5 cores Jun 04 13:14:56 my-rpi uwsgi [6618]: *** Hom kev ua haujlwm: ua ntej ***

● project1-sensor.service-Project 1 sensor service Loaded: loaded (/etc/systemd/system/project1-sensor.service; neeg xiam oob khab; tus muag khoom preset: qhib) Active: nquag (khiav) txij hnub Monday 2018-06-04 13: 16:49 CEST; 5s dhau los Lub ntsiab PID: 6826 (nab nab) Cov Haujlwm: 1 (txwv: 4915) CGroup: /system.slice/project1-sensor.service └─6826/home/me/project1/env/bin/python/home/me/project1 /sensor/sensor.py

Jun 04 13:16:49 my-rpi systemd [1]: Pib Project 1 sensor pabcuam. Lub Rau Hli 04 13:16:49 kuv-rpi nab hab sej [6826]: DEBUG: _ lub ntsiab _: Txuag sensor txheej txheem_count = b'217 / n 'rau database Jun 04 13:16:55 my-rpi nab hab sej [6826]: DEBUG: _ main_: Txuag sensor process_count = b'218 / n 'rau database

nginx

kuv@kuv-rpi: ~/project1 $ ls -l/etc/nginx/sites-*

/etc/nginx/sites-available: tag nrho 4 -rw-r-r-- 1 lub hauv paus cag 2416 Lub Xya hli ntuj 12 2017 default

/etc/nginx/sites-enabled: total 0 lrwxrwxrwx 1 root root 34 Jan 18 13:25 default->/etc/nginx/sites-available/default

Txhawm rau ua txhua yam ua tiav ua cov lus txib no.

kuv@kuv-rpi: ~/project1 $ sudo cp conf/nginx/etc/nginx/sites-available/project1me@my-rpi: ~/project1 $ sudo rm/etc/nginx/sites-enabled/default me@my- rpi: ~/project1 $ sudo ln -s/etc/nginx/sites-available/project1/etc/nginx/sites-enabled/project1 me@my-rpi: ~/project1 $ sudo systemctl restart nginx.service

Pib dua

Cia peb paub tseeb tias txhua yam pib tau txais.

Mus rau kab ntawv conf thiab ua cov lus txib kawg no thiab koj ua tiav!

kuv@kuv-rpi: ~/project1 $ sudo systemctl pab kom project1-*

Yog tias koj rov pib dua koj Pi nws yuav tsum pib txiav.

Kauj Ruam 5: Kauj Ruam 5: Ua Vaj Tsev

Kauj Ruam 5: Ua Vaj Tsev
Kauj Ruam 5: Ua Vaj Tsev
Kauj Ruam 5: Ua Vaj Tsev
Kauj Ruam 5: Ua Vaj Tsev
Kauj Ruam 5: Ua Vaj Tsev
Kauj Ruam 5: Ua Vaj Tsev
Kauj Ruam 5: Ua Vaj Tsev
Kauj Ruam 5: Ua Vaj Tsev

Rov ua dua tshiab

Txhawm rau ua kuv lub tsev kuv siv lub txee qub uas kuv niam yuav rub tawm.

puag

Kuv pom 4 daim phiaj (34 cm x 26 cm). (yog li nws yog lub voos xwmfab ntawm 34 x 34 x 26).

Hauv qab kuv tau ntxiv ib daim ntoo ntoo ua hauv qab.

Board nrog coj

Hauv nruab nrab kuv tau muab 2 daim ntoo me me ntawm txhua sab ob ntawm 9 cm los ntawm sab saud. Qhov no tuav lub rooj tsavxwm uas tus coj yuav zaum.

Lub rooj tsavxwm nrog tus coj yog lub rooj tsavxwm me me (32 cm x 32 cm).

Kuv drilled 9 qhov rau cov coj kom tawm ntawm.

faib

Kuv tau faib ua cov khoom qub ib yam li hauv qab thiab pawg thawj coj nrog coj.

4 daim ib qho nrog qhov txhab ntawm 10.3 cm (9 cm x 31 cm). Tam sim no kuv tuaj yeem tso lawv ua ke.

Khawm thiab nyeem ntawv RFID

Kuv tau ua lub qhov hauv paus kom tso kuv li RFID nyeem ntawv thiab cov nyees khawm nkag rau. Rau RFID Kuv muab daim txiag nyias nyias tso rau pem hauv ntej kom nws zoo nkauj dua.

Kauj Ruam 6: Kauj Ruam 6: Muab Txhua Yam Hauv Tsev

Qhov no nyob ntawm seb koj xav ua nws li cas. Kuv tus kheej siv ntau txoj hlua tsis tas yuav siv dua vim kuv xav kom rov siv tau kuv li Raspberry Pi.

Kuv glued tus coj nyob rau hauv qhov chaw thiab kaw cov RFID nyeem ntawv thiab breadboards rau rooj plaub.

Thiab qhov no yog qhov koj ua tus Keysorter!

Pom zoo: