Cov txheej txheem:

DIY Tsev Saib Xyuas Nrog RaspberryPi thiab Cloud4Rpi: 5 Kauj Ruam
DIY Tsev Saib Xyuas Nrog RaspberryPi thiab Cloud4Rpi: 5 Kauj Ruam

Video: DIY Tsev Saib Xyuas Nrog RaspberryPi thiab Cloud4Rpi: 5 Kauj Ruam

Video: DIY Tsev Saib Xyuas Nrog RaspberryPi thiab Cloud4Rpi: 5 Kauj Ruam
Video: Часы G-Shock до 250 долларов-15 лучших часов Casio G до 250 доллар... 2024, Hlis ntuj nqeg
Anonim
DIY Tsev Saib Xyuas Nrog RaspberryPi thiab Cloud4Rpi
DIY Tsev Saib Xyuas Nrog RaspberryPi thiab Cloud4Rpi

Ib lub caij ntuj no kuv tau mus rau kuv lub tsev lub tsev, thiab pom tias nws txias heev nyob ntawd. Qee yam tau tshwm sim nrog hluav taws xob thiab RCD lub tshuab hluav taws xob tau hloov nws, thiab cua sov tau dhau lawm. Kuv muaj hmoo kuv tuaj rau ntawd, txwv tsis pub ob peb hnub txhua yam yuav tau khov uas yog qhov phem heev rau cov kav dej thiab cov tshuab hluav taws xob.

Kuv muaj ntau lub Raspberry Pi nyob ib puag ncig, thiab lub ntsuas cua sov, yog li kuv xav - vim li cas kuv thiaj tsis ua qhov ntsuas yooj yim? Cov lus qhia hauv qab no xav tias koj muaj Raspberry Pi nrog Raspbian thiab teeb tsa kev sib txuas network. Hauv kuv qhov xwm txheej nws yog Raspberry Pi B+ nrog Raspbian (2018-06-27-raspbian-stretch-lite).

Kauj Ruam 1: Kev Ntsuas Kub

Kev Ntsuas Kub
Kev Ntsuas Kub
Kev Ntsuas Kub
Kev Ntsuas Kub

Yuav ua li cas txuas DS18B20 qhov ntsuas kub? Tsuas yog google yuav ua li cas, thiab koj yuav pom ntau cov duab zoo li qhov no:

Hauv kuv qhov xwm txheej kuv muaj cov xov dub, daj thiab liab. Cov xim dub yog av, mus rau hauv av pin, liab yog lub zog - mus rau 3.3v tus pin, thiab daj yog cov ntaub ntawv - yuav tsum mus rau GPIO4 tus pin, nrog 4.7 kOm resistor txuas nrog cov ntaub ntawv thiab lub zog. Note, koj tuaj yeem txuas ob peb lub ntsuas cua ua ke (lawv yog digital, thiab muaj qhov chaw sib txawv), koj xav tau tsuas yog ib tus neeg tawm tsam. Tom qab txuas koj lub sensor, koj yuav tsum pab kom 1Wire hauv raspi-teeb tsa:

sudo raspi-teeb tsa

Mus rau 5 Qhov kev xaiv cuam tshuam, pab P7 1-Hlau thiab rov pib dua.

Tom qab ntawd koj tuaj yeem sim yog tias koj tuaj yeem pom lub sensor:

sudo modprobe w1-gpiosudo modprobe w1-thermls/sys/npav/w1/khoom siv/

Koj yuav tsum pom qee yam zoo li no:

pi@vcontrol: ~ $ ls/sys/bus/w1/devices/28–00044eae2dff w1_bus_master1

28–00044eae2dff yog peb qhov ntsuas kub.

Kho vajtse yog npaj txhij. Tam sim no kuv yuav tsum teeb tsa ntu saib xyuas. Kuv xav tau qee yam uas yuav qhia kuv cov ntaub ntawv thiab ceeb toom rau kuv yog tias lub cuab yeej raug kaw ib ntus lossis tsis muaj lub zog, lossis qhov ntsuas kub tsawg. Pom tseeb qhov no tsis tuaj yeem yog raspberry pi nws tus kheej, yuav tsum muaj qee tus neeg rau zaub mov lossis kev pabcuam hauv internet uas saib xyuas kuv lub cuab yeej.

Kuv tuaj yeem tsim tus neeg rau zaub mov yooj yim, tau txais hosting thiab teeb tsa txhua yam, tab sis honely, Kuv tsis xav tau. Hmoov zoo, qee leej tau xav txog qhov no twb tau tsim thiab tsim cloud4rpi.io - huab tswj vaj huam sib luag rau koj lub cuab yeej.

Kauj ruam 2: Teeb Up Cloud4Rpi.io

Teeb tsa Cloud4Rpi.io
Teeb tsa Cloud4Rpi.io

Cloud4Rpi muab kev pabcuam uas cia koj lub cuab yeej xa thiab tau txais cov ntaub ntawv siv MQTT lossis HTTP cov kev cai. Lawv muaj lub tsev qiv ntawv thov rau Python, yog li kuv yuav siv Python.

Cov nab npawb piv txwv uas los nrog Cloud4Rpi cov kev pabcuam twb muaj cov lej rau DS18B20 ntsuas kub.

Yog li kuv tau mus rau https://cloud4rpi.io, tsim tus as khauj thiab ntxiv cov cuab yeej tshiab nyob ntawd. Cov nplooj ntawv ntaus ntawv muaj cov cim cim - txoj hlua uas qhia txog lub cuab yeej, thiab yuav tsum tau teev nyob hauv txoj haujlwm uas xa cov ntaub ntawv.

Txhawm rau pib nrog, nws ib txwm yog lub tswv yim zoo los hloov kho tus tswj hwm pob thiab txhim kho pob khoom (nco tseg: nws tuaj yeem siv sijhawm yog tias koj tsis tau hloov kho ib ntus):

sudo apt-tau hloov tshiab & sudo apt-tau hloov tshiab

Tom qab ntawd, teeb tsa git, Python thiab nws tus thawj tswj hwm pob Pip:

sudo apt-tau nruab git nab hab sej nab hab sej-pip

Tom qab ntawd, teeb tsa cloud4rpi Python tsev qiv ntawv:

sudo pip nruab cloud4rpi

Thaum kawg, kuv npaj sau kuv qhov kev tswj hwm. Kuv pib los ntawm qhov piv txwv muaj nyob ntawm https://github.com/cloud4rpi/cloud4rpi-raspberrypi …

git clone https://github.com/cloud4rpi/cloud4rpi-raspberrypi… cloud4rpicd cloud4rpi

Cov ntaub ntawv tseem ceeb hauv program yog control.py - Kuv yuav tsum hloov kho nws rau qhov kuv xav tau. Ua ntej, kho qhov program thiab muab cov cim cim:

sudo nano tswj.py

Nrhiav kab DEVICE_TOKEN = '…'] thiab qhia lub cuab yeej token nyob ntawd. Tom qab ntawd kuv tuaj yeem ua haujlwm yooj yim: Nws ua haujlwm thiab tshaj tawm qhov ntsuas kub hauv RoomTemp kuj sib txawv:

sudo python control.py

Nws ua haujlwm thiab tshaj tawm qhov ntsuas kub hauv RoomTemp sib txawv.

Nco ntsoov tias nws tshawb pom txhua tus onewire ds18b20 sensors

ds_sensors = ds18b20. DS18B20.find_all ()

thiab siv thawj qhov pom sensor:

RoomTemp ': {' hom ':' zauv ',' khi ': ds_sensors [0] yog ds_sensors lwm Tsis muaj}

Ok, uas yog ib qho yooj yim, vim tias qhov qauv piv txwv muaj txhua yam uas xav tau los ua haujlwm nrog ds18b20 sensor ntawm Raspberry Pi. Tam sim no kuv yuav tsum nrhiav txoj hauv kev los qhia qhov xwm txheej ntawm lub zog.

Kauj Ruam 3: UPS Saib Xyuas

UPS Saib Xyuas
UPS Saib Xyuas

Qhov tom ntej no kuv xav tshuaj xyuas yog UPS xwm txheej, yog li yog tias muaj hluav taws xob tsis txaus, Kuv yuav paub txog nws ua ntej txhua yam txiav tawm.

Kuv muaj APC UPS nrog USB tswj, yog li kuv sai sai googled thiab pom tias kuv xav tau apcupsd. https://www.anites.com/2013/09/monitoring-ups.html… Kuv tau sim ob peb zaug los nruab nws ntawm apt-get, thiab nws tsis ua haujlwm rau kuv rau ntau yam laj thawj. Kuv yuav qhia yuav ua li cas rau nruab nws los ntawm cov peev txheej.

wget https://sourceforge.net/projects/apcupsd/files/ap…tar xvf apcupsd-3.14.14.tar.gz cd apcupsd-3.14.14./configure --enable-usb sudo ua sudo nruab

Tom qab ntawd kuv kho apcupsd.conf txuas rau kuv UPS ntawm usb.

sudo nano /etc/apcupsd/apcupsd.conf# #UPSCABLE ntse UPSCABLE usb ##UPSTYPE apcsmart #DEVICE/dev/ttyS0 UPSTYPE usb DEVICE

Tam sim no kuv tuaj yeem ntsaws USB cable los ntawm UPS rau RaspberryPi thiab sim yog tias UPS yuav pom.

sudo apctest cov

Nws yuav tsum muab rau koj tsis muaj lus yuam kev.

Tam sim no sevice apcupsd yuav tsum tau pib:

sudo systemctl pib apcupsd

Txhawm rau quiery UPS xwm txheej Kuv tuaj yeem siv qhov xwm txheej hais kom ua:

sudo /etc/init.d/apcupsd xwm txheej

Thiab nws yuav tso tawm qee yam zoo li no:

APC: 001, 035, 0855 Hnub tim: 2018-10-14 16:55:30 +0300 HOSTNAME: vcontrol VERSION: 3.14.14 (31 Tsib Hlis 2016) debian UPSNAME: vcontrol CABLE: USB Cable DRIVER: USB UPS Tsav Tsheb UPSMODE: Sawv Ib Leeg ZOO TSHAJ PLAWS: 2018-10-14 16:54:28 +0300 Qauv: Back-UPS XS 650CI STATUS: ONLINE LINEV: 238.0 Volt LOADPCT: 0.0 Feem pua BCHARGE: 100.0 Feem pua TIMELEFT: 293.3 feeb MBATTCHG: 5 Feem pua MINTIMEL: 3 feeb MAXTIME: 0 Seconds SENSE: LOTRANS Nruab Nrab: 140.0 Volts HITRANS: 300.0 Volts ALARMDEL: 30 Seconds BATTV: 14.2 Volts LASTXFER: Tsis hloov pauv txij li turnon NUMXFERS: 0 TONBATT: 0 Seconds CUMONBATT: 0 Seconds XOFFBATT: N/A STATLA000: 0: 2014-06-10 NOMINV: 230 Volts NOMBATTV: 12.0 Volts NOMPOWER: 390 Watts FIRMWARE: 892. R3. I USB FW: R3 END APC: 2018-10-14 16:55:38 +0300

Kuv xav tau tus xwm txheej - uas yog kab "STATUS:".

Lub tsev qiv ntawv Cloud4rpi muaj tus qauv 'rpy.py' uas rov qab Raspberry Pi cov txheej txheem tsis xws li hostname lossis cpu kub. Txij li tag nrho cov params yog cov txiaj ntsig ntawm kev khiav qee cov lus txib thiab cais tawm, nws tseem muaj qhov ua haujlwm 'parse_output' ua haujlwm uas ua raws qhov kuv xav tau. Nov yog yuav ua li cas kom tau txais kuv li UPS raws li txoj cai:

def ups_status (): tshwm sim = rpi.parse_output (r'STATUS / s+: / s+(S+) ', [' /etc/init.d/apcupsd ',' status ']) yog qhov tshwm sim: rov tshwm sim lwm yam: rov qab 'Tsis paub'

Txhawm rau xa cov xwm txheej no mus rau cloud4rpi, kuv yuav tsum tshaj tawm qhov hloov pauv UPSStatus thiab khi nws rau kuv li haujlwm ups_status: Tam sim no kuv tuaj yeem ua kuv qhov haujlwm:

variables = {'RoomTemp': {'type': 'numeric', 'bind': ds_sensors [0]}, 'UPSStatus': {'type': 'string', 'bind': ups_status}}

Thiab kuv tuaj yeem pom tam sim kuv qhov sib txawv ntawm nplooj ntawv cloud4rpi.

Kauj Ruam 4: Npaj rau "kev tsim khoom"

Npaj rau "kev tsim khoom"
Npaj rau "kev tsim khoom"

Txhua txoj haujlwm tau ua haujlwm, thiab tam sim no kuv yuav tsum npaj kuv lub cuab yeej rau hom tsis muaj neeg saib xyuas.

Txhawm rau pib nrog, Kuv yuav kho lub sijhawm sib nrug. Lub sij hawm pov ntawv xaiv tsa txhais tau tias qhov kev zov me nyuam ntsuas qhov ntsuas kub thiab UPS li cas - teem nws li ib pliag.

Cov txiaj ntsig tau xa mus rau huab txhua 5 feeb, thiab cov ntaub ntawv tshuaj xyuas - txhua teev.

# ConstantsDATA_SENDING_INTERVAL = 300 # sec DIAG_SENDING_INTERVAL = 3600 # sec POLL_INTERVAL = 1 # sec

Thaum UPS hloov pauv xwm txheej - kuv tsis xav kom kuv lub cuab yeej tos 5 feeb, thiab kuv xa cov ntaub ntawv tam sim ntawd. Yog li kuv tau hloov kho me ntsis lub voj tseem ceeb thiab nws zoo li qhov no:

data_timer = 0diag_timer = 0 prevUPS = 'ONLINE' thaum muaj tseeb: newUPS = ups_status () yog (data_timer <= 0) lossis (newUPS! = prevUPS): device.publish_data () data_timer = DATA_SENDING_INTERVAL prevUPS = tshiab device.publish_diag () diag_timer = DIAG_SENDING_INTERVAL pw (POLL_INTERVAL) diag_timer -= POLL_INTERVAL data_timer -= POLL_INTERVAL

Xeem: khiav tsab ntawv:

sudo python control.py

Thiab kuv tuaj yeem saib UPS xwm txheej ntawm kuv nplooj ntawv ntaus ntawv.

Yog tias kuv tua UPS lub zog, xwm txheej hloov pauv hauv ob peb feeb, yog li txhua yam ua haujlwm tam sim no kuv yuav tsum pib apcupsd thiab kuv tswj.py ntawm kev pib ua haujlwm. Apcupsd cov kev pabcuam qub thiab kom pib nws ntawm raspbian niaj hnub no, Kuv yuav tsum hloov kho /etc/init.d/apcupsd cov ntaub ntawv, los ntawm kev ntxiv cov kab no nyob qhov twg rau saum:

### Pib INIT INFO # Muab: apcupsd # Yuav tsum-Pib: $ tag nrho # Yuav Tsum-Nres: # Pib-Pib: 2 3 4 5 # Default-Stop: # Short-Description: APC UPS daemon… ### END INIT Cov ntaub ntawv#

Tom qab ntawd qhib qhov kev pabcuam:

sudo systemctl pab kom apcupsd

Tom qab ntawd pib qhov kev pabcuam:

sudo systemctl pib apcupsd

Tam sim no apcupsd yuav pib ntawm qhov system pib.

Txhawm rau nruab control.py ua qhov kev pabcuam, Kuv siv cov ntawv pabcuam service_install.sh muab:

sudo bash service_install.sh ~/cloud4rpi/control.py

Tam sim no kev pabcuam tau pib thiab nws shouls muaj sia nyob rov pib dua.

Kauj Ruam 5: Teeb Chaw Tswj Vaj Huam Sib Luag

Teeb Chaw Tswj Vaj Huam Sib Luag
Teeb Chaw Tswj Vaj Huam Sib Luag

Cloud4rpi cia kuv teeb tsa lub tswj vaj huam sib luag rau kuv lub cuab yeej. Koj tuaj yeem ntxiv "widgets" thiab khi lawv rau cov cuab yeej hloov pauv.

Kuv lub cuab yeej muab ob qhov kev nyeem nkaus xwb - RoomTemp thiab UPSStatus:

variables = {'RoomTemp': {'type': 'numeric', 'bind': ds_sensors [0]}, 'UPSStatus': {'type': 'string', 'bind': ups_status}}

Kuv ntxiv 3 widgets - Tus lej rau RoomTemp, Ntawv rau UPSStatus thiab Daim Ntawv rau RoomTemp.

Kuv tuaj yeem teeb tsa kev ceeb toom, yog li kuv tau txais email thaum qhov kub tsis tshaj qhov teev tseg, UPS mus offline lossis ntaus ntawv nws tus kheej tsis xa cov ntaub ntawv thaum nws yuav tsum tau. thaum muaj qee yam tsis raug, yog li kuv tuaj yeem hu xov tooj rau cov neeg nyob ze thiab nug lawv kom txheeb xyuas seb muaj dab tsi tshwm sim. Nov yog tus lej tseeb ntawm control.py.

Pom zoo: