Cov txheej txheem:

Kev Ntsuas Kub thiab Vaum Siv Raspberry Pi: 6 Kauj Ruam (nrog Duab)
Kev Ntsuas Kub thiab Vaum Siv Raspberry Pi: 6 Kauj Ruam (nrog Duab)

Video: Kev Ntsuas Kub thiab Vaum Siv Raspberry Pi: 6 Kauj Ruam (nrog Duab)

Video: Kev Ntsuas Kub thiab Vaum Siv Raspberry Pi: 6 Kauj Ruam (nrog Duab)
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Hlis ntuj nqeg
Anonim
Kev Ntsuas Kub thiab Vaum Siv Raspberry Pi
Kev Ntsuas Kub thiab Vaum Siv Raspberry Pi
Kev Ntsuas Kub thiab Vaum Siv Raspberry Pi
Kev Ntsuas Kub thiab Vaum Siv Raspberry Pi

Lub caij ntuj sov los txog, thiab cov uas tsis muaj lub tshuab cua txias yuav tsum tau npaj los tswj huab cua sab hauv tsev. Hauv kab ntawv no, Kuv tab tom piav qhia txoj hauv kev niaj hnub los ntsuas qhov ntsuas tseem ceeb tshaj plaws rau tib neeg kev nplij siab: kub thiab av noo. Cov ntaub ntawv sau no raug xa mus rau huab thiab ua tiav nyob ntawd.

Kuv tab tom siv Raspberry Pi 1 board thiab DHT22 sensor. Koj tuaj yeem ua tib yam ntawm txhua lub khoos phis tawj uas muaj Internet, GPIO, thiab Python. Qhov pheej yig dua DHT11 sensor kuj ua haujlwm tau zoo.

Kauj Ruam 1: Npaj Kho Vajtse

Npaj Kho Vajtse
Npaj Kho Vajtse
Npaj Kho Vajtse
Npaj Kho Vajtse

Cia peb pib los ntawm qhov pib, vim tias kuv tsis tau siv kuv li Raspberry Pi ntev heev.

Peb yuav xav tau:

  • Raspberry Pi board (lossis lwm IoT-taw qhia platform).
  • SD lossis microSD daim npav (nyob ntawm lub platform).
  • 5V/1A ntawm micro-USB.
  • LAN cable, uas muab Internet txuas.
  • HDMI zaub, RCA zaub, lossis UART chaw nres nkoj (kom qhib SSH).

Thawj kauj ruam yog rub Raspbian. Kuv tau xaiv qhov Lite version, raws li kuv yuav siv SSH hloov ntawm cov khoom. Cov khoom tau hloov pauv txij li lub sijhawm dhau los kuv tau ua nws: tam sim no muaj qhov zoo kawg nkaus hlawv software hu ua Etcher, uas ua haujlwm zoo kawg nkaus, thiab muaj qhov tsim tau zoo nkauj.

Tom qab cov duab hlawv tau ua tiav, Kuv tso daim npav SD rau hauv kuv tus Pi, ntsaws LAN thiab txuas hluav taws xob rau hauv, thiab tom qab ib ntus, kuv lub router sau npe lub cuab yeej tshiab.

Kauj ruam 2: Pab kom SSH

Pab kom SSH
Pab kom SSH
Pab kom SSH
Pab kom SSH
Pab kom SSH
Pab kom SSH

SSH yog neeg xiam los ntawm lub neej ntawd. Kuv tuaj yeem siv UART-USB hloov pauv lossis tsuas yog txuas cov khoom siv kom pom lub plhaub thiab pab SSH.

Tom qab rov pib dua, Kuv kawg hauv. Thawj yam ua ntej, cia hloov tshiab:

sudo apt hloov tshiab && sudo apt hloov tshiab -y

Tam sim no cia peb txuas cov cuab yeej tshiab no mus rau Huab.

Kauj Ruam 3: Txhim Kho Cloud4RPi

Txhim kho Cloud4RPi
Txhim kho Cloud4RPi

Kuv txiav txim siab sim huab huab hu ua Cloud4RPi, uas yog tsim los rau IoT.

Raws li cov ntaub ntawv, peb xav tau cov pob hauv qab no kom nws ua haujlwm:

sudo apt nruab git python nab hab sej -pip -y

Cov tsev qiv ntawv cov neeg siv khoom tuaj yeem teeb tsa hauv ib qho lus txib:

sudo pip nruab cloud4rpi

Tam sim no peb xav tau qee qhov qauv piv txwv kom ntseeg tau tias nws ua haujlwm.

git clone https://github.com/cloud4rpi/cloud4rpi-raspberrypi-python && cd cloud4rpi-raspberrypi-python git clone https://gist.github.com/f8327a1ef09ceb1ef142fa68701270de.git e && mv e/minimal.py minimal.py && rmdir -re

Kuv txiav txim siab los khiav minimal.py, tab sis kuv tsis nyiam cov ntaub ntawv cuav. Luckily, Kuv pom txoj hauv kev yooj yim los ua cov ntaub ntawv kuaj mob tiag hauv qhov piv txwv no.

los ntawm rpi ntshuam *

Tom qab ntawd tshem tawm cov haujlwm no uas muab cov ntaub ntawv cuav (rpi.py piav qhia lawv tam sim no):

def cpu_temp (): ua

rov qab 70 def ip_address (): rov qab '8.8.8.8' def host_name (): rov qab 'hostname' def os_name (): rov qab 'osx'

Tam sim no peb xav tau tus cim, uas tso cai rau Cloud4RPi txuas cov cuab yeej nrog tus as khauj. Txhawm rau kom tau ib qho, tsim ib tus as khauj ntawm cloud4rpi.io thiab ntaus tus Ntaus Tshiab khawm ntawm nplooj ntawv no. Hloov _YOUR_DEVICE_TOKEN_ txoj hlua hauv cov ntaub ntawv minimal.py nrog koj lub cuab yeej lub cim thiab khaws cov ntawv. Tam sim no peb tau npaj rau thawj qhov kev tshaj tawm.

nab hab sej minimal.py

Qhib lub cuab yeej nplooj ntawv thiab tshawb xyuas tias cov ntaub ntawv nyob ntawd.

Tam sim no cia peb txav mus rau cov ntaub ntawv ntawm lub ntiaj teb tiag.

Kauj ruam 4: Txuas lub Sensor

Txuas lub Sensor
Txuas lub Sensor

Peb yuav xav tau:

  • DHT22 lossis DHT11 humidity sensor
  • Rub-up resistor (5-10 KΩ)
  • Hlau

DHT22 sensor ntsuas kub thiab av noo ib txhij. Cov txheej txheem kev sib txuas lus tsis yog tus qauv, yog li peb tsis tas yuav ua kom nws nyob hauv raspi -teeb tsa - tus lej GPIO yooj yim ntau dua li txaus.

Txhawm rau kom tau txais cov ntaub ntawv, Kuv yuav siv Adafruit lub tsev qiv ntawv zoo rau DHT sensors, tab sis nws yuav tsis ua haujlwm zoo li qub. Kuv ib zaug pom qhov txawv txav tsis tu ncua hauv cov cai, uas tsis ua haujlwm rau kuv kho vajtse, thiab tom qab ob xyoos kuv qhov kev thov rub tawm tseem tseem tos. Kuv kuj tseem tau hloov pauv lub rooj saib xyuas qhov ruaj khov vim tias kuv Raspberry Pi 1 nrog BCM2835 tau ceeb pom tias yog Raspberry Pi 3. Kuv xav tias nws muaj tseeb… Yog li, kuv pom zoo siv kuv rab diav rawg. Yog tias koj ntsib teeb meem nrog nws, thov sim thawj qhov chaw cia khoom, tej zaum nws ua haujlwm rau qee leej, tab sis kuv tsis yog ib tus ntawm lawv.

git clone https://github.com/Himura2la/Adafruit_Python_DHT…. Adafruit_Python_DHT

Raws li lub tsev qiv ntawv tau sau hauv C, nws yuav tsum tau muab tso ua ke, yog li koj xav tau cov pob tsim-qhov tseem ceeb thiab sej-dev.

sudo apt install build-essential python-dev -ysudo python setup.py nruab

Thaum cov pob tau teeb tsa, txuas DHT22 raws li qhia hauv daim duab.

Thiab sim nws:

cd ~ nab hab sej -c "ntshuam Adafruit_DHT li d; luam d.read_retry (d. DHT22, 4)"

Yog tias koj pom qee yam zoo li (39.20000076293945, 22.600000381469727), koj yuav tsum paub tias qhov no yog cov av noo hauv feem pua thiab kub hauv Celsius.

Tam sim no, cia txhua yam ua ke!

Kauj Ruam 5: Xa Kev Nyeem Sensor mus rau Huab

Xa Cov Ntawv Nyeem Sensor mus rau Huab
Xa Cov Ntawv Nyeem Sensor mus rau Huab

Kuv yuav siv qhov tsawg.py ua lub hauv paus thiab ntxiv DHT22 kev cuam tshuam rau hauv nws.

cd cloud4rpi-raspberrypi-nab hab sej

cp minimal.py ~/cloud_dht22.py cp rpi.py ~/rpi.py cd vi cloud_dht22.py

Raws li DHT22 xa rov qab ob qho tib si kub thiab av noo hauv ib zaug hu, Kuv khaws lawv thoob ntiaj teb thiab hloov kho ib zaug hauv qhov kev thov, xav tias ncua sijhawm ntawm lawv ntau dua 10 vib nas this. Xav txog cov cai hauv qab no, uas tau txais DHT22 cov ntaub ntawv:

ntshuam Adafruit_DHT

temp, hum = Tsis muaj, Tsis muaj last_update = time.time () - 20 def update_data (): ntiaj teb kawg_update, hum, temp yog time.time () - last_update> 10: hum, temp = Adafruit_DHT.read_retry (Adafruit_DHT. DHT22, 4) last_update = time.time () def get_t (): hloov tshiab_data () rov puag ncig (temp, 2) yog temp tsis yog Tsis muaj Ib qho ntxiv Tsis muaj def get_h (): hloov tshiab_data () rov puag ncig (hum, 2) yog hum tsis yog Tsis muaj lwm tus Tsis muaj

Ntxig cov cai no tom qab cov khoom siv uas twb muaj lawm thiab hloov kho qhov hloov pauv kom nws siv cov haujlwm tshiab:

variables = {

'DHT22 Temp': {'type': 'numeric', 'bind': get_t}, 'DHT22 Humidity': {'type': 'numeric', 'bind': get_h}, 'CPU Temp': {'type ':' lej ',' khi ': cpu_temp}}

Nias lub pob liab kom pib hloov cov ntaub ntawv:

nab hab sej cloud_dht22.py

Tom qab ntawd koj tuaj yeem tshawb xyuas nplooj ntawv ntaus ntawv.

Koj tuaj yeem tso nws zoo li yog, tab sis kuv nyiam muaj kev pabcuam rau txhua yam. Qhov no ua kom ntseeg tau tias tsab ntawv yeej ib txwm ua haujlwm. Tsim kev pabcuam nrog cov ntawv sau ua haujlwm tsis siv neeg:

wget -O https://github.com/cloud4rpi/cloud4rpi-raspberrypi-python/blob/master/service_install.sh | sudo bash -s cloud_dht22.py

Pib qhov kev pabcuam:

sudo kev pabcuam cloud4rpi pib

Thiab xyuas nws:

pi@raspberrypi: ~ $ sudo service cloud4rpi xwm txheej -l

● cloud4rpi.service-Cloud4RPi daemon Loaded: loaded (/lib/systemd/system/cloud4rpi.service; enabled) Active: nquag (khiav) txij hnub Wednesday 2017-05-17 20:22:48 UTC; 1 feeb dhau los Lub ntsiab PID: 560 (nab nab) CGroup: /system.slice/cloud4rpi.service └─560/usr/bin/python /home/pi/cloud_dht22.pyMay 17 20:22:51 raspberrypi nab hab sej [560]: Tshaj tawm iot -hub/messages: {'type': 'config', 'ts': '2017-05-17T20… y'}]} May 17 20:22:53 raspberrypi nab hab sej [560]: Tshaj tawm iot-hub/lus: {'type': 'data', 'ts': '2017-05-17T20: 2… 40'}} May 17 20:22:53 raspberrypi nab hab sej [560]: Tshaj tawm iot-hub/lus: {'hom': 'system', 'ts': '2017-05-17T20….4'}}

Yog tias txhua yam ua haujlwm raws li qhov xav tau, peb tuaj yeem mus txuas ntxiv thiab siv Cloud4RPi lub peev xwm los tswj hwm nrog cov ntaub ntawv.

Kauj Ruam 6: Daim duab thiab Tswb

Daim ntawv thiab Tswb
Daim ntawv thiab Tswb
Daim ntawv thiab Tswb
Daim ntawv thiab Tswb
Daim ntawv thiab Tswb
Daim ntawv thiab Tswb

Ua ntej tshaj plaws, cia cov phiaj xwm sib txawv los saib seb lawv hloov pauv li cas. Qhov no tuaj yeem ua tiav los ntawm kev ntxiv Cov Tswj Vaj Huam Sib Luag tshiab thiab tso cov kab ntawv xav tau hauv nws.

Lwm qhov uas peb tuaj yeem ua ntawm no yog teeb tsa Kev Ceeb Toom. Cov yam ntxwv no ua rau koj teeb tsa thaj tsam nyab xeeb rau qhov sib txawv. Sai li qhov ntau tau hla dhau, nws xa email ceeb toom. Ntawm Tswj Vaj Huam Sib Luag kho nplooj ntawv, koj tuaj yeem hloov mus rau Alerts thiab teeb tsa ib qho.

Txoj cai tom qab ntawd, cov av noo hauv kuv chav pib poob sai yam tsis muaj laj thawj pom, thiab lub tswb nrov tom qab ntawd.

Koj tuaj yeem siv Cloud4RPi dawb nrog txhua yam khoom siv uas muaj peev xwm ua rau Python. As rau kuv, tam sim no kuv ib txwm paub thaum twg yuav tsum qhib lub tshuab cua txias, thiab kuv tseem tuaj yeem txuas nws mus rau kev xa tawm rau kev tswj chaw taws teeb ntawm Cloud4RPi. Kuv npaj rau qhov sov! Txais tos, Lub caij ntuj sov!

Pom zoo: