Cov txheej txheem:

Ok Google Tsob Ntoo Dej/rab phom dej: 20 Kauj Ruam
Ok Google Tsob Ntoo Dej/rab phom dej: 20 Kauj Ruam

Video: Ok Google Tsob Ntoo Dej/rab phom dej: 20 Kauj Ruam

Video: Ok Google Tsob Ntoo Dej/rab phom dej: 20 Kauj Ruam
Video: Ruam tsab ntse tuag tsau dej 2/21/2023 2024, Kaum ib hlis
Anonim
Ok Google Tsob Ntoo Dej/rab phom dej
Ok Google Tsob Ntoo Dej/rab phom dej

Nov yog txoj haujlwm lom zem uas siv Google Tsev lossis ib lub xov tooj nrog Google tus pab rau nws kom tsuag dej rau ntawm ib tus neeg lossis ywg dej rau qee cov nroj tsuag. Nws kuj tseem muaj peev xwm thov tau ntau yam rau lwm yam siv xws li teeb, cua sov, kiv cua thiab lwm yam. Yog tias koj nyiam qhov no thov pov npav rau cov haujlwm no hauv IOT kev sib tw. Ua tsaug.

Kauj Ruam 1: Cov Khoom Xav Tau

Cov peev txheej xav tau
Cov peev txheej xav tau

Koj yuav xav tau cov hauv qab no:

  • Raspberry pi (txhua tus qauv uas tau nkag mus rau internet)
  • Lub twj tso kua dej 12v (Nov yog qhov kuv tau siv)
  • Lub hwj chim 12v (Siv qhov no lossis ib qho dag ib ncig)
  • A 5v 2 channel relay (Nov yog hom uas kuv tau siv)
  • Qee tus poj niam rau poj niam jumper coj
  • Lub thawv yas tuav dej
  • Qee txoj hauv kev kom cov dej tawm ntawm lub twj tso kua mis (Kuv khoov lub raj yas tab sis koj tuaj yeem siv cov quav quav)

Peb tau siv cov khoom xa rov qab raws li nws tso cai rau ua rau nws nyob deb nrog lub raspberry pi ntau dua li yuav tsum muaj lub cev nyob ntawd kom qhib nws raws li koj xav tau yog tias nws tsuas yog hloov pauv.

Kauj ruam 2: Google Assistant

Nco ntsoov tias koj muaj qee txoj hauv kev nkag mus rau Google tus pab. Koj tuaj yeem siv google tsev lossis xov tooj.

Kauj Ruam 3: Txiav Hlau

Txiav Hlau
Txiav Hlau

Siv cov xaim hluav taws xob los txiav thiab tom qab ntawd hle qhov xaus ntawm koj qhov 12v cov khoom siv thiab lub twj tso kua mis kom lawv tuaj yeem txuas rau qhov txuas. Nco ntsoov hle lub tsho kom txaus kom muaj kev sib txuas ruaj khov.

Kauj Ruam 4: Txuas twj rau Relay

Txuas twj rau Relay
Txuas twj rau Relay
  1. Ntsia lub davhlau ya nyob twg nruab nrab ntawm ob qho txuas
  2. Ntxig cov xov hlau los ntawm lub twj tso kua dej
  3. Ntsia dua

Kauj Ruam 5: Txuas Cov Khoom Siv Hluav Taws Xob rau Kev Tshaj Tawm

Txuas Cov Khoom Siv Hluav Taws Xob rau Relay
Txuas Cov Khoom Siv Hluav Taws Xob rau Relay
  1. Tshem tawm cov dav hlau
  2. Muab cov xov hlau los ntawm lub hwj chim 12v tso rau hauv
  3. Ntsia lawv rov qab rau hauv qhov chaw

Kauj Ruam 6: Txuas Raspberry Pi rau Relay

Txuas Raspberry Pi rau Relay
Txuas Raspberry Pi rau Relay

Txuas raspberry pi mus txuas ntxiv raws li qhia hauv daim duab saum toj no. Koj yuav tsum tau txuas tus xa mus rau hauv av, 5v, thiab 2 GPIO pins.

Kauj Ruam 7: Ruaj Ntseg Lub Twj Tso Kua Mis

Ruaj Ntseg Lub Twj Tso Kua Mis
Ruaj Ntseg Lub Twj Tso Kua Mis

Siv ob qho tib si blu-tack lossis kab xev kaw kom ruaj ntseg lub twj tso kua mis rau hauv lub khob yas.

Kauj Ruam 8: Coj Dej

Coj Dej
Coj Dej
Coj Dej
Coj Dej

Yog tias koj xav kom dej txhawm rau ib tus neeg hauv lub ntsej muag nws yuav tsum tau qhia. Txhawm rau ua qhov no kuv siv rab phom cua sov los kho lub raj yas rau hauv cov duab uas pom saum toj no. Tom qab ntawd kuv tau kaw lub cwj mem rau saum. Ib qho ntxiv, koj tuaj yeem siv cov quav nyab.

Yog tias koj xav tau dej qee cov nroj tsuag koj tuaj yeem ntxiv raj yas lossis sab hauv ntawm tus cwj mem.

Kauj Ruam 9: Muab Txhua Yam Ua Ke

Muab Txhua Yam Ua Ke
Muab Txhua Yam Ua Ke
Muab Txhua Yam Ua Ke
Muab Txhua Yam Ua Ke
Muab Txhua Yam Ua Ke
Muab Txhua Yam Ua Ke

Kuv tau ntxiv lwm lub thawv yas thiab muab cov raspberry pi thiab tso rau hauv kom nws tsis txhob ntub.

Kuv tau suav nrog daim duab qhia hluav taws xob saum toj no txhawm rau ua kom pom kev me me.

Kauj Ruam 10: Kuaj Cov Khoom Ua Haujlwm

Txhawm rau ntsuas lub twj tso kua mis ua haujlwm khiav cov cai hauv qab no ntawm raspberry pi. Qhov no yuav tsum tig lub twj tso kua mis tawm thiab tom qab ntawd (lossis lwm txoj hauv kev puag ncig).

los ntawm gpiozero ntshuam LED

lub sijhawm ntshuam #this yuav xa cov qauv cuam tshuam uas peb xav tau rau cov cai no

relay = LED (14)

relay2 = LED (15) #muab lub relays ib LED

thaum Muaj Tseeb:

relay.on () #yog koj twv nws… tig lub relay ntawm relay.off () #yog koj twv nws… tig lub relay tawm lub sijhawm.sleep (1) #tsaug zog rau 1 thib ob relay.on () #relay ntawm relay.off () #relay so time.sleep (1) #tsaug zog

Kauj ruam 11: Ntshuam Flask

Txoj hauv kev yooj yim tshaj plaws rau tus pabcuam google los tswj cov raspberry pi yog los ntawm kev tau txais nws los tuav lub vev xaib. Peb tuaj yeem tau txais Google mus ntsib nplooj ntawv ntawm tus neeg rau zaub mov ntawd thaum twg koj hais qee yam thiab sau tus lej raspberry los qhib thiab xa tawm thaum tus neeg rau zaub mov tuaj xyuas. Yog tias koj xav tau kev qhia ntxaws ntxaws ntxiv ntawm cov hwj tom qab ntawd: mus ntsib qhov kev qhia no los ntawm raspberry pi.

Ntawm koj tus raspberry pi ntshuam lub hwj chim module ntawm nab hab sej.

  1. Xyuas kom koj tau txuas nrog internet
  2. Qhib lub davhlau ya nyob twg
  3. Hom hauv:

sudo pip3 nruab flask

Yog tias qhov no tsis ua haujlwm:

  • Xyuas kom koj tau txuas nrog internet
  • Saib ntawm phau ntawv qhia no

Kauj Ruam 12: Tsim Daim Ntawv Teev Npe rau Peb Txoj Haujlwm thiab Mus Rau Hauv Nws

Ua qhov no los ntawm qhib lub davhlau ya nyob twg thiab ntaus hauv:

mkdir webapp cov

cd wb web

Kauj Ruam 13: Coding Web Server

  1. Qhib tsis ua haujlwm 3
  2. File> Tsim tshiab
  3. Txuag nws hauv lub vev xaib app nplaub tshev uas koj nyuam qhuav tsim
  4. Ntxig cov cai no

los ntawm cov raj ntshuam Flaskfrom gpiozero ntshuam LED lub sijhawm ntshuam #cov no tau xa cov qauv yuav tsum tau ua rau txoj haujlwm no xa tawm = LED (14) relay2 = LED (15) #muab lub relays LED app = Flask (_ name_) #muab Flask hloov pauv lub npe kom thiaj li nws yooj yim dua los ua haujlwm nrog nws tom qab ntawm @app.route ('/', cov hau kev = ['GET']) #ua kom tau txais ntawm nplooj ntawv web "" "qhov haujlwm no yuav rov ua dab tsi uas tau tshwm rau ntawm nplooj ntawv tseem ceeb "" "def index (): rov qab 'Nplooj ntawv tseem ceeb' @app.route ('/on') #turning ntawm kev xa tawm los ntawm kev ua haujlwm hauv qab no" "" tig rau lub relays thiab luam ntawv hi los xyuas qhov ua haujlwm tau zoo " "" def rau (): print ("hi") relay.on () relay2.off () rov qab 'ntawm' @app.route ('/off') #kaw qhov kev xa tawm los ntawm kev ua haujlwm hauv qab no "" "tig tawm ntawm qhov txuas thiab luam ntawv hi los xyuas qhov ua haujlwm tau ua haujlwm raug "" "def off (): print (" nyob zoo ") relay.off () relay2.on () rov qab 'tawm' @app.route ('/mus') #running lub luag haujlwm mus "" "txoj haujlwm no tig rau ntawm qhov txuas kom nws txau dej" "" def go (): relay.on () r elay2.off () time.sleep (3) relay.off () relay2.on () rov qab ('mus') "" "nkag mus rau nplooj ntawv web los ntawm qhov chaw cuam tshuam (8000 feem ntau yog tsev) thiab host" "" yog _name_ == '_main_': app.run (debug = True, port = 8000, host = '0.0.0.0')

Cov lus piav qhia dab tsi tshwm sim hauv txoj cai

Kauj Ruam 14: Xeem Txoj Cai Ua Haujlwm

Qhib koj lub vev xaib thiab nkag mus rau URL

Koj yuav tsum pom lub vijtsam dawb tab sis koj yuav tsum tuaj yeem hnov qhov nyem ntawm qhov txuas mus lossis yog lub twj tso kua mis ntsaws, nws yuav tsum mus.

Txhawm rau tig lub twj tso tawm mus rau

Nco tseg: 127.0.0.1 txhais tau tias "tsev", piv txwv li lub khoos phis tawj no: 5000 txhais tau tias 'chaw nres nkoj 5000', uas yog chaw nres nkoj lub vev xaib ua haujlwm. Yog tias qhov no ua haujlwm ces koj tuaj yeem coj nws mus ntxiv los ntawm:

1. Tshawb nrhiav koj tus raspberry pis tus IP chaw nyob los ntawm kev ntaus hauv:

hostname -Ib

2. Ntawm txhua lub khoos phis tawj txuas nrog tib lub wifi zoo li koj tus pi mus ntsib tus pisipadress/on

Qhov no yuav tsum qhib lub relay.

Qhov no qhia tau tias koj tuaj yeem tswj hwm koj li raspberry pi los ntawm ib lub computer txuas nrog tib lub wifi zoo li koj li raspberry pi.

Kauj ruam 15: Tunneling

Yog li Google Lub Tsev tuaj yeem mus ntsib lub vev xaib no koj yuav xav tsim lub qhov kom cov khoos phis tawj uas tsis txuas nrog tib tus IP chaw nyob zoo li koj tseem tuaj yeem kaw qhov txuas thiab qhib. Koj tuaj yeem ua qhov no nrog ngrok. Nov yog qhov program uas koj tuaj yeem teeb tsa ntawm raspberry pi uas yuav tso cai rau koj mus ntsib lub vas sab lub vev xaib los ntawm ib lub computer.

Mus ntsib lawv lub vev xaib kom paub ntau ntxiv:

Kauj Ruam 16: Txhim Kho Ngrok

Nkag mus rau qhov txuas no ntawm koj tus raspberry pi: https://ngrok.com/download thiab ua raws cov lus qhia txhawm rau rub tawm thiab teeb tsa ngrok.

Kauj Ruam 17: Xeem Ngrok

Xyuas kom tseeb tias koj lub flask server ua haujlwm. Qhib lwm lub davhlau ya nyob twg thiab ntaus hauv cd webapp

Tom qab ntawd pib ngrok los ntawm kev ntaus hauv

./ngrok http 5000

Qhov no yuav tsum qhia koj qhov URL uas koj yuav tsum muaj peev xwm mus rau ntawm ib lub cuab yeej. Luam qhov no thiab xa email rau koj tus kheej rau qib tom ntej

Yog tias qhov no tsis ua haujlwm:

  1. Xyuas kom lub raj mis khiav
  2. Nco ntsoov tias koj tab tom khiav ngrok hauv tib lub nplaub tshev zoo li lub program flask
  3. Nco ntsoov tias koj tau theej qhov txuas raug (nws hloov pauv txhua lub sijhawm koj rov pib qhov haujlwm)

Kauj Ruam 18: IFFF

IFFF: Yog Qhov No Yog Li No yog qhov program pub dawb uas tuaj yeem siv los ua koj lub tsev hauv google mus ntsib lub vev xaib thaum hais ib yam dab tsi rau nws, Txhawm rau teeb tsa qhov no ua raws cov theem hauv qab no:

  1. Tog twg los mus ntsib https://ifttt.com/ lossis rub tawm lub app
  2. Tsim ib tus account
  3. Nyem tsim tshiab applet (qee zaum hauv qab kuv cov applets)
  4. Nyem qhov no
  5. Tshawb Google thiab xaiv Google Assistant
  6. Nyem hais cov kab lus yooj yim
  7. Hauv qab qhov koj xav hais kom muab "qhib dej rab phom"
  8. Nyem tsim txhais
  9. Nyem qhov ntawd
  10. Tshawb nrhiav lub vev xaib
  11. Nyem webnooks
  12. Nyem Ua qhov web thov
  13. Hauv qab URL nkag mus rau qhov URL ngrok muab rau koj ua ntej/mus
  14. Hauv Txoj Cai Xaiv GET
  15. Hauv Cov Ntsiab Lus xaiv cov ntawv/dawb
  16. Nyem Tsim
  17. Nyem tag

Kauj ruam 19: Ua tiav

Tam sim no thaum koj hais nyob zoo google (ntxig cov kab lus koj tau xaiv), lub twj tso kua mis yuav tsum qhib.

Yog tias qhov no tsis ua haujlwm (nws coj kuv txog 15 sim kom nws ua haujlwm):

  1. Nco ntsoov tias txhua qhov program tau ua haujlwm
  2. Xyuas kom txhua tus Leads txuas nrog
  3. Nco ntsoov qhov URL koj nkag mus rau IFTT yog qhov tshiab tshaj plaws
  4. Nco ntsoov tias raspberry pi txuas nrog internet

Kauj Ruam 20: Kev sib tw IOT

Yog tias koj nyiam qhov kev qhia no thov thov pov npav rau peb hauv kev sib tw IOT. Ua tsaug ntau

Pom zoo: