Cov txheej txheem:
- Khoom siv
- Kauj Ruam 1: Sib dhos Cov Khoos Phis Tawj
- Kauj ruam 2: Xyuas kom tseeb tias koj tus Pi txuas nrog Is Taws Nem
- Kauj Ruam 3: Teeb Lub Koob Yees Duab
- Kauj Ruam 4: Nruab Flask
- Kauj Ruam 5: Tsim Chav Kawm Ntawv
- Kauj Ruam 6: Tsim lub raj mis Template
- Kauj Ruam 7: Muab Tus Qauv
- Kauj Ruam 8: Tsim Lub Koob Yees Duab Chav Kawm
- Kauj Ruam 9: Tsim Cov Qauv Sau
- Kauj ruam 10: Pib Server
- Kauj ruam 11: Sim nws tawm
Video: Raspberry Pi Security Camera: 11 Kauj Ruam (nrog Duab)
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:25
Nov yog cov lus qhia ib qib zuj zus qhia yuav ua li cas thiaj tsim tau IoT, lub zog ua kom lub koob yees duab ruaj ntseg siv Raspberry Pi. Koj yuav kawm paub yuav tsim lub tshuab raj lub vev xaib li cas thiab daim ntawv uas tso cai rau tus neeg siv kho lub koob yees duab kom nkag siab thiab lub sijhawm kaw, ua haujlwm pib/nres kaw, thiab/lossis thaij duab uas yuav raug khaws cia rau hauv zos.
Khoom siv
- Raspberry Pi 3
- Pi lub koob yees duab
- PIR tsab ntawv tsa suab sensor
- SD daim npav
- Lub hwj chim
Kauj Ruam 1: Sib dhos Cov Khoos Phis Tawj
Thaum Pi raug tua, ntxig daim npav micro-SD rau hauv Pi. Ntxig lub koob yees duab module ribbon cable rau hauv lub koob yees duab module chaw nres nkoj ntawm Pi. Tom qab ntawd, txuas 3 tus pin (sau VCC, OUT, thiab GND) ntawm PRI lub suab ntsuas mus rau Pi's GPIO pins. Txuas VCC mus rau 5.5V ntawm lub zog, GND rau hauv av, thiab OUT txhawm rau pin 11 ntawm Pi.
Kauj ruam 2: Xyuas kom tseeb tias koj tus Pi txuas nrog Is Taws Nem
Tam sim no, qhib Pi los ntawm kev txuas nws mus rau lub hwj chim thiab txheeb xyuas tias koj tau txuas nrog internet siv cov lus txib ping. Yog tias koj tsis paub yuav txuas koj Pi li cas rau hauv internet, nyem qhov no.
sudo ping www.google.com
Yog tias koj ua tiav, koj yuav tsum pom tias cov ntaub ntawv tau txais los ntawm google.
Ib qho ntxiv, koj tuaj yeem siv ifconfig kom pom koj tus IP chaw nyob.
sudo ifconfig
Kauj Ruam 3: Teeb Lub Koob Yees Duab
Siv cov lus txib hauv qab no los qhib lub teeb tsa kev teeb tsa, thiab ua kom lub koob yees duab nyob hauv "kev xaiv cuam tshuam".
sudo raspi-teeb tsa
Tom qab rov pib dua, koj tuaj yeem tso saib cov xwm txheej ntawm koj lub koob yees duab kom ntseeg tau tias nws tau txuas nrog kom raug.
vcgencmd get_camera
Thaum kawg, teeb tsa lub picamera module.
pip nruab picamera
Kauj Ruam 4: Nruab Flask
Nruab ib lub raj mis thiab lub raj mis-so tus qauv rau Python:
sudo apt-tau nruab python-dev python-pip
nab hab sej -m pip teeb tsa lub raj mis -so kom txaus
Tom ntej no, peb yuav teeb tsa tus nab npawb nab raj mis siv rau tsim cov ntawv.
pip nruab flask-wtf
Kauj Ruam 5: Tsim Chav Kawm Ntawv
Ua cov npe hu ua iotProject khaws tag nrho koj cov ntaub ntawv hauv.
sudo mkdir iotProject
Tsim cov ntaub ntawv nab npawb npe "camControl.py".
sudo nano camControl.py
Hauv cov ntawv no peb yuav tsim peb chav kawm ntawv, uas tso cai rau peb los tsim lub vev xaib nrog cov ntawv ntawv thiab cov ntawv qhia zaub mov nco rau tus neeg siv kom tuaj yeem hloov pauv lub koob yees duab teeb tsa, pib ua/nres kaw, thiab ntes cov vis dis aus.
los ntawm flask_wtf ntshuam FlaskFormfrom wtforms.validators ntshuam Cov Ntaub Ntawv Xav tau los ntawm wtforms ntshuam SubmitField los ntawm wtforms ntshuam validators, IntegerField, BooleanField, SelectField
chav kawm camFrame (FlaskForm):
videoDuration = IntegerField ('Teev Sijhawm Teev Npe (vib nas this)')
rhiab heev = IntegerField ('Motion Sensitivity (thaj tsam 2500-10000) n Tus lej siab dua, lub koob yees duab tsis zoo dua yog', validators = [validators. NumberRange (min = 2500, max = 10000, message = 'Tus Nqi Tawm Ntawm Qhov Ntau')])
options = SelectField ('Options', options = [('none', 'No action'), ('rec', 'Start Recording'), ('stop', 'Stop Recording'), ('pic', 'Siv Duab')])
xa = SubmitField ('Xa')
Kauj Ruam 6: Tsim lub raj mis Template
Txhawm rau tsim cov neeg siv kev sib tham, koj yuav tsum tsim Flask template uas siv daim ntawv uas koj nyuam qhuav tsim. Cov ntaub ntawv no yuav raug sau ua html, thiab khaws cia rau hauv daim nplaub tshev hu ua qauv, uas yuav tsum muaj nyob hauv cov npe tib yam li koj daim ntawv.
Sab hauv ntawm koj cov ntawv tais ceev tseg, tsim cov ntawv hu ua index.html. Hauv cov ntawv no, rov ua dua cov cai uas tau hais los saum no.
Kauj Ruam 7: Muab Tus Qauv
Tam sim no nws yog lub sijhawm los tsim cov ntawv uas ua rau tus qauv. Tsim cov ntaub ntawv npe appCam.py (nco ntsoov tias koj tsis nyob hauv cov ntawv tais ceev tseg lawm). Txhua cov ntsiab lus hloov pauv siv hauv tus qauv yuav tsum raug siv ua lub npe sib cav hauv kev hu mus rau render_template ().
ntshuam camControlfrom flask ntshuam Flask, render_template, thov, Teb los ntawm flask_restful ntshuam peev txheej, Api, reqparse
app = Flask (_ npe_)
app.config ['SECRET_KEY'] = '13542' api = Api (app)
parser = reqparse. RequestParser ()
parser.add_argument ('dur', type = int, help = 'Duration ntawm cov vis dis aus thaum pom lub zog') parser.add_argument ('sens', type = int, help = 'Theem ntawm kev txav mus los kom ua kom kaw') parser.add_argument ('opt', type = str, help = 'Manually record a video or capture an image')
Hloov kho chav kawm (Cov peev txheej):
#Cov khoom rau wtforms def post (tus kheej): args = parser.parse_args () #rc.input (args ['dur'], args ['sens'], args ['opt']) #sau rau cov ntawv ntawv uas tham nrog lub koob yees duab khiav hauv lub koob yees duab parallelSettingsFile = qhib ("cameraSettings.txt", 'w') cameraSettingsFile.write (args ['dur'] + '\ n') #wur dur cameraSettingsFile.write (args ['hnov'] + '\ n') #write sens cameraSettingsFile.write (args ['opt'] + '\ n') #write opt cameraSettingsFile.close () rov qab {'dur': args ['dur'], 'sens': args ['kev nkag siab'], 'xaiv': args ['xaiv']}
@app.route ('/', cov hau kev = ['GET', 'POST'])
def index (): "" "Tus tswj lub vev xaib" "" form = camControl.camFrame () #this yog daim ntawv thov yog thov.method == 'POST': print (request.form) args = [i rau kuv hauv kev thov.form.items ()] #rc.input (int (args [0] [1]), int (args [1] [1]), args [2] [1]) cameraSettingsFile = qhib ("cameraSettings.txt ", 'w') cameraSettingsFile.write (args [0] [1] + '\ n') #write dur cameraSettingsFile.write (args [1] [1] + '\ n') #write sens cameraSettingsFile.write (args [2] [1] + '\ n') #write opt cameraSettingsFile.close () imageDictionary = {"filename": "image.jpg"} return render_template ('index.html', form = form, image = imageDictionary)
api.add_resource (Hloov tshiab, '/hloov tshiab/')
yog _name_ == '_main_':
app.run (host = '0.0.0.0', chaw nres nkoj = 80, debug = Tseeb, threaded = Tseeb)
Kauj Ruam 8: Tsim Lub Koob Yees Duab Chav Kawm
Tam sim no peb xav tsim cov ntaub ntawv hu ua camOperator.py. Hauv nws peb yuav ua chav kawm lub koob yees duab nrog cov txheej txheem los tswj lub koob yees duab, siv cov haujlwm PiCamera uas twb muaj lawm. Peb yuav siv qhov piv txwv ntawm cov khoom no hauv cov kauj ruam tom ntej uas peb yuav ua ke ua haujlwm ntawm lub koob yees duab thiab lub suab txav.
Cov txheej txheem tau hais tseg hauv chav kawm no hloov pauv "cov ntaub ntawv" teeb tsa ntawm lub koob yees duab kev nyab xeeb siv qhov nkag siab thiab lub sijhawm nkag mus uas tus neeg siv muab, thaum tsim cov txiaj ntsig tsis raug rau cov kev hloov pauv no yog tias cov neeg siv tswv yim tsis tuaj.
ntshuam RPi. GPIO ua GPIOimport lub sij hawm ntshuam picamera los ntawm lub sijhawm ntshuam datetime
GPIO.setmode (GPIO. BOARD)
GPIO.setup (11, GPIO. IN)
ntes = 0
chav kawm lub koob yees duab
def _init _ (tus kheej):
#constructor self.cam = picamera. PiCamera () self.data = self.dur = 10 self.sens = 2500 self.opt = "tsis muaj"
def cov ntaub ntawv (tus kheej, dur):
#Records rau lub sijhawm muab los ntawm tus tswj videoName = str (datetime.now ()) videoName = videoName.replace (':', ') videoName = videoName.replace ('. ',') Self.cam.start_recording ('/home/pi/iotProject/videos/' + videoName + '.h264') time.sleep (dur) self.cam.stop_recording ()
def ua haujlwm (tus kheej, dur, sens):
#Kev ua haujlwm tseem ceeb ntawm lub koob yees duab uas tshawb xyuas tas li yog tias tib neeg nyob ze, yog tias tib neeg nyob ib puag ncig ntev txaus, peb pib kaw! thoob ntiaj teb pom kuv = GPIO.input (11) yog tias kuv == 0: #Thaum cov zis los ntawm lub suab sensor yog LOW pom = 0 lub sijhawm pw tsaug zog (0.1) elif i == 1: #Thaum cov zis los ntawm lub suab sensor yog HIGH luam tawm (" tsab ntawv tsa suab pom " +str (ntes)) yog tias pom> = sens*10: self.record (dur) print (" RECORDED ") ntes = 0 time.sleep (0.1) detect += 1
Kauj Ruam 9: Tsim Cov Qauv Sau
Qhov kev zov me nyuam kawg uas xav tau rau txoj haujlwm no yuav raug sau rau hauv cov ntawv hu ua rec.py. Cov ntaub ntawv no qhia lub koob yees duab thaum kaw, ntev npaum li cas kaw, thiab yog/thaum yuav thaij duab. Nws ua qhov no los ntawm kev tshuaj xyuas tas li thiab nyeem cov neeg siv cov ntaub ntawv sau rau hauv kab ntawv los ntawm qib 5. tus pi, xws li hauv.h264 lossis-j.webp
'' 'Ua haujlwm ua ke nrog cov neeg rau zaub mov flask, nyeem cov kev hloov pauv teeb tsa los ntawm cov ntawv server. Tus neeg rau zaub mov tswj kev hloov pauv tau teeb tsa hauv cov ntawv cais thaum xa cov ntawv. Tus lej module nyeem cov kev hloov pauv no thiab hloov kho lub koob yees duab raws lawv. '' 'ntshuam camOperator los ntawm lub sijhawm ntshuam datetime ntshuam sijhawm
rc = camOperator.cameraOperator ()
cameraSettingsFile = qhib ("cameraSettings.txt", 'w') cameraSettingsFile.close () #qhov no, peb qhib thiab kaw hauv kev sau hom txhawm rau tshem tawm cov ntsiab lus hauv cov ntawv ua ntej lub voj tseem ceeb khiav
#Lub voj txuas mus tas li uas saib xyuas seb tib neeg nyob ze. Yog lawv yog, ces
#lub koob yees duab pib kaw. Txoj haujlwm no khiav hauv paralell nrog lub hwj #server uas tswj lub koob yees duab no. recordingInProcess = Cuav thaum Muaj Tseeb: #kos/kaw yog (kawInProcess == Cuav): rc.operation (rc.dur, rc.sens) #hloov pauv cov chaw ntawm lub koob yees duab raws li server serverSettingsFile = qhib ("cameraSettings.txt", 'r') settingNum = 0 rau teeb tsa hauv lub koob yees duabSettingsFile.readlines (): yog teeb tsaNum == 0: #Duration hloov rc.dur = int (teeb tsa) elif settingNum == 1: #Sensitivity hloov rc.sens = int (teeb tsa) elif settingNum == 2: #Action hloov rc.opt = teeb tsa settingNum += 1 lub koob yees duabSettingsFile.close ()
#execute ib qho kev ua
# yog rc.opt == "tsis muaj": # txuas ntxiv yog rc.opt == "rec / n" thiab kawInProcess == Tsis tseeb: luam tawm ("Khiav cov lus txib los ntawm tus tswj") # Tsim lub npe rau video raws li lub sijhawm tam sim no videoName = "snappedVid _"+str (datetime.now ()) videoName = videoName.replace (':', ') videoName = videoName.replace ('. ',') rc.cam.start_recording ('/home/pi/iotProject /videos/' + videoName +'.h264 ') recordingInProcess = True elif rc.opt == "nres / n" thiab kawInProcess == Muaj tseeb: luam tawm ("Nres kaw cov lus txib los ntawm tus tswj") rc.cam.stop_recording () kawInProcess = Cuav cameraSettingsFile = qhib ("cameraSettings.txt", 'w') cameraSettingsFile.write (str (rc.dur)+'\ n') cameraSettingsFile.write (str (rc.sens)+'\ n') cameraSettingsFile. sau ("tsis muaj / n") rc.opt = "tsis muaj / n" elif rc.opt == "pic / n" thiab kawInProcess == Tsis tseeb: luam tawm ("Snap ib pic txib los ntawm tus tswj") pictureName = "snappedPic_ "+str (datetime.now ()) pictureName = pictureName.replace (':', ') pictureName = pictureName.replace ('. ',') rc.cam.st art_preview () time.sleep (5) rc.cam.capture ('duab/' + pictureName + '.jpg') rc.cam.stop_preview () cameraSettingsFile = qhib ("cameraSettings.txt", 'w') cameraSettingsFile. sau (str (rc.dur)+'\ n') cameraSettingsFile.write (str (rc.sens)+'\ n') cameraSettingsFile.write ("none / n") rc.opt = "tsis muaj / n"
Kauj ruam 10: Pib Server
SSH rau hauv pi thiab pib server siv cov kab hais kom ua saum toj no.
Kauj ruam 11: Sim nws tawm
Nkag mus rau lub vev xaib siv tus IP chaw nyob thiab koj yuav tsum muaj peev xwm tswj lub koob yees duab nyob deb!
Pom zoo:
Cov Duab Duab Duab thiab Cov Duab 1: 4 Cov Kauj Ruam (nrog Duab)
Cov Duab Duab Cubes thiab Cov Duab 1: Thaum sim nrog qee cov ntoo ntoo thiab cov duab los qhia, kuv pom ob peb txoj hauv kev los ua cov voos thiab lwm yam duab los ntawm cov khoom siv yooj yim. Los ntawm kev muab cov no los ua Cov Ntawv Qhia, Kuv vam tias yuav txhawb nqa kev ua si thiab kev kawm. Kev hloov pauv ntawm qhov kev qhia no
DIY Professional Open Source Night Vision Security Camera: 10 Kauj Ruam (nrog Duab)
DIY Professional Open Source Night Vision Security Camera: Hauv qhov kev qhia tshiab no, peb yuav ua ke ua peb lub Raspberry Pi qhib qhov vis dis aus lub koob yees duab.Yog, peb tab tom tham ntawm no txog qhov qhib qhov chaw sab nraum zoov lub koob yees duab, muaj peev xwm pom yav tsaus ntuj thiab pom kev pom, txhua qhov txuas nrog peb Jeed
Cov Duab Duab Duab Duab, WiFi Txuas - Raspberry Pi: 4 Cov Kauj Ruam (nrog Duab)
Cov Duab Duab Duab Duab, WiFi Txuas - Raspberry Pi: Nov yog txoj hauv kev yooj yim heev thiab tus nqi qis mus rau cov duab thav duab digital - nrog qhov zoo ntawm kev ntxiv /tshem cov duab hla WiFi ntawm 'nyem thiab luag' siv (pub dawb) xa cov ntaub ntawv . Nws tuaj yeem siv tau los ntawm qhov me me £ 4.50 Pi Zero. Koj tseem tuaj yeem hloov pauv
WoodThing IOT Security Camera: 8 Kauj Ruam (nrog Duab)
WoodThing IOT Lub Koob Yees Duab Ruaj Ntseg: Nov yog lub zog IP cam raws li Raspberry PI. Nws khiav motionEyeOS, yog li tuaj yeem siv los tswj ntau lub koob yees duab IP nyob deb nrog rau tso cai rau koj txuas mus txog plaub qhov nqi qis USB web cams ntxiv. Nta: USB powered, suab paub nrog s
Tsab ntawv tsa suab qhib Security Security Yard Kos Npe: 4 Cov Kauj Ruam (nrog Duab)
Motion Activated Security Yard Sign: Tsoos kev nyab xeeb kev nyab xeeb hauv tsev cov cim tsis ua dab tsi. Qhov tseeb lawv tsis tau hloov pauv ntau dua 30 xyoo dhau los. Txawm li cas los xij, lawv yog qhov muaj txiaj ntsig tiv thaiv tsuav lawv tso rau hauv qhov chaw pom tau zoo hauv koj lub vaj thiab saib zoo. Kuv hlub