Cov txheej txheem:

Google Assistant Raws Li LED Tswj Siv Raspberry Pi: 3 Kauj Ruam
Google Assistant Raws Li LED Tswj Siv Raspberry Pi: 3 Kauj Ruam

Video: Google Assistant Raws Li LED Tswj Siv Raspberry Pi: 3 Kauj Ruam

Video: Google Assistant Raws Li LED Tswj Siv Raspberry Pi: 3 Kauj Ruam
Video: Tshuaj theem vim li cas thiaj tau nqi ?/ Siv kho mob dab tsi?/paris polyphylla use for? 2024, Kaum ib hlis
Anonim
Google Assistant Raws Li LED Tswj Siv Raspberry Pi
Google Assistant Raws Li LED Tswj Siv Raspberry Pi
Google Assistant Raws Li LED Tswj Siv Raspberry Pi
Google Assistant Raws Li LED Tswj Siv Raspberry Pi
Google Assistant Raws Li LED Tswj Siv Raspberry Pi
Google Assistant Raws Li LED Tswj Siv Raspberry Pi
Google Assistant Raws Li LED Tswj Siv Raspberry Pi
Google Assistant Raws Li LED Tswj Siv Raspberry Pi

Hav!

Hauv txoj haujlwm no, peb yuav siv Google Assistant raws li kev tswj hwm ntawm LED siv Raspberry Pi 4 siv HTTP hauv Python. Koj tuaj yeem hloov lub LED nrog lub teeb pom kev (pom tseeb tsis yog lus, koj yuav xav tau lub teeb hluav taws xob sib txuas hauv nruab nrab) lossis lwm yam khoom siv hauv tsev yog li qhov haujlwm no tuaj yeem ua tiav ntxiv rau lub hom phiaj siv hluav taws xob hauv tsev.

Khoom siv

Yam koj yuav xav tau rau qhov haujlwm no:

1. Raspberry Pi

2. LED

3. Jumper xov hlau -2 (txiv neej rau poj niam)

4. Cov qhob cij

5. IFTTT app (https://play.google.com/store/apps/details?id=com.ifttt.ifttt&hl=en_IN)

6. Thingspeak tus account (https://thingspeak.com/)

Qee qhov yuav tsum tau ua ua ntej:

1. Networking Basics-HTTP

2. Nab hab sej kom nkag mus saib cov ntaub ntawv hauv web

Kauj ruam 1: Tsim Ib Yam Dab Tsi Channel

Tsim Ib Yam Dab Tsi Channel
Tsim Ib Yam Dab Tsi Channel
Tsim Ib Yam Dab Tsi Channel
Tsim Ib Yam Dab Tsi Channel
Tsim Ib Yam Dab Neeg Channel
Tsim Ib Yam Dab Neeg Channel
Tsim Ib Yam Dab Tsi Channel
Tsim Ib Yam Dab Tsi Channel

Yog tias koj tshiab rau Thingspeak thiab tsis tau siv dua ua ntej, ua raws cov theem hauv qab no:

Mus rau

Koj yuav tsum tso npe ua ntej koj pib siv Thingspeak

Tom qab kos npe, mus rau ntu Channels

Hauv qab Cov Kab, xaiv Tshiab Channel (saib duab rau siv)

Hauv Channel Tshiab, koj yuav pom cov ntaub ntawv sib txawv lub thawv. Koj tsuas yog yuav tsum tau sau rau hauv Lub Npe Lub Npe. Koj tuaj yeem tso npe rau koj cov channel yam koj xav tau. Kuv tau txuas daim duab uas kuv tau tso kuv lub npe hu ua Raspberry Pi 4. Tawm ntawm lub thawv uas seem li nws yog.

Nrog koj zoo siab! Koj tau ua tiav tsim cov channel rau koj qhov haujlwm IoT. (saib cov duab txuas uas koj tuaj yeem pom kuv cov channel hu ua Raspberry Pi 4 tau tsim tiav)

Kauj Ruam 2: Siv IFTTT App

Siv IFTTT App
Siv IFTTT App
Siv IFTTT App
Siv IFTTT App
Siv IFTTT App
Siv IFTTT App
Siv IFTTT App
Siv IFTTT App

Peb yuav tsum siv daim ntawv thov no txhawm rau ua kom tau txais kev thov rau tshaj tawm cov ntaub ntawv ntawm koj tus Tsim Thingspeak channel siv Google Assistant. Xav txog lub app no ua kev sib cuam tshuam ntawm Google Assistant thiab koj Thingspeak channel.

Tom ntej no, peb tsim GET thov ntawm IFTTT app.

Rub tawm IFTTT app los ntawm

Tsim koj tus account

Mus rau Ua koj tus kheej Applets los ntawm kos

Coj mus rhaub Yog tias qhov kev xaiv no

Xaiv qhov kev pabcuam ua Google Assistant

Hauv qhov ntawd, xaiv Hais ib kab lus yooj yim

Hauv qab qhov kev xaiv ntawd, qee lub thawv xov xwm yuav tshwm sim. Txog qhov ntawd, xa mus rau cov duab thiab sau cov ntsiab lus kom haum! (muaj ob daim duab rau lub hom phiaj no: 1. Ua kom lub teeb ci LED 2. Ua kom lub teeb tawm)

Peb tau ua tiav Qhov Yog Qhov no yog Google Assistant. Tam sim no peb xaiv Tom qab ntawd qhov kev xaiv uas yog Webhooks.

Hauv qab no, xaiv Ua lub vev xaib thov

Xa daim duab rau cov ntaub ntawv uas yuav tsum tau sau rau hauv lub thawv. Xa mus rau qhov URL no https://api.thingspeak.com/update?api_key=INSERT KOJ YUAV TSUM sau API KEY & field1 = 1

Hauv qhov URL saum toj no, koj yuav pom tias kuv tau hais txog INSERT YOUR WRITE API KEY. Nov yog tus yuam sij API uas yog tus kheej ntawm cov channel uas koj tau tsim ntawm Thingspeak (saib duab). Sau tus lej API yuav pab koj sau cov ntaub ntawv tshwj xeeb rau koj cov channel thiab zoo ib yam Nyeem API qhov tseem ceeb yuav pab koj kom tau txais cov ntaub ntawv los ntawm cov channel.

Sib nrug los ntawm koj Sau API tus yuam sij, cov ntaub ntawv tas los ntawm cov thawv tseem zoo ib yam.

Yog li ntawm no koj tau tsim qhov tshwm sim qhov twg thaum koj hais rau koj tus Google Assistant, "Qhib lub LED rau" nws yuav xa "1" rau koj li Thingspeak channel.

Tam sim no, zoo ib yam, koj yuav tsum tsim Applet tshiab ntawm IFTTT app txhawm rau tig lub LED tawm. Kuv tau txuas cov duab yog tias koj tsis meej pem txog qhov zoo ib yam. Txwv tsis pub, cov txheej txheem tig lub LED tawm yog tib yam li qhov koj tau ua saum toj no sib nrug ntawm qee qhov kev hloov pauv me me.

Kauj ruam 3: Thaum kawg Pib rau Code

Thaum kawg Pib rau Code
Thaum kawg Pib rau Code

Kuv yuav piav qhia lub hom phiaj tseem ceeb ntawm Python code. Peb yuav tsum nqa cov ntaub ntawv los ntawm Thingspeak channel uas yuav yog "1" lossis "0" raws li qhov koj hais rau koj tus Google Assistant. Peb yuav tsum qhib lossis tua LED raws qhov no. Yog tias tus nqi tso tawm ntawm Thingspeak channel yog "1", tom qab ntawd peb qhib lub LED, thiab yog tias nws yog "0", peb tua nws.

Hauv txoj cai, koj yuav xav tau ob yam: 1. Koj Nyeem API qhov tseem ceeb 2. Koj li Channel ID (xa cov duab rau tib yam)

Nov yog tus lej (piv txwv tias koj paub qhov yuav tsum tau ua ntej ntawm HTTP thiab Python):

ntshuam urllib

ntshuam thov

ntshuam json

lub sij hawm ntshuam

ntshuam RPi. GPIO ua GPIO

GPIO.setmode (GPIO. BOARD)

GPIO.setup (7, GPIO. OUT)

sim:

thaum (1):

URL = 'https://api.thingspeak.com/channels/INSER KOJ CHANNEL ID/fields/1.json? Api_key =' KEY = 'INSERT YOUR READ API KEY'

HEADER = '& cov txiaj ntsig = 2'

NEW_URL = URL+KEY+HEADER

#print (NEW_URL)

get_data = thov.get (NEW_URL).json ()

#print (tau_data)

feild_1 = get_data ['txau']

#print ("Teb:", feild_1)

t =

rau x hauv feild_1:

t.append (x ['field1'])

luam tawm (t [1])

yog int (t [1]) == 1:

GPIO. tawm (7, 1)

elif int (t [1]) == 0:

GPIO.output (7, 0)

tshwj tsis yog KeyboardInterrupt:

GPIO.cleanup ()

Pom zoo: