Cov txheej txheem:

Tswj Chav Nyob Nrog Alexa thiab Raspberry Pi: 12 Cov Kauj Ruam
Tswj Chav Nyob Nrog Alexa thiab Raspberry Pi: 12 Cov Kauj Ruam

Video: Tswj Chav Nyob Nrog Alexa thiab Raspberry Pi: 12 Cov Kauj Ruam

Video: Tswj Chav Nyob Nrog Alexa thiab Raspberry Pi: 12 Cov Kauj Ruam
Video: Plab Plab Ntswg..(Pluav Pluav Ntswg) Maiv Twm New Song 2023-2024 2024, Hlis ntuj nqeg
Anonim
Tswj Chav Nyob Nrog Alexa thiab Raspberry Pi
Tswj Chav Nyob Nrog Alexa thiab Raspberry Pi

Tswj koj chav TV nyob, teeb, thiab Ntxuam nrog Alexa (Amazon Echo lossis Dot) thiab Raspberry Pi GPIO.

Kauj ruam 1: Pib Teeb

Kuv siv Raspberry Pi 2 thiab Raspbian Jessie duab rub tawm los ntawm

Thaum nkag mus, nkag mus rau cov lus txib hauv qab no txhawm rau txhim kho cov pob khoom xav tau thiab cov tsev qiv ntawv nab nab:

sudo apt-tau hloov tshiab && sudo apt-tau hloov tshiab -ysudo apt-tau nruab python2.7-dev python-dev python-pip sudo pip install Flask flask-ask sudo apt-get install lirc

Kauj ruam 2: Teeb Ngrok

Teeb tsa Ngrok
Teeb tsa Ngrok

Mus ntsib https://ngrok.com/download thiab tau txais qhov tseeb Linux ARM tso tawm raws li zip thiab unzip hauv cov npe hauv tsev:

unzip /home/pi/ngrok-stable-linux-arm.zip

Qhib lub davhlau ya nyob twg tshiab thiab nkag mus rau cov lus txib hauv qab no:

sudo./ngrok http 4000

Qhib lwm lub davhlau ya nyob twg tshiab thiab nkag mus rau cov lus txib hauv qab no:

sudo./ngrok http 4500

Qhib peb lub davhlau ya nyob twg tshiab thiab nkag mus rau cov lus txib hauv qab no:

sudo./ngrok http 5000

Kauj Ruam 3: Python Tsab Ntawv rau Lub Teeb Hloov Tswj

Qhib lub davhlau ya nyob twg ntu tshiab thiab tsim cov ntaub ntawv nab npawb tshiab lub npe light_control.py:

nano teeb_control.py

Luam/paste cov cai hauv qab no rau hauv cov ntawv tshiab:

los ntawm cov raj ntshuam Flaskfrom flask_ask ntshuam Nug, nqe lus, hloov_errors ntshuam RPi. GPIO li GPIO ntshuam logging ntshuam os GPIO.setmode (GPIO. BCM) app = Flask (_ name_) nug = Nug (app, '/') logging.getLogger (" flask_ask "). setLevel (logging. DEBUG) @ask.intent ('LightControlIntent', kuas = {'xwm txheej': 'xwm txheej'}) def light_control (xwm txheej): sim: pinNum = 27 tshwj tsis yog kev zam raws li e: rov hais nqe lus ('Tus lej lej siv tsis tau.') GPIO.setup (pinNum, GPIO. OUT) yog xwm txheej hauv ['ntawm', 'siab']: GPIO.output (pinNum, GPIO. LOW) yog xwm txheej hauv ['tawm', ' tsawg ']: GPIO.output (pinNum, GPIO. HIGH) rov hais qhia (' Tig {} Chav Nyob Teeb'.format (xwm txheej)) yog _name_ == '_main_': chaw nres nkoj = 4000 app.run (host = ' 0.0.0.0 ', chaw nres nkoj = chaw nres nkoj)

Txuag thiab kaw cov ntawv.

Pib flask server nrog:

sudo python light_control.py

Cia ob leeg ngrok thiab light_control.py khiav

Kauj Ruam 4: Python Script rau Fan Control

Qhib lub davhlau ya nyob twg ntu tshiab thiab tsim cov ntaub ntawv nab npawb tshiab hu ua fan_control.py:

nano fan_control.py

Luam/paste cov cai hauv qab no rau hauv cov ntawv tshiab:

los ntawm lub raj mis ntshuam Flask

los ntawm flask_ask ntshuam Nug, nqe lus, hloov_errors ntshuam RPi. GPIO li GPIO ntshuam logging ntshuam os GPIO.setmode (GPIO. BCM) app = Flask (_ name_) nug = Nug (app, '/') logging.getLogger ("flask_ask").setLevel (logging. DEBUG) @ask.intent ('FanControlIntent', kuas = {'xwm txheej': 'xwm txheej'}) def fan_control (xwm txheej): sim: pinNum = 22 tshwj tsis yog raws li e: xa nqe lus ('Tus lej tus lej tsis siv tau. ') GPIO.setup (pinNum, GPIO. OUT) yog xwm txheej hauv [' on ',' high ']: GPIO.output (pinNum, GPIO. LOW) yog tias xwm txheej hauv [' off ',' low ']: GPIO.output (pinNum, GPIO. HIGH) cov lus xa rov qab ('Tig {} Chav Nyob Teeb'.format (xwm txheej)) yog _name_ ==' _main_ ': chaw nres nkoj = 4500 app.run (host =' 0.0.0.0 ', chaw nres nkoj = chaw nres nkoj)

Txuag thiab kaw cov ntawv.

Pib flask server nrog:

sudo python fan_control.py

Tawm ob qho tib si ngrok, light_control.py, thiab fan_control.py khiav

Kauj Ruam 5: Txhim Kho thiab teeb tsa LIRC Pob

Txhawm rau tswj hwm TV koj yuav tsum teeb tsa tus pin ntawm Raspberry Pi los tsim cov duab liab liab (IR) rau koj lub TV tshwj xeeb. Qhib lub davhlau ya nyob twg thiab nkag mus rau cov lus txib hauv qab no txhawm rau teeb tsa LIRC pob uas ua raws li lub teeb liab infrared ntawm ntau lub chaw taws teeb tswj.

sudo apt-tau nruab lirc

Tom ntej no, koj yuav tsum tau pab thiab teeb tsa lub lirc_rpi kernel module. Txhawm rau ua li ntawd, qhib cov qauv hauv Nano editor

sudo nano /thiab /modules

Ntxiv cov kab hauv qab no rau hauv cov ntawv (Nco ntsoov tias gpio_out_pin qhov ntsuas ntsuas ntsuas rau tus pin tswj IR LED):

lirc_devlirc_rpi gpio_out_pin = 17

Tom ntej no, qhib kho vajtse.conf filein Nano ua ntej nrog sudo:

sudo nano /etc/lirc/hardware.conf

Ntxiv cov teeb tsa hauv qab no rau hauv cov ntawv:

LIRCD_ARGS = "-uinput" LOAD_MODULES = muaj tseeb

DRIVER = "pib"

DEVICE = "/dev/lirc0"

MODULES = "lirc_rpi"

LIRCD_CONF = ""

LIRCMD_CONF = ""

Tam sim no, rov pib dua Raspberry Pi:

sudo rov pib dua

Kauj Ruam 6: Python Script rau TV Tswj

Qhib lub davhlau ya nyob twg ntu tshiab thiab tsim cov ntaub ntawv nab npawb tshiab hu ua ir_control.py:

nano ir_control.py

Mus rau

Nrhiav lub chaw taws teeb uas sib haum nrog koj lub TV. Hauv kuv qhov xwm txheej kuv muaj Sanyo TV uas ua haujlwm nrog sanyo-tv01 teeb tsa cov ntaub ntawv. Thaum koj pom cov ntawv uas txhawb nqa koj lub TV qhib nws thiab saib los ntawm cov lus txib xaiv.

Luam/paste cov cai hauv qab no rau hauv cov ntawv tshiab thiab hloov sanyo-tv01 nrog lub npe cov ntaub ntawv uas ua haujlwm nrog koj lub TV. Kuj xyuas kom ntseeg tau tias lub TV txib tau txais kev txhawb nqa los ntawm koj lub TV teeb tsa cov ntaub ntawv; Koj yuav tau hloov kho KEY_POWER, KEY_VIDEO, KEY_VOLUMEUP, KEY_VOLUMEDOWN, thiab KEY_MUTE cov lus txib kom ua haujlwm raug nrog koj lub TV cov ntaub ntawv teeb tsa:

los ntawm cov raj ntshuam Flaskfrom flask_ask ntshuam Nug, nqe lus, hloov_errors ntshuam RPi. GPIO li GPIO ntshuam logging ntshuam os GPIO.setmode (GPIO. BCM) app = Flask (_ name_) nug = Nug (app, '/') logging.getLogger (" flask_ask "). setLevel (logging. DEBUG) @ask.intent ('GPIOControlIntent', kuas = {'xwm txheej': 'xwm txheej'}) #'tus pin': 'tus pin'}) def tv_function (xwm txheej): yog xwm txheej ['tig rau']: os.system ("irsend SEND_ONCE sanyo-tv01 KEY_POWER") rov hais nqe lus ('Tig rau TV') elif status in ['turn off']: os.system ("irsend SEND_ONCE sanyo-tv01 KEY_POWER ") rov hais nqe lus ('Tua lub TV') elif xwm txheej hauv ['hloov pauv cov tswv yim']: os.system (" irsend SEND_ONCE sanyo-tv01 KEY_VIDEO ") os.system (" irsend SEND_ONCE sanyo-tv01 KEY_VIDEO ") rov qab nqe lus ('Hloov cov tswv yim hauv TV') elif xwm txheej hauv ['nce ntim']: os.system ("irsend SEND_ONCE sanyo-tv01 KEY_VOLUMEUP") os.system ("irsend SEND_ONCE sanyo-tv01 KEY_VOLUMEUP") os.system ("irsend SEND_ONCE sanyo-tv01 KEY_VOLUMEUP") os.system ("xa rov qab SEND_ONCE sanyo-tv01 KEY_VOLUMEUP ") os.system (" irsend SEND_ONCE sanyo-tv01 KEY_VOLUMEUP ") rov hais nqe lus ('Ua kom muaj zog ntxiv hauv TV') elif xwm txheej hauv ['txo ntim']: os.system (" rov qab SEND_ONCE sanyo-tv01 KEY_VOLUMEDOWN ") os.system ("irsend SEND_ONCE sanyo-tv01 KEY_VOLUMEDOWN") os.system ("irsend SEပြန် ") rov qab nqe lus ('Txo Cov Ntim Hauv TV') elif status in ['mute']: os.system (" irsend SEND_ONCE sanyo-tv01 KEY_MUTE ") return statement ('Muting the TV') elif status in ['unmute ']: os.system ("irsend SEND_ONCE sanyo-tv01 KEY_MUTE") rov qab nqe lus (' Unmuting TV ') lwm qhov: rov hais nqe lus (' Tsis muaj nuj nqi nyob deb. ') yog _name_ ==' _main_ ': chaw nres nkoj = 5000 app.run (host = '0.0.0.0', chaw nres nkoj = chaw nres nkoj)

Txuag thiab kaw cov ntawv.

Pib flask server nrog:

sudo python ir_control.py

Tawm tag nrho peb lub qhov rooj davhlau ya nyob twg windows, light_control.py, fan_control.py, thiab ir_control.py khiav

Kauj ruam 7: Nkag mus rau AWS Account

Login to AWS Account
Login to AWS Account

Ua ntej tsim lossis nkag mus rau koj tus AWS Tus Tsim Kho Tus Kheej thiab qhib koj cov npe ntawm Alexa Txawj Ntse.

Kauj Ruam 8: Teeb TV Alexa Txuj Ci

Kev teeb tsa TV Alexa Skill
Kev teeb tsa TV Alexa Skill

Xaiv "Ntxiv Kev Txawj Ntse Tshiab".

Teem lub Npe Txawj Ntse rau 'Trigger TV' thiab Lub Npe Lub Npe rau lo lus (s) koj xav siv los qhib kev txawj.

Nyem 'Tom ntej' txuas ntxiv.

Luam/muab tshuaj txhuam cov hauv qab no rau hauv 'Lub Hom Phiaj Ua Haujlwm' lub thawv:

"slots": [{"name": "status", "type": "TV_Function"}, {"name": "amount", "type": "AMAZON. NUMBER"}], "txhob txwm": "GPIOControlIntent "}]}

Tom ntej no, nyem 'Ntxiv Qhov Hom'

Nkag mus TV_Function hauv qhov 'Enter Type' field.

Nkag mus rau qhov tseem ceeb hauv qab no hauv qhov 'Enter Values' field:

tig rau

tua kev hloov pauv tswv yim nce ntim txo ntim mute unmute

Tom ntej no, Luam/paste cov hauv qab no rau hauv 'Sample Utterances' lub thawv:

GPIOControlIntent {xwm txheej}

GPIOControlIntent {xwm txheej} los ntawm {tus nqi}

Nyem 'Tom ntej' txuas ntxiv.

Xaiv 'HTTPS' raws li Hom Kev Pab Cuam Tshuam thiab xaiv ib cheeb tsam. Enter ngrok URL los ntawm kauj ruam 2 thiab nyem 'Tom ntej'. Qhov URL yuav tsum yog qee yam xws li:

ed6ea04d.ngrok.io

Nyem 'Tom ntej' txuas ntxiv thiab nias 'Txuag'.

Kauj Ruam 9: Teeb Alexa Txuj Ci Teeb

Teeb Teeb Alexa Txuj Ci Teeb
Teeb Teeb Alexa Txuj Ci Teeb

Kaw qhov txuj ci qhib thiab xaiv "Ntxiv Qhov Txuj Ci Tshiab".

Teem lub Npe Txawj Ntse rau 'Teeb Tswj' thiab Lub Npe Sau Npe rau lo lus (s) koj xav siv los qhib kev txawj.

Nyem 'Tom ntej' txuas ntxiv. Luam/muab tshuaj txhuam cov hauv qab no rau hauv 'Lub Hom Phiaj Ua Haujlwm' lub thawv:

{

"kev xav": [{"slots": [{"name": "status", "type": "LIGHTS_CONTROL"}], "txhob txwm": "LightsControlIntent"}]}

Tom ntej no, nyem 'Ntxiv Qhov Hom'.

Nkag mus "LIGHTS_CONTROL" hauv qhov 'Enter Type' field.

Nkag mus rau qhov tseem ceeb hauv qab no hauv qhov 'Enter Values' field:

nyob rau

tawm

Tom ntej no, Luam/paste cov hauv qab no rau hauv 'Sample Utterances' lub thawv:

LightsControlIntent tig {xwm txheej}

Nyem 'Tom ntej' txuas ntxiv. Xaiv 'HTTPS' ua Hom Kev Pabcuam Qhov Chaw thiab xaiv ib cheeb tsam. Nkag mus rau ngrok URL los ntawm kauj ruam 2 thiab nyem 'Tom ntej'. Qhov URL yuav tsum yog qee yam xws li:

ed6ea04d.ngrok.io

Nyem 'Tom ntej' txuas ntxiv thiab nias 'Txuag'.

Kauj Ruam 10: Ntxuam Alexa Txuj Ci Teeb

Ntxuam Alexa Txuj Ci Teeb
Ntxuam Alexa Txuj Ci Teeb

Kaw qhov txuj ci qhib thiab xaiv "Ntxiv Qhov Txuj Ci Tshiab".

Teem lub Npe Kev Txawj Ntse rau 'Kev Tswj Tus Kheej' thiab Lub Npe Sau Npe rau lo lus (s) koj xav siv los qhib lub peev xwm.

Nyem 'Tom ntej' txuas ntxiv.

Luam/muab tshuaj txhuam cov hauv qab no rau hauv 'Lub Hom Phiaj Ua Haujlwm' lub thawv:

{

"kev xav": [{"slots": [{"name": "status", "type": "FAN_CONTROL"}], "txhob txwm": "FANControlIntent"}]}

Tom ntej no, nyem 'Ntxiv Qhov Hom'.

Nkag mus "FAN_CONTROL" hauv qhov 'Enter Type' field.

Nkag mus rau qhov tseem ceeb hauv qab no hauv qhov 'Enter Values' field:

nyob rau

tawm

Tom ntej no, Luam/paste cov hauv qab no rau hauv 'Sample Utterances' lub thawv:

FANControlIntent tig {xwm txheej}

Nyem 'Tom ntej' txuas ntxiv. Xaiv 'HTTPS' ua Hom Kev Pabcuam Qhov Chaw thiab xaiv ib cheeb tsam. Nkag mus rau ngrok URL los ntawm kauj ruam 2 thiab nyem 'Tom ntej'. Qhov URL yuav tsum yog qee yam xws li:

ed6ea04d.ngrok.io

Nyem 'Tom ntej' txuas ntxiv thiab nias 'Txuag'.

Kauj ruam 11: Tsim Ciruit

Tsim Ciruit
Tsim Ciruit

Txuas lub Circuit Court raws li qhia hauv daim duab. Kuv siv JBtek 8 Channel DC 5V Relay Module los txuas rau kuv lub tsev AC 120v kab thiab hauv av.

Kauj ruam 12: Alexa Commands

Tam sim no cov lus txib hauv qab no tuaj yeem hais rau Alexa los tswj koj chav nyob.

Pom zoo: