Cov txheej txheem:

Yuav Ua Li Cas Kom Ntsuas Dej Ntshav Pom Kev Tswb Siv Raspberry Pi thiab Particle Argon: 6 Kauj Ruam
Yuav Ua Li Cas Kom Ntsuas Dej Ntshav Pom Kev Tswb Siv Raspberry Pi thiab Particle Argon: 6 Kauj Ruam
Anonim
Image
Image
Yuav Ua Li Cas Kom Ntsuas Dej Ntshav Dej Ruaj Ntseg Siv Raspberry Pi thiab Particle Argon
Yuav Ua Li Cas Kom Ntsuas Dej Ntshav Dej Ruaj Ntseg Siv Raspberry Pi thiab Particle Argon

Muaj cov qauv ntsuas dej nyab yog qhov zoo los tiv thaiv kev puas tsuaj loj rau koj lub tsev lossis chaw ua haujlwm.

Tab sis nws ua rau nyuaj yog tias koj tsis nyob hauv tsev tuaj koom lub tswb.

Tau kawg koj tuaj yeem yuav cov ntse

Lub tswb ceeb toom dej nyab no txheeb xyuas cov kua thiab ua rau lub tswb nrov thiab hloov kho lub vev xaib txog dej nyab uas tuaj yeem nkag mus tau rau txhua qhov chaw hauv ntiaj teb no, txawm tias koj tab tom so so lossis tsuas yog tom haujlwm thiab koj xav paub txog koj lub tsev li cas.

Khoom siv

Raspberry pi (Kuv siv tus qauv 3 B+) khiav raspbian

Particle Argon

Grove Dej Sensor

Raspi Lub Koob Yees Duab

Buzzer

Jumper xov hlau

Kauj Ruam 1: Txuas Dej Sensor mus rau Particle

Txuas Dej Sensor mus rau Particle
Txuas Dej Sensor mus rau Particle
Txuas Dej Sensor mus rau Particle
Txuas Dej Sensor mus rau Particle

dej ntsuas muaj 4 tus pin, uas yog GND, VCC, NC thiab SIG thiab peb yuav siv tsuas yog peb ntawm lawv

Kuv txuas SIG tus pin rau D2 ntawm Argon.

Tam sim no, koj tuaj yeem tso Particle Web IDE los sau cov cai thiab nyem rau Argon

Yog li peb tau sau npe Particle muaj nuj nqi ua kua thiab piav qhia qhov sib txawv isFloodPresent, uas tuaj yeem hu los ntawm Particle Console thiab tau txais tus nqi boolean ntawm isFloodPresent thiab tseem hu ua kua rau kev sim thuam uas siv tus nqi 1 uas yog txhais tau tias muaj tseeb rau dej nyab (dej) tam sim no.

xyuas kom tseeb tias koj tuaj yeem pom qhov ua haujlwm thiab hloov pauv tau los ntawm Particle Console ntawm koj li Particle Device.

Kauj ruam 2: Txuas Tswb Qhov Chaw rau Raspberry

Txuas Alarm Source rau Raspberry
Txuas Alarm Source rau Raspberry

Ntawm daim ntawv qhia zaub mov koj tuaj yeem txuas Buzzer rau Raspberry's GPIO tus pin

Kuv tau txuas me me kawg ntawm buzzer rau GND (PIN 6) thiab ntev kawg rau tus pin 7 ntawm raspberry.

Tam sim no khiav cov cai kom pom. Peb yuav xav tau cov ntaub ntawv nab hab sej ua haujlwm txhua lub sijhawm yog li nws tuaj yeem tau txais cov txiaj ntsig los ntawm lub vev xaib thiab teb raws li.

Xwb, koj tuaj yeem khiav cov ntawv no ntawm kev pib ntawm koj lub raspberry uas koj tuaj yeem ua los ntawm kev kho /etc /systemd

thiab cov ntawv no yuav muab tso rau hauv cgi nplaub tshev ntawm koj lub server apache, Kuv tau ua cov npe tshiab dej nyab-cgi sab hauv/var/www/html/thiab muab cov ntawv no.py uas yuav sib tham nrog kuv tsab ntawv cgi

Kauj ruam 3: Configure Apache Server

Configure Apache Server
Configure Apache Server

koj tuaj yeem nruab apache server los ntawm kev sau sudo apt-tau nruab apache2

thaum nws tau teeb tsa, koj tuaj yeem txheeb xyuas los ntawm kev ntaus hostname -I

thiab koj yuav tau txais koj tus IP chaw nyob thiab koj tuaj yeem nkag mus rau koj tus browser thiab yuav tsum pom server khiav

Kauj Ruam 4: Pab CGI ntawm Apache

Pab kom CGI ntawm Apache
Pab kom CGI ntawm Apache

koj tuaj yeem pab cgi los ntawm kev sau sudo a2enmod cgi

Los ntawm Default cgi_bin ntawm apache nyob hauv/usr/lib/cgi-bin

qhov no yog qhov uas koj tuaj yeem tso koj cov ntawv cgi tom qab ua kom cgi

kom ua tau zoo, koj yuav tsum rov pib dua apache server

Kuv xav tau cov npe kev cai rau kuv cov ntawv cgi yog li kuv tsim cov npe hauv/var/www/html/hu ua dej nyab-cgi

kom pab tau phau ntawv no kuv yuav tsum ua cov ntaub ntawv conf los ntawm kev ntaus ntawv

sudo nano /etc/apache2/conf-available/flood-cgi.conf

thiab ntxiv cov lus txib raws li qhia hauv screenshot

tom qab ntawd qhib cov npe no los ntawm kev ntaus ntawv

var/www/html $ sudo a2enconf dej nyab-cgi

tam sim no koj tuaj yeem rov pib dua koj lub apache server dua thiab tag nrho cgi los ntawm daim nplaub tshev no yuav nyeem tau los ntawm apache tom qab kev tso cai.

Kauj Ruam 5: Teeb Web Page

Teeb Web Page
Teeb Web Page

Rau qhov kev pabcuam web yooj yim no, Kuv siv HTML, Javascript, CSS, jquery thiab ajax.

Kuv muaj tsib daim ntawv tswj hwm uas tuaj yeem nyem tau, Hauv qhov xwm txheej thaum thaij duab tau nyem los ntawm nplooj ntawv web, nws yuav ua rau lub pob nyem khawm nyem ua haujlwm thiab cov haujlwm no zoo li qhov no

$ ("#photobutton"). nyem (ua haujlwm () {var floodDate = Hnub Tshiab ();

var floodImageName = "Flood_IMG_" + floodDate.toLocaleTimeString ();

$.ajax ({

url: 'dej nyab-cgi/flood_cgi.py', txoj kev: 'post', cov ntaub ntawv: {name_for_image: floodImageName}, kev vam meej: muaj nuj nqi (cov ntaub ntawv) {

ceeb toom (cov ntaub ntawv, xwm txheej)

$ ("#picpic"). attr ("src", "flood-cgi/" + floodImageName + ".jpg");

}

})

});

qhov no yuav hu rau tsab ntawv flood_cgi.py los yees duab thiab khaws cov duab nrog cov npe kev cai tsim los ntawm hnub tim thiab sijhawm tam sim no thiab ajax thauj khoom mus rau nplooj ntawv.

hauv qhov xwm txheej Tswb, peb tuaj yeem siv txoj haujlwm no

muaj nuj nqi callAlarm (alarmType) {

$.ajax ({

url: 'dej nyab-cgi/tswb.cgi', txoj kev: 'post', cov ntaub ntawv: {alarm_type: alarmType}, kev vam meej: muaj nuj nqi (cov ntaub ntawv) {ceeb toom (cov ntaub ntawv)

}, yuam kev: muaj nuj nqi (XMLHttpRequest, textStatus, throwError) {ceeb toom (povError)}});

}

muaj nuj nqi callAlarm yuav raug hu thaum buzzer daim ntawv tau nyem, $ ("#buzzer"). nyem (ua haujlwm () {callAlarm ("test");

})

hauv qab tus lej yog thaum koj xav nyem nyem dej nyab piv txwv li hu rau Particle API thiab hu rau kev ua haujlwm thiab hloov pauv tus nqi kua 1 thiab tshuaj xyuas lub kaw lus yog tias tag nrho ua haujlwm raws li qhov xav tau los ntawm kev ua ib qho kev sib tw dej nyab

$ ("#mockFlood"). nyem (ua haujlwm () {console.log ("thuam dej nyab tau thov");

var floodVal = 1;

$ ("#signal2"). css ("font-size", "me");

var varName = "isFloodPresent";

var deviceID = "Koj li cuab yeej ID";

var accessToken = "KOJ ACCESS TOKEN";

yog (floodVal) {

$.post ("https://api.particle.io/v1/devices/" + deviceID + "/kua? access_token =" + accessToken, {kua: floodVal}, muaj nuj nqi (cov ntaub ntawv, xwm txheej) {

yog (xwm txheej == "kev vam meej") {

ceeb toom ("Mock Flood tau ua !!!");

lwm yam {

ceeb toom ("Thov txim, muaj teeb meem");

}

});

}

});

Cov no yog lub luag haujlwm tseem ceeb uas koj xav tau txhawm rau txuas nrog Particle Api thiab koj cov txiv pos nphuab yog li koj cov raspberry pi thiab cov khoom me me Argon tuaj yeem sib txuas lus.

ceeb toom: Kuv xav upload tag nrho cov cai, tab sis nws tsis tso cai rau kuv upload.html ntawv

Kauj Ruam 6: Tsim Tsab Ntawv rau Raspi Lub Koob Yees Duab

peb tab tom tsim qhov yooj yim.py txhawm rau ntes cov duab thiab uas yuav muaj cov lus piav qhia ntawm hnub thiab sijhawm tam sim no ntawm nws.

tom qab ntawd peb yuav tsim cgi tsab ntawv flood_cgi.py yog li nws yuav raug hu los ntawm lub vev xaib thiab qhov no yuav hais kom.py cov ntawv los yees duab.

nco ntsoov pib cgi tsab ntawv nrog #! /usr/bin/env nab hab sej

thiab tseem muab kev tso cai apache los khiav cov ntaub ntawv no.

apache server khiav ntawm tus neeg siv www-cov ntaub ntawv yog li thaum peb tsim cov.py lossis.cgi ntawv, apache xav tau los ua tus tswv ntawm cov ntawv

sudo chown pi: www-cov ntaub ntawv dej nyab-cgi.py

thiab muab kev tso cai rau txim

sudo chmod a+x dej nyab -cgi.py

koj yuav tsum ua qhov no rau txhua cov ntaub ntawv uas xav tau los ntawm apache server.

NCO TSEG: nthuav tawm koj cov raspberry rau hauv internet thiab muab tag nrho cov kev tso cai no ua rau koj raspberry muaj kev phom sij rau kev nyab xeeb yog li cov neeg siv nruj thiab tso cai yuav tsum tau ua raws thiab teeb tsa firewall zoo li tsis yooj yim firewall (ufw)

Pom zoo: