Cov txheej txheem:

Internet Enabled Power Outlet: 13 Kauj Ruam
Internet Enabled Power Outlet: 13 Kauj Ruam

Video: Internet Enabled Power Outlet: 13 Kauj Ruam

Video: Internet Enabled Power Outlet: 13 Kauj Ruam
Video: Interface with Remote Power Sockets -- Final Version 2024, Hlis ntuj nqeg
Anonim
Image
Image
Cov Khoom Siv Xav Tau
Cov Khoom Siv Xav Tau

PowerHub Webserver Project & Internet Enabled Outlet Setup Instructions

Lub hauv paus cov ntaub ntawv tseem nyob ruaj khov rau Internet qhib lub teeb thiab qhov hluav taws xob hauv koj lub tsev!

Kauj Ruam 1: PowerHub Webserver Project & Internet Enabled Outlet Setup Instructions

Lub hauv paus cov ntaub ntawv tseem nyob ruaj khov rau Is Taws Nem qhib lub teeb thiab qhov hluav taws xob hauv koj lub tsev

Flashing RaspberriPi Hard Disk/Install Required Software (Using Ubuntu Linux) Download "RASPBIAN JESSIE LITE"

Tsim koj lub hard disk tshiab rau DashboardPI

Ntxig lub microSD rau koj lub khoos phis tawj ntawm USB adapter thiab tsim cov duab disk siv cov lus txib dd

Nrhiav koj daim npav microSD tso ntawm df -h hais kom ua, unmount nws thiab tsim cov duab disk nrog daim disk theej daim ntawv dd

$ df -h/dev/sdb1 7.4G 32K 7.4G 1%/media/XXX/1234-5678

$ umount /dev /sdb1

Ceev faj: nco ntsoov tias cov lus txib yog qhov tseeb, koj tuaj yeem ua rau lwm lub disks puas tsuaj nrog cov lus txib no

yog = qhov chaw ntawm RASPBIAN JESSIE LITE duab cov ntaub ntawv ntawm = qhov chaw ntawm koj daim npav microSD

$ sudo dd bs = 4M yog =/path/to/raspbian-jessie-lite.img ntawm =/dev/sdb (ceeb toom: qhov no, nws yog/dev/sdb,/dev/sdb1 yog lub koomhaum uas twb muaj lawm muab faib rau ntawm microSD)

Teeb koj li RaspberriPi

Ntxig koj daim npav microSD tshiab rau raspberrypi thiab siv nws nrog lub ntsuas saib txuas nrog rau HDMI chaw nres nkoj

ID nkag mus

neeg siv: pi pass: raspberry

Hloov koj tus lej password rau kev nyab xeeb

sudo passwd pib

Kauj ruam 2: Pab kom RaspberriPi Advanced Options

sudo raspi-teeb tsa

Xaiv: 1 Nthuav Cov Ntaub Ntawv System

9 Advanced Options

A2 Hostname hloov nws mus rau "WIFI-OUTLET"

A4 SSH Pab kom SSH Server

A7 I2C Pab kom i2c interface

Pab kom Askiv/Asmeskas Keyboard

sudo nano/etc/default/keyboard

Hloov cov kab hauv qab no: XKBLAYOUT = "peb"

Rov pib dua PI rau Keyboard hloov pauv / cov txheej txheem txheej txheem hloov pauv kom muaj txiaj ntsig

$ sudo kaw -r tam sim no

Auto-Txuas rau koj li WiFi

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Ntxiv cov kab hauv qab no kom muaj koj cov raspberrypi txuas nrog koj lub WiFi hauv tsev (yog tias koj lub wireless network npe "linksys" piv txwv, piv txwv li hauv qab no)

network = {ssid = "linksys" psk = "WIRELESS PASSWORD HERE"} Rov pib PI txuas rau WiFi network

$ sudo kaw -r tam sim no

Tam sim no tias koj tus PI yog qhov kawg ntawm lub network hauv zej zog, koj tuaj yeem nkag mus rau nws deb ntawm SSH. Tab sis ua ntej koj yuav tsum tau txais tus IP chaw nws tam sim no muaj.

$ ifconfig Saib rau "inet addr: 192.168. XXX. XXX" hauv cov lus txib hauv qab no tso tawm rau koj tus PI IP Chaw Nyob

Mus rau lwm lub tshuab thiab nkag mus rau koj li raspberrypi ntawm ssh

$ ssh [email protected]. XXX. XXX

Kauj Ruam 3: Pib Txhim Kho Cov Pob Yuav Tsum Muaj

$ sudo apt-tau hloov tshiab

$ sudo apt-tau hloov tshiab

$ sudo apt-tau nruab vim git nab-thov python-gpiozero python-smbus i2c-tools python-imaging python-smbus build-essential python-dev rpi.gpio python3 python3-pip libi2c-dev python3-spidev nab hab sej-spidev

Hloov kho thaj chaw sijhawm hauv cheeb tsam

$ sudo dpkg-reconfigure tzdata

xaiv koj lub sijhawm siv lub interface

Teeb cov npe yooj yim l hais kom ua [xaiv tau]

vi ~/.bashrc

ntxiv cov kab hauv qab no:

alias l = 'ls -lh'

qhov chaw ~/.bashrc

Txhim kho VIM default syntax highlighting [yeem]

sudo vi/etc/vim/vimrc

tsis pom zoo cov kab hauv qab no:

syntax yog

Nruab i2c Python Tsav Tsheb

Kauj Ruam 4: Txhim Kho WEB API

Cov lus qhia hauv qab no yuav tso cai rau koj los tsim lub hauv paus nruab nrab uas piav qhia rau ntau yam wifi qhib lub qhov hluav taws xob thiab cov phab ntsa hloov pauv uas koj tuaj yeem tsim, cov cuab yeej twg tau qhib thiab tawm. Nov yog tsab ntawv PHP me me tso rau ntawm lub vev xaib uas koj xaiv. Nws muaj cov API hauv qab no kom tau txais thiab teeb tsa cov ntaub ntawv rau nws. Nco tseg: tsis txhob hnov qab suav nrog.htaccess cov ntaub ntawv kom tsim nyog URL txoj hauv kev los ua qhov chaw.

Nruab qhov "index.php", "values/" folder thiab settings.php (teeb tsa rau koj tus kheej qhov tseem ceeb) rau PHP qhib webserver ntawm koj xaiv. Tus lej tseem ceeb zais cia hauv "settings.php" cov ntaub ntawv yuav tsum phim tus nqi zais cia uas koj yuav teeb tsa hauv "settings.py" cov ntaub ntawv. Qhov no yuav nyob rau theem pib tiv thaiv lwm lub vev xaib los ntawm kev teeb tsa / sau qhov tseem ceeb, tig rau koj li khoom siv, tam sim no koj xav tau qhov hashed API qhov tseem ceeb hauv HTTP thov header kom ua li ntawd.

API txhawb nqa cov yam ntxwv hauv qab no, rau txoj haujlwm no peb yuav siv tsuas yog "tus chij" qhov muaj txiaj ntsig uas yog tus nqi boolean uas qhia qhov hloov pauv kom qhib thiab tua. Tej zaum yog tias koj xav ua kom zoo dua qhov "nyeem" qhov txiaj ntsig koj tuaj yeem muaj nws yog li yog tias chav sov tau kub dhau los ntawm kev ntsuas kub nyob ntawd, nws tuaj yeem tig lub qhov rai kiv cua, thiab lwm yam.

Tau txais Txoj Cai

Clone cov haujlwm hauv qab no los ntawm GitHub kom tau txais txoj cai los ua haujlwm webserver thiab qhov hluav taws xob RaspberryPI.

github.com/khinds10/PowerHub

API Endpoints thaum khiav ntawm webserver

myhost/message (tau txais cov lus tam sim no teeb)

myhost/message/set (HTTP POST a string string value to this URL to set a new message)

myhost/flag/{id} (tau txais tam sim no boolean xwm txheej ntawm tus chij los ntawm tus lej: {id})

myhost/chij/tag nrho (tau txais tag nrho cov xwm txheej tam sim no boolean ntawm txhua tus chij raws li kab lus)

myhost/flag/{id}/set (teeb tsa tam sim no boolean xwm txheej rau 'tseeb' rau tus chij los ntawm tus lej: {id})

myhost/flag/{id}/unset (teeb tsa tam sim no boolean xwm txheej rau 'cuav' rau tus chij los ntawm tus lej: {id})

myhost/nyeem/{id} (tau txais tus nqi nruab nrab tam sim no rau kev nyeem los ntawm tus lej: {id})

myhost/nyeem/tag nrho (tau txais tus nqi nruab nrab tam sim no rau txhua qhov kev nyeem ua ib qho array)

myhost/nyeem/{id}/teeb tsa (HTTP POST tus lej tus lej nyoos rau qhov URL no ntxiv tus nqi tshiab rau tam sim no xam nruab nrab) - saib hauv qab no seb muaj pes tsawg tus nqi hauv tag nrho suav nrog tus nqi nruab nrab Kev teeb tsa Tus lej 'nyeem' raug suav ua qhov nruab nrab ntawm qee tus lej ntawm kev nyeem tsis ntev los no tseem muaj nuj nqis. Teem cov hauv qab no tas mus li pes tsawg ntawm cov ntawv nyeem tshiab tam sim no yuav tsum suav nrog los tsim qhov nruab nrab.

$ readingsAverageLimit = 5;

Datastore Server yuav ua kom muaj nuj nqis rau cov ntaub ntawv yooj yim nyob ntawm kev teev npe cov lus pom hauv qab no. Nco tseg: {id} yuav raug hloov los ntawm tus lej tiag uas tau nthuav tawm los ntawm qhov kev thov nkag URL.

$ valueFileFolder = 'qhov tseem ceeb' (lub npe ntawm daim nplaub tshev kom muaj cov ntaub ntawv ntsuas) $ messageFileName = 'message.msg' (lub npe ntawm cov ntawv xa ntawv) $ readingsFilesNames = 'nyeem {id}.avg' (lub npe ntawm CSV nruab nrab nyeem cov ntawv) $ flagFilesNames = 'chij {id}.flg' (lub npe ntawm tus chij tus nqi boolean tus chij)

Xyuas kom tseeb tias txhua cov ntaub ntawv tus nqi raug sau los ntawm systemchmod 777 qhov tseem ceeb/*

Kauj Ruam 5: Cov Khoom Xav Tau

Cov Khoom Siv Xav Tau
Cov Khoom Siv Xav Tau
Cov Khoom Siv Xav Tau
Cov Khoom Siv Xav Tau
Cov Khoom Siv Xav Tau
Cov Khoom Siv Xav Tau

1 nti qhov pom (rau kev xyaum)

5V 2 Channel Relay Module

Duplex Receptacle Wall Phaj

Duplex Receptacle

Pi Zero W

Nto Mount Backbox Dual Gang

Dawb Illuminated Laub Khawm

Kauj Ruam 6: Tsim Lub Qhov Hluav Taws Xob

Tsim lub Qhov Hluav Taws Xob
Tsim lub Qhov Hluav Taws Xob

Rhuav Tawm Tabs

Ua txhaum lub tab ntawm ib sab ntawm lub qhov hluav taws xob kom txhua lub qhov (socket) qhib/tawm ntawm nws tus kheej

Kauj ruam 7: Nruab Nyees khawm

Nruab Nyees khawm
Nruab Nyees khawm
Nruab Nyees khawm
Nruab Nyees khawm

Ntawm lub ntsej muag qhov hluav taws xob siv 1 qhov pom pom txiav 2 qhov rau cov nyees khawm tso rau ib sab ntawm lub qhov hluav taws xob

Xeem Sizing ntawm cov khoom

Ua kom ntseeg tau tias txhua qhov khoom siv yuav haum rau hauv lub qhov hluav taws xob sab saum toj lub thawv

Kauj Ruam 8: Hlau Txuas

Hlau Relay
Hlau Relay
Hlau Relay
Hlau Relay

Hlau txuas mus rau lub qhov hluav taws xob, los ntawm txoj hlua txuas mus rau ntawm phab ntsa, txuas hauv av (ntsuab) thiab nruab nrab (dawb) ncaj qha rau lub qhov hluav taws xob tus kheej

Kauj Ruam 9: Ntxiv Xov Tooj thiab Sib Dhos Duab

Cov Xov Tooj Ntxiv thiab Sib Dhos Duab
Cov Xov Tooj Ntxiv thiab Sib Dhos Duab

Kauj Ruam 10: Daim duab thaiv

Daim duab thaiv
Daim duab thaiv

Siv daim duab kom raug xaim cov khoom kom ua haujlwm nrog RaspberryPI Python code.

Kauj Ruam 11: Kuaj Qhuav Qhuav

Kuaj Qhuav Qhuav
Kuaj Qhuav Qhuav
Kuaj Qhuav Qhuav
Kuaj Qhuav Qhuav
Kuaj Qhuav Qhuav
Kuaj Qhuav Qhuav

Tom qab kev sib dhos zaum kawg ua ntej ntsia lub qhov nyob ua ke, ua kom qhuav ntawm lub cuab yeej kom paub tseeb tias tsis muaj luv, thaiv tsis zoo

Kauj ruam 12: Teem Startup Scripts

crontab -e

ntxiv cov kab hauv qab no

@reboot sej /home/pi/PowerHub/device/outlet/buttons.py @reboot sej /home/pi/PowerHub/device/outlet/relay.py

Pom zoo: