Cov txheej txheem:

Alexa Raspberry Pi Relay Controller: 6 Kauj Ruam
Alexa Raspberry Pi Relay Controller: 6 Kauj Ruam

Video: Alexa Raspberry Pi Relay Controller: 6 Kauj Ruam

Video: Alexa Raspberry Pi Relay Controller: 6 Kauj Ruam
Video: Бесшумное zigbee реле в подрозетник без нулевой линии, особенности монтажа, установка конденсатора 2024, Kaum ib hlis
Anonim
Alexa Raspberry Pi Relay Controller
Alexa Raspberry Pi Relay Controller
Alexa Raspberry Pi Relay Controller
Alexa Raspberry Pi Relay Controller
Alexa Raspberry Pi Relay Controller
Alexa Raspberry Pi Relay Controller

Kuv tsim Cov Lus Qhia no los qhia kuv cov kev paub nrog kev sib xyaw IOT cov khoom siv nrog Amazon's Alexa.

Txoj haujlwm no tso cai rau pawg tswj hwm txuas nrog lub raspberry pi kom tswj tau los ntawm smarthome maub los.

Nws tau raug sim nrog Alexa tab sis kuj zoo li ua haujlwm tau zoo nrog Samsung Smartthings thiab lwm yam kev cuam tshuam kev tswj hwm raws li nws ua raws cov kab ntawm Belkin Wemo qhov nyob.

Muaj ntau qhov piv txwv raws li FAUXMO tus lej zoo tab sis qhov no txhais tau tias kawm nab hab sej thiab tsis muab cov ncauj lus kom ntxaws tswj kuv xav tau rau kuv cov cuab yeej thiab yog li kuv txiav txim siab rov tsim ib qho los ntawm kos siv C raws li kuv lub hauv paus coding lus.

Kuv kuj tsis xav tau mus rau qhov tob ntawm lambda code ntawm Amazon.com yog li kuv tau khaws nws yooj yim heev.

Kuv tau tshaj tawm qhov chaw thiab sau ntawv ntawm Github:

github.com/Switchdoctorstu/StuPiMo

Kev qhia yog tiag tiag txhawm rau ua kom nws ua haujlwm li cas thiab tshaj tawm kuv cov ntawv yog tias nws pab lwm tus.

Kauj Ruam 1: Cov khoom siv thiab kev sib txuas

Cov Khoom Siv thiab Kev Sib Txuas
Cov Khoom Siv thiab Kev Sib Txuas
Cov Khoom Siv thiab Kev Sib Txuas
Cov Khoom Siv thiab Kev Sib Txuas
Cov Khoom Siv thiab Kev Sib Txuas
Cov Khoom Siv thiab Kev Sib Txuas

Yam uas koj xav tau muaj nyob rau ntawm Amazon / EBay:

  • Txiv pos PI *
  • Pi zog muab khoom
  • Dupont txuas
  • Relay Board
  • Qhib micro USB qub (txhawm rau txiav ib nrab rau lub zog rau daim npav txuas)

Ib qho raspberry Pi yuav ua haujlwm, kuv tau sim qhov no ntawm Tus Qauv B thiab Xoom.

*Yog tias siv Pi Zero koj yuav xav tau OTG Network Adapter (tshwj tsis yog koj yuav 'W' version nrog buit hauv WiFi)

Koj yuav tsum txuas tus Pi mus rau lub network.

Siv dupont connetors los txuas daim npav xa mus rau Pi.

Nco tseg tias daim npav xa rov qab yuav tsum siv lub zog sab nraud (tshem qhov txuas thiab txuas mus rau sab nraud 5v). Nws yuav ua haujlwm tau zoo los ntawm PI tab sis nws tsis tau qhia rau kev tsim khoom.

Txog kuv teeb kuv siv lub zog sab nraud USB HUB. Qhov no muab lub zog rau PI.

Kuv kuj txiav qhov kawg ntawm tus xov tooj USB qub thiab siv lub zog txuas los ntawm 2 USB txuas mus rau lub hub kom nyab xeeb. Kuv 'ntau lawm' version siv me me 5V 5A hloov hom fais fab mov. Ib zaug ntxiv kuv tsuas yog txiav USB tus thawj coj hauv ib nrab kom muaj zog Pi ntawm Micro-USB thiab txiav ob qho ntawm dupont txuas mus rau lub hwj chim pawg thawj coj saib xyuas. Muaj 4 lub xov hlau nyob hauv USB, feem ntau siv liab/dub los qhia txog 5v cov khoom siv tab sis yog tias tsis ntseeg siv lub ntsuas kom paub tseeb tias koj tau txais cov xov hlau raug.

Cov pins txuas ntawm lub rooj tsav xwm tau txuas nrog rau GPIO tus lej cuam tshuam ntawm PI lub taub hau.

Txoj cai tso cai rau koj xaiv GPIO pins tab sis lub neej ntawd kuv siv yog:

  1. Relay Pin 1 - Hauv av
  2. Relay Pin 2 - Txuas 1 - GPIO 0
  3. Siv tus lej 3 - Txuas 2 - GPIO 1
  4. Txuas tus lej 4 - Txuas 3 - GPIO 2
  5. Siv tus lej 5 - Txuas 4 - GPIO 3
  6. Siv tus lej 6 - Txuas 5 - GPIO 4
  7. Siv tus lej 7 - Txuas 6 - GPIO 5
  8. Siv tus lej 8 - Txuas 7 - GPIO 6
  9. Siv tus lej 9 - Txuas 8 - GPIO 7
  10. Siv tus lej Pin 10 - +5v rau kev xav

Kauj Ruam 2: Teeb PI

Kuv yuav tsis rov tsim cov lus qhia yuav ua li cas kom tau txais koj li PI thiab khiav thiab txuas nrog lub network.

Muaj ntau cov lus qhia suav nrog kev qhia tau zoo ntawm:

www.instructables.com/id/Ultimate-Raspberr…

Koj yuav tsum coj koj tus kheej mus rau qhov chaw uas pom PI ntawm lub network thiab koj tuaj yeem txuas rau nws.

Nws tsis muaj teeb meem seb qhov no yog dhau Ethernet lossis Wireless.

Txoj haujlwm no tuaj yeem ua tiav nrog tsuas yog Raspberry PI siv Geany Programmers Editor tab sis kuv tus kheej pom nws yooj yim dua los ua kuv cov lej npaj ua ntej ntawm PC siv Visual Studio lossis Eclipse (lossis txawm tias Notepad ++) thiab tom qab ntawd muab nws tso rau PI rau kev debugging siv Kev sib txuas VNC Ib zaug ntxiv kuv yuav tsis npog qhov ntawd vim tias muaj ntau yam qhia tau zoo ntawm teeb tsa VNC ntawm RPi.

Txhua yam koj xav tau yog mus txog qhov chaw koj tuaj yeem rub tawm thiab sau cov cai.

Ib daim ntawv ceeb toom uas tseem ceeb yog vim tias UPNP tus tuav haujlwm xav tau UDP multicast, cov cuam tshuam siv yuav tsum tau teeb tsa mus rau 'Promiscuous' hom.

Qhov no tuaj yeem ua tiav ntawm kab hais kom ua:

pi@raspberrypi: ~ $ ifconfig eth0 promisc

thiab / lossis

pi@raspberrypi: ~ $ ifconfig wlan0 promisc

Qhov no yuav tsum tau ua tas mus li yog li kuv kho qhov /etc/rc.local

sudo nano / etc / rc.local

suav nrog kab:

sudo ifconfig eth0 promisc

tom qab thawj txheej chij # kab kom ntseeg tau tias cov cuam tshuam tau teeb tsa thaum pib.

Kauj Ruam 3: Rub tawm thiab Sib Sau Txoj Cai

Cov cai nws tus kheej zaum hauv kuv Github repsoitory;

github.com/Switchdoctorstu/StuPiMo/blob/ma…

whilst muaj 'txoj kev' txoj hauv kev rau clone lub chaw cia khoom. Kuv pom nws yooj yim dua tsuas yog qhib Geany editor ntawm Pi desktop thiab muab cov lej tso rau hauv.

Ib yam nkaus, yog tias koj siv kab hais kom ua;

Tsim cov npe tshiab

mkdir Tso

Hloov mus rau nws

cd Stuv

Ua ib daim ntawv tshiab

nano StuPiMo.c

Luam cov cai los ntawm Github nyoos thiab muab nws tso rau hauv cov ntawv tshiab

Txuag thiab tawm.

Thaum koj muaj cov ntaub ntawv raws li C qhov khoom siv tus lej koj tuaj yeem sau nws siv

gcc -o StuPiMo StuPiMo.c -l wiringPi

nco ntsoov "-l wiringPi" xav tau los xyuas kom meej tias cov neeg sib txuas sib txuas hauv cov tsev qiv ntawv wiringPi xav tau.

Cov cai tuaj yeem ua haujlwm siv

./StuPiMo

Ib zaug ntxiv, yog tias koj xav kom qhov no khiav ntawm kev pib, siv cov lus txib:

sudo nano /etc/rc.local

ntxiv cov kab hauv qab no

sudo/tsev/pi/Stu/StuPiMo &

rau koj cov ntaub ntawv /etc/rc.local. Tsis txhob hnov qab khaws koj cov ntawv ntawm kev tawm.

Nco tseg qhov '&' yog qhov tseem ceeb kom ntseeg tau tias cov txheej txheem raug tsim los kom ntseeg tau tias tsab ntawv tsis raug thaiv ntawm qhov no.

Kauj ruam 4: Siv Nws

Thaum koj tau txais txoj cai khiav, nug alexa rau 'Tshawb Pom Li' thiab nws yuav tsum pom tag nrho 8 ntawm cov khoom siv Wemo virtual.

Tom qab ntawd nws tsuas yog rooj plaub hais tias: "Alexa tig rau lub qhov (socket) 1" lossis "Alexa tua lub qhov (socket) 6" thiab lwm yam thiab cov cuam tshuam cuam tshuam yuav raug hloov pauv.

Kauj Ruam 5: Txoj Cai Ua Haujlwm Li Cas

Txoj cai ua haujlwm los ntawm kev ua raws cov kab ntawm Belkin Wemo cov khoom siv.

Txhawm rau ua tiav qhov no nws yuav tsum lis 2 txoj haujlwm tseem ceeb

  • UPNP pom kev tshaj tawm xov xwm
  • a 'tus tuav lub cuab yeej' (ib qho ntawm ib lub cuab yeej virtual) los tswj cov lus txib xa mus rau lub cuab yeej thiab cov lus teb xav tau.

Qhov 'txiaj ntsig' tshwj xeeb yog tias nws tseem luam tawm lub vev xaib kom tso cai sib txuas ntawm cov khoom siv.

UPNP tus tuav ntaub ntawv

Tus tuav haujlwm UPNP qhib lub qhov (socket) los saib xyuas SSDP cov txheej txheem txheej txheem ntawm 239.255.255.250 chaw nres nkoj 1900.

Nws teb rau ib qho 'M-SEARCH' cov lus nug los nrog lub pob tshawb pom cov lus teb uas tshaj tawm tus neeg wemo emulators rau txhua tus neeg uas nug.

Tus Neeg Siv Khoom Siv

Tus tuav cov cuab yeej (ib tus rau ib lub cuab yeej virtual) saib xyuas ntawm IP chaw nres nkoj thiab teb rau kev thov.

Nws yuav ua haujlwm teeb tsa.xml cov lus teb thaum nug

Nws yuav ua haujlwm cov ntaub ntawv piav qhia xwm txheej thaum nug

Nws yuav teb rau GETBINARYSTATE thov

Nws yuav ua thiab teb rau SETBINARYSTATE qhov kev thov

Web neeg rau zaub mov

Lub vev xaib yog tus txheej txheem yooj yim uas tsim ib daim ntawv HTML uas muaj lub pob ntawm kev xa tawm.

Nws yuav teb rau cov nyees khawm raug nias thiab toggle lub xeev ntawm kev xa tawm raws li.

Kauj Ruam 6: Customization thiab Cov Npe Zoo

Customization thiab Cov Npe Zoo
Customization thiab Cov Npe Zoo

Kuv tsis tau chim nrog cov cai kom nws yooj yim thiab kho tau.

Cov hauv paus tuaj yeem hloov kho los ntawm cov lus txhais thaum pib ntawm txoj cai:

// ntiaj teb cov ntsiab lus#txhais WEBPORT 5353 // chaw nres nkoj kom khiav lub vev xaib

#define NUMDEVICES 8 // Tus naj npawb ntawm cov cuab yeej virtual los tsim

#define PORTBASE 43450 // lub hauv paus IP chaw nres nkoj kom nce ntxiv los ntawm

WEBPORT yog tus naj npawb chaw nres nkoj uas tsim los hauv lub vev xaib ua haujlwm. Qhov no tuaj yeem ua zaum ntawm 80 kom ua tej yam yooj yim tab sis kuv pom tias nws tsis sib haum nrog tomcat lossis lwm yam kev pabcuam khiav hauv zos.

NUMDEVICES piav qhia tus naj npawb ntawm tus kheej WEMO emulators los tshaj tawm. Yog tias koj muaj 2 daim npav xa daim npav xa tawm qhov no mus rau 2, 4 chaw nres nkoj = 4 thiab lwm yam.

Cov phooj ywg lub npe rau cov cuab yeej tau teeb tsa ib txwm hu ua setup_names:

int setup_names (char tus phooj ywg [NUMDEVICES] [NAMELEN]) {int i = 0;

// siv lub voj no

rau (kuv = 0; kuv <NUMDEVICES; kuv ++) {

sprintf (tus phooj ywg , "Qhov ntsaws %d", i + 1);

}

// lossis cov lus hauv qab no los sau cov npe khoom

/*

strcpy (phooj ywg [0], "TV TV");

strcpy (phooj ywg [1], "Daim pam hluav taws xob");

strcpy (tus phooj ywg [2], "Chav Teeb");

strcpy (phooj ywg [3], "Qhov Ncauj 4");

strcpy (phooj ywg [4], "Qhov Ncauj 5");

strcpy (phooj ywg [5], "Qhov Ncauj 6");

strcpy (phooj ywg [6], "Qhov Ncauj 7");

strcpy (phooj ywg [7], "Qhov Ncauj 8");

*/

rov i;

}

Kuv siv lub voj los hu rau txhua lub cuab yeej 'Socket n' tab sis koj tuaj yeem tshem tawm lub voj no thiab ntxiv koj tus kheej lub npe phooj ywg hloov (tsuas yog nco ntsoov tias koj ntxiv tus lej tib yam li NUMDEVICES) yog tias koj rho tawm / * * /

Nco ntsoov rov sau cov cai yog tias koj hloov pauv.

Pom zoo: