Cov txheej txheem:

Cov Txheej Txheem Kev Tswj Cov Khoom Siv: 10 Cov Kauj Ruam (nrog Duab)
Cov Txheej Txheem Kev Tswj Cov Khoom Siv: 10 Cov Kauj Ruam (nrog Duab)

Video: Cov Txheej Txheem Kev Tswj Cov Khoom Siv: 10 Cov Kauj Ruam (nrog Duab)

Video: Cov Txheej Txheem Kev Tswj Cov Khoom Siv: 10 Cov Kauj Ruam (nrog Duab)
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim
Cov Txheej Txheem Kev Tswj Xyuas Cov Khoom Siv
Cov Txheej Txheem Kev Tswj Xyuas Cov Khoom Siv

Kuv ib txwm xav tau txoj hauv kev pheej yig kom taug qab txhua yam hauv kuv lub pantry, yog li ob peb lub hlis dhau los kuv tau pib ua haujlwm ntawm ib qhov haujlwm uas yuav ua li ntawd. Lub hom phiaj yog ua kom yooj yim, pheej yig uas yooj yim siv thaum tseem khaws cov ntaub ntawv txaus kom tsim nyog rau kev siv zog ntxiv. Qhov kuv ua thaum kawg yog kev tswj hwm cov khoom lag luam uas tuaj yeem khaws thiab hloov kho cov ntaub ntawv hais txog txhua yam khoom uas muaj tus lej bar code, ntxiv rau kuv cov ntaub ntawv yooj yim txog cov khoom ntawd hauv internet.

Hauv ntej, lub kaw lus ua haujlwm zoo li no.

  1. Ib qho bar code tau luam theej duab.
  2. Python tsab ntawv nyeem cov ntaub ntawv los ntawm lub tshuab luam ntawv.
  3. Qhov kev thov raug xa mus rau REST API khiav ntawm node-liab.
  4. API txheej txheem thov, mines cov ntaub ntawv ntxiv hauv is taws nem, thiab kho cov ntaub ntawv raws li qhov tsim nyog.

Txhua yam no tau ua tiav ntawm ib qho Raspberry Pi, muab koj lub peev xwm los hloov kho thiab khaws cov ntaub ntawv txog koj cov khoom lag luam tag nrho hauv ib qho me me, nqa tau yooj yim. Txoj haujlwm no yog qhov txuj ci me ntsis thiab nkag siab yooj yim ntawm cov chaw khaws ntaub ntawv, HTTP, thiab Python yuav pab tau heev, tab sis kuv yuav ua qhov zoo tshaj plaws kom yooj yim txaus rau tus pib nkag siab. Cia peb pib!

Kauj ruam 1: Yam Koj Yuav Tsum Tau

Yam Koj Yuav Tsum Tau
Yam Koj Yuav Tsum Tau

Cov ntu koj yuav xav tau rau txoj haujlwm no yog…

  • Raspberry Pi
  • USB Bar Code Scanner (txuas rau qhov kuv siv)
  • WiFi adapter (Yog tias koj Pi tsis tau tsim hauv WiFi)
  • Toggle Hloov
  • Jumper Hlau
  • Case rau koj Raspberry Pi (yeem)

Kauj ruam 2: Nruab thiab teeb tsa Database

Nruab thiab teeb tsa Database
Nruab thiab teeb tsa Database

MySQL yog cov txheej txheem tswj hwm cov ntaub ntawv uas yuav tuav tag nrho cov ntaub ntawv peb rub tawm los ntawm kev ntsuas kab ntawv. Qhov no yooj yim heev ua ntawm Pi, yooj yim khiav cov lus txib hauv qab no hauv lub davhlau ya nyob twg ntawm koj Pi.

sudo apt-tau nruab mysql-server

Tom qab ntawd koj yuav tau taug kev los ntawm cov txheej txheem teeb tsa, thiab hais kom tsim tus password. Qhov ntawd yog nws. Nrog MySQL teeb tsa, koj Pi tuaj yeem ua raws li nws tus kheej lub server me me. Tam sim no peb yuav tsum tsim cov ntxhuav uas yuav tuav peb cov ntaub ntawv. Ua ntej, nkag mus. Tom qab teeb tsa, tsuas yog MySql tus neeg siv yog hauv paus (tus neeg siv uas tau nkag mus rau txhua lub rooj thiab kab ke). Koj tuaj yeem nkag mus rau hauv hauv paus los ntawm kev ua cov lus txib hauv qab no.

mysql -root -p

Tsis ntev peb yuav teeb tsa lwm tus neeg siv uas peb cov txheej txheem siv tab sis ua ntej peb yuav tsum tsim peb cov ntaub ntawv khaws tseg, thiab cov ntxhuav hauv cov ntaub ntawv ntawd. Txhawm rau ua qhov no, khiav cov lus txib hauv qab no.

tsim cov khoom lag luam database;

siv cov khoom lag luam; tsim cov lus upc_count (upc varchar (15) tsis yog null, suav cov lej (3) tsis null default 0, npe varchar (255), loj varchar (40), chaw tsim khoom varchar (80), thawj qhov tseem ceeb (upc));

Tam sim no peb muaj cov lus yooj yim nrog tsib kab upc (uas yuav yog tus yuam sij thawj), suav, lub npe, qhov loj me, thiab chaw tsim khoom. Nco tseg: Tus lej nce yog tus lej uas qhia qhov khoom tshwj xeeb. Tus lej ntawd yog dab tsi uas tau nyeem los ntawm daim ntawv cim npe bar code thaum nws tau luam tawm.

Thaum kawg, peb yuav teeb tsa tus neeg siv uas peb xav tau. Kuv yuav hu rau kuv, ua qhov no, ua raws cov lus txib hauv qab no, siv lub npe siv thiab tus lej twg koj xav tau:

muab tag nrho ntawm cov khoom muag.* rau ''@'localhost' txheeb xyuas los ntawm;

Tam sim no peb muaj peb lub database, peb tuaj yeem pib tsim cov kab ke!

Kauj Ruam 3: Tau Txais OutPan API Key

OutPan yog API uas tuaj yeem siv tau cov ntaub ntawv hais txog cov khoom siv nws tus lej upc. Peb yuav siv qhov no txhawm rau tshawb xyuas cov ntaub ntawv ntau ntxiv txog cov khoom lag luam raws li lawv tau ntxiv rau hauv cov ntaub ntawv khaws tseg. Nov yog pej xeem api, tab sis txhawm rau siv nws koj yuav tsum sau npe thiab tau txais tus yuam sij api. Kev sau npe yog qhov yooj yim heev, tsuas yog mus ntawm no thiab ua raws cov kauj ruam txhawm rau sau npe rau tus yuam sij.

Thaum koj tau txais koj tus yuam sij, theej nws tawm. Koj yuav xav tau nws hauv qib tom ntej.

Kauj Ruam 4: Nruab thiab Teeb Node-Liab

Nruab thiab Teeb Node-Liab
Nruab thiab Teeb Node-Liab
Nruab thiab Teeb Node-Liab
Nruab thiab Teeb Node-Liab

Node-Red los tau teeb tsa ua ntej ntawm txhua lub khoos phis tawj ntawm Raspbian OS txij li qhov kawg ntawm 2015. Txhawm rau kom paub yog tias koj tau node-liab teeb tsa, yooj yim khiav cov lus txib hauv qab no hauv lub davhlau ya nyob twg.

node-liab

Yog tias "lus txib tsis pom" cov lus tau tshwm sim, koj yuav tsum tau teeb tsa ntawm-liab. Txhawm rau ua qhov no, khiav cov lus txib hauv qab no.

sudo apt-tau hloov tshiab sudo apt-tau nruab nodered

Tom qab pib node-liab, koj tuaj yeem nkag mus rau liab-liab los ntawm qhov chaw nyob pom hauv qhov tso tawm.

Tsuas yog teeb tsa sab laug yog teeb tsa MySQL nodes. Koj tuaj yeem ua qhov no los ntawm qhov browser. Nyem rau ntawm lub cim nyob rau sab xis saum toj ntawm nplooj ntawv thiab tom qab ntawd nyem rau ntawm 'Manage Palette' xaiv. Los ntawm qhov ntawd yooj yim tshawb rau 'mysql' thiab nyem lub pob teeb tsa.

Tam sim no peb tau npaj los ntshuam API.

Kauj Ruam 5: Teeb API

Teeb API
Teeb API
Teeb API
Teeb API
Teeb API
Teeb API

Hauv qab no yog tag nrho cov node-liab API uas kuv tau sau. Cias luam txhua yam hauv qab no, nyem rau ntawm lub cim nyob rau sab xis saum toj, thiab mus rau ntshuam → los ntawm cov ntawv teev cia.

[{"id": "ef09537e.8b96d", "type": "subflow", "name": "mineOpenPanData", "info": "", "in": [{"x": 64, "y": 57, "xov hlau": [{"id": "b8b6d2e4.169e7"}]}}, "tawm": [{"x": 755, "y": 58, "xov hlau": [{"id": "8dc2d52b.6a6fd8", "port": 0}]}]}, {"id": "b8b6d2e4.169e7", "type": "http request", "z": "ef09537e.8b96d", "npe ":" Tawm Pan Pan "," method ":" GET "," ret ":" txt "," url ":" https://api.outpan.com/v2/products/{{{upc}}} ? apikey = "," tls ":" "," x ": 202," y ": 57," xov ":

Tam sim no koj muaj tag nrho API uas peb yuav siv los ntxig thiab hloov kho cov ntaub ntawv. Tsuas yog ob peb qhov kev hloov kho yuav tsum tau ua ua ntej peb npaj siv nws.

  1. Ua ntej, nkag mus rau txhua qhov MySQL database nodes thiab hloov lub npe siv thiab tus lej nkag mus rau cov uas koj tsim rau lub database hauv cov kauj ruam dhau los.
  2. Qhov thib ob, hloov kho mineOutPanData subflow kom HTTP thov siv kom tau txais Open Pan cov ntaub ntawv siv koj tus kheej tus lej API.

Tam sim no koj tau npaj siv API. Cov dej ntws no tsim tau yooj yim REST API uas tso cai rau koj xa cov ntaub ntawv los ntawm ib lub cuab yeej txuas nrog internet siv HTTP thov.

Kauj Ruam 6: (Tsis teb los tau) Nkag siab API

Txuas lub Toggle Hloov
Txuas lub Toggle Hloov

Qhov kawg peb yuav tsum tau ua yog txuas qhov hloov pauv mus rau GPIO yog li peb tuaj yeem luam theej tawm hauv ob hom, ntxiv thiab tshem tawm.

Nov yog qhov zoo nkauj ncaj nraim, yooj yim teeb tsa toggle hloov los nyeem los ntawm GPIO tus pin 21 ntawm tus Pi thiab koj zoo mus. Siv lub voj voos ntawm daim duab txuas (hu ua PUD DOWN Circuit) tsab ntawv yuav xa cov ntawv thov ntxiv thaum lub toggle hloov tau raug kaw thiab thov tshem tawm thaum lub toggle hloov tau qhib.

Tom qab ntawd peb tsuas xev cov xov hlau rau sab hauv ntawm rooj plaub thiab peb zoo mus.

Kauj Ruam 9: (Tsis teb los tau) Tsim Tus Neeg Siv Kev Sib Tham

(Tsis teb los tau) Tsim Tus Neeg Siv Kev Sib Tham
(Tsis teb los tau) Tsim Tus Neeg Siv Kev Sib Tham

Kauj ruam kawg no tsis tsim nyog tab sis yuav pab tau yog tias koj xav siv lub peev xwm ntawm lub kaw lus. Kuv rigged tus neeg siv yooj yim heev interface uas nthuav tawm tag nrho cov ntaub ntawv peb muaj hauv peb cov database hauv qhov yooj yim mus rau lub rooj. Lub rooj tuaj yeem txheeb los ntawm kab ntawv thiab tseem tshawb nrhiav, ua kom yooj yim pom qhov koj muaj ntawm tes.

UI yog qhov yooj yim zoo nkauj; Kuv rov npaj siab qee qhov piv txwv piv txwv kuv pom hauv online los ua haujlwm nrog peb API (yog tias koj txaus siab, tus lej piv txwv tuaj yeem pom ntawm no).

Txhawm rau khiav UI, ua cov hauv qab no …

  1. Txuag cov ntaub ntawv txuas nrog index.txt ua index.html (Kuv tsis tuaj yeem xa cov ntawv ua HTML ntaub ntawv rau qee qhov laj thawj).
  2. Muab ob daim ntawv tso rau hauv tib lub npe ntawm koj lub computer.
  3. Khiav cov ntawv 'index.html' hauv koj lub vev xaib uas koj nyiam.

Tam sim no peb tuaj yeem pom yooj yim thiab txheeb los ntawm koj cov khoom muag!

Kauj ruam 10: Pib Scanning

Pib Luam theej duab!
Pib Luam theej duab!

Tam sim no koj tau npaj los pib scanning! Yog tias koj muaj lus nug dab tsi tso rau hauv cov lus thiab kuv yuav nco ntsoov teb thaum kuv tuaj yeem ua tau.

Thaum kawg, koj cov pov npav hauv kev sib tw yuav zoo siab heev. Ua tsaug rau kev nyeem ntawv!

Pom zoo: