Cov txheej txheem:

UCL - Tsev cog khoom IIOT: 11 Kauj Ruam
UCL - Tsev cog khoom IIOT: 11 Kauj Ruam

Video: UCL - Tsev cog khoom IIOT: 11 Kauj Ruam

Video: UCL - Tsev cog khoom IIOT: 11 Kauj Ruam
Video: Cog khoom ntis tsev 12/2/2020 2024, Kaum ib hlis
Anonim
UCL - IIOT Tsev Cog Khoom
UCL - IIOT Tsev Cog Khoom

Txoj haujlwm no yog kev txuas ntxiv ntawm peb txoj haujlwm yav dhau los nrog Tsev Cog Khoom (https://www.instructables.com/id/EAL-EMBEDDED-GREE…).

Hauv qhov haujlwm no peb tau ntxiv cov ntaub ntawv khaws cia, qhov uas peb nkag mus rau tag nrho peb cov ntaub ntawv thiab tom qab ntawd pom nws nrog ntawm-liab kom pom dav dua.

Cov ntsiab lus peb nkag rau hauv peb cov ntaub ntawv khaws cia yog Humidity, Kub thiab noo ntawm cov av, uas tau qhia hauv kab duab sib txawv.

Dhau li dataloggin peb kuj tseem tuaj yeem tswj hwm cov ntaub ntawv uas tau ua haujlwm hauv Tsev Cog Khoom thiab tswj nws nyob deb.

Tom qab ntawd peb tseem tuaj yeem tswj hwm lub twj tso kua mis thiab kiv cua ntawm tus kheej.

Kauj Ruam 1: Phau Ntawv Qhia Kev Txhim Kho

Phau ntawv qhia kev teeb tsa
Phau ntawv qhia kev teeb tsa

Thawj kauj ruam yog txhawm rau txhim kho txhua qhov sib txawv.

Sab hauv cov kab zauv (), peb tau teev qhov chaw uas cuam tshuam nrog. Yog li piv txwv, Arduino txuas nrog Raspberry Pi ntawm USB cable.

Kho vajtse siv:

  • Arduino (Raspberry Pi)
  • Raspberry Pi 3 B+
  • Av hygrometer (Arduino)
  • DHT11 sensor (Arduino)
  • HG-320 Submersible Dej Twj (Relay)
  • 5V tshaj tawm (Arduino)
  • Ib lub computer kiv cua (Relay)
  • 230V fais fab mov (twj tso kua mis)

Software siv:

  • Raspbian (OS rau Raspberry Pi)
  • Arduino IDE Cov
  • Nab hab sej (Raspberry Pi)- PySerial- MySQLclient
  • Node-Red (Raspberry Pi)- Pythonshell- Summariser- MySQL- Dashboard
  • MySQL server (freemysqlhosting.net)

Ua ntej koj yuav tsum txuas cov khoom siv kho vajtse, yog li ua raws phau ntawv qhia no los tsim lub tsev cog khoom: Nruab Cov Lus Qhia.

Tom qab ntawd koj yuav tsum teeb tsa Raspbian OS ntawm koj li Raspberry Pi. Tom qab ntawd koj yuav tsum teeb tsa Python, thiab tom qab ntawd teeb tsa cov tsev qiv ntawv sej.

Cov kauj ruam tom ntej yog teeb tsa Node-Red ntawm Raspberry Pi, thiab tom qab ntawd mus rau tus thawj tswj hwm pallette thiab teeb tsa cov qauv qhia ua ntej.

Tom qab ntawd mus rau qhov chaw Dawb MySQL Server thiab tsim MySQL server dawb.

Thaum txhua qhov no ua tiav, koj npaj tau xa cov ntawv nab nab mus rau koj Raspberry Pi, ntshuam Node-Red tsab ntawv thiab xa cov cai rau Arduino.

Kauj ruam 2: Showcase of Control

Image
Image

Kauj Ruam 3: Sau Cov Khoom/software Siv hauv Txoj Haujlwm

Peb tau siv cov thev naus laus zis hauv qab no los ua Tsev Cog Khoom

  • Arduino
  • Raspberry Pi
  • Node-Liab
  • Nab hab sej
  • PHPMyAdmin

Kauj ruam 4: Kuv/0 Sau

Daim duab thaiv
Daim duab thaiv

Kauj Ruam 5: Daim Kab Xev

Kauj Ruam 6: Arduino Code

Tus lej Arduino ua haujlwm los ntawm kev luam cov ntaub ntawv, ntsuas los ntawm lub ntsuas cua, mus rau qhov txuas txuas uas nws tau nyeem los ntawm Raspberry Pi thiab pauv mus rau lub hauv paus.

Arduino kuj tseem muaj qee qhov digital inputpins txuas nrog Raspberry Pi uas Arduino nyeem thiab yog tias ib ntawm peb ua HIGH qhov profile yuav hloov pauv vim yog IF nqe lus.

Tsis tas li peb tau hloov kho cov cai kom siv Millis hloov qhov kev ncua uas ua rau lub hauv paus thiab so ntawm cov cai kom nyeem txhua lub sijhawm tsis txhob ncua sijhawm los ntawm qhov qub qeeb.

Kauj Ruam 7: Raspberry Pi 3 B+

Raspberry Pi 3 B+
Raspberry Pi 3 B+

Peb siv Raspberry Pi 3 B+ rau txuas peb Arduino nrog internet thiab MySQL database. Qhov no ua rau nws muaj peev xwm rau peb khaws cov ntaub ntawv los ntawm peb lub ntsuas cua thiab ua kom pom kev zoo rau tus neeg siv kawg. Rau cov neeg siv sib tham peb siv Node-Red nrog Dashboard palette.

Tab sis ua ntej peb tuaj yeem qhia peb cov ntaub ntawv ntsuas ntawm Node-Red, peb xav tau txoj hauv kev los tso cov ntaub ntawv ntawm MySQL database, thiab rau qhov ntawd peb tau ua Python tsab ntawv uas yuav ua haujlwm ntawm peb Raspberry Pi.

Kauj Ruam 8: Python

Nab hab sej
Nab hab sej

Python tsab ntawv yog siv los txais cov ntaub ntawv los ntawm kev sib txuas lus txuas los ntawm Arduino. Tsab ntawv xa cov ntaub ntawv mus rau MySQL database.

Peb siv ob lub tsev qiv ntawv, pyserial thiab mysqlclient.

Yog li thawj kauj ruam yuav rub ob lub tsev qiv ntawv no:

  1. PySerial
  2. MySQLclient

PySerial yog siv los sau cov ntaub ntawv los ntawm Arduino ntawm kev sib txuas lus txuas.

ntaus ntawv = '/dev/ttyUSB0'

arduino = serial. Serial (ntaus ntawv, 9600)

Thawj kab tau siv los txheeb xyuas peb li COM-chaw nres nkoj. Ntawm Raspberry Pi nws yog /dev /ttyUSB0, uas peb siv rau Arduino. Kab thib ob yog qhib qhov chaw nres nkoj txuas mus rau Arduino. Peb tsuas yog txiav txim siab qhov twg COM-chaw nres nkoj thiab qhov nrawm txuas txuas tau khiav ntawm.

Tus so ntawm txoj cai tau ua haujlwm ib ntus.

Tom ntej no peb siv ntau Sim thiab Tsuas yog cov block. Thawj qhov chaws tau sim khiav sab hauv Sim sim, yog tias qhov ntawd ua tsis tau ces nws ua haujlwm tshwj tsis yog thaiv. Tab sis yog tias Sim block ua haujlwm zoo, nws tsis ua haujlwm tshwj tsis yog thaiv, nws tsuas yog ua haujlwm tas li ntawm cov cai.

Yog li sab hauv Cov Sim sim peb muaj cov lej uas yuav nyeem cov ntawv sib txuas lus thiab tom qab ntawd xa nws mus rau peb MySQL database.

hygrolist = arduino.readlines (1)

templist = arduino.readlines (2) humidlist = arduino.readlines (3)

Yog li cov cai saum toj no yog rau nyeem kab hauv kab lus-kev sib txuas lus. Tus lej nyob rau qhov kawg ntawm txoj cai yog txhais kab uas tau nyeem hauv kab ntawv. Yog li cov kab no tau raug cais nyob hauv ntau qhov sib txawv.

Thaum cov ntaub ntawv los ntawm Arduino tau txais, peb siv tus qauv mysqlclient rau xa cov ntaub ntawv rau peb MySQL Server.

db = _mysql.connect (host = "sql7.freemysqlhosting.net", user = "sql7256552", passwd = "3ebtbP8FQ2", db = "sql7256552")

Kab ntawv no yog txuas rau peb MySQL database. Nws qhia meej txog server, username, password thiab database twg nws yuav tsum txuas rau sab hauv server. Ntawm no koj yuav tsum qhia meej qhov kev sib txuas rau koj li MySQL DB.

db.query ("INSERTINTO` TempHumid` (`temp`,` humid`, `hygro`) VALUES (%s, %s, %s)" %(temp, ntub, hygro))

Yog li ntawm no peb coj peb qhov kev sib txuas DB thiab ua SQL cov lus nug. Cov lus nug hais tias qhov tseem ceeb yuav tsum tau muab tso rau hauv lub rooj "TempHumid" thiab tom qab ntawd nkag mus rau kab "temp", "humid" thiab "hygro". Ntu kawg “(%s, %s, %s)” yog txoj hlua kab ntawv thiab tau siv los muab cov ntaub ntawv khaws tseg rau hom ntawv uas nws nyeem tau.

Thiab txhua qhov kev nqis tes no tau muab tso rau hauv lub sijhawm luv, yog li peb khaws cov ntaub ntawv xa mus rau MySQL server.

Yog tias koj xav pom tag nrho cov cai, rub cov ntawv nab nab (TempHumid.py).

Kauj ruam 9: MySQL

MySQL
MySQL
MySQL
MySQL

Txog MySQL server, peb siv kev pabcuam dawb ntawm www.freemysqlhosting.net. Peb tuaj yeem ua tus neeg rau zaub mov hauv zos ntawm Raspberry Pi, tab sis peb tau mus nrog cov kev pabcuam dawb kom ua kom nws txuas nrog huab/internet.

Txhawm rau nkag mus rau koj li MySQL, koj yuav tsum mus rau phpmyadmin.co thiab nkag mus nrog cov ntaub ntawv pov thawj los ntawm koj tus lej freemysqlhosting.

Thaum koj nyob sab hauv, koj yuav tsum tsim lub rooj hu ua "TempHumid", sab hauv lub rooj no koj yuav tsum tsim 4 kab ntawv hu ua, "ID", "temp", "humid" thiab "hygro". Thawj kab ntawv (ID) koj yuav tsum tau khij lub npov A_I (Pib nce ntxiv). Qhov no yog li kab ntawv ID muab txhua cov ntaub ntawv tus lej ID. Txhua kab ntawv hauv qab no yuav tsum tau teeb tsa ua INT (tus lej suav), thiab teeb tsa tus qauv tus nqi rau NULL.

Kauj ruam 10: Node-Liab

Node-Liab
Node-Liab
Node-Liab
Node-Liab
Node-Liab
Node-Liab

Hauv peb qhov haujlwm peb siv Node-Red los ua lub ntsej muag duab. Node-Red tau ua haujlwm ntawm Raspberry Pi thiab tau khaws cov ntaub ntawv los ntawm peb MySQL database thiab tau qhia cov ntaub ntawv no nrog cov khoom tsis zoo li cov ntsuas ntsuas thiab cov duab kab duab, kom cov neeg siv kawg tuaj yeem saib xyuas cov ntaub ntawv. Qhov ntse tshaj plaws ntawm Node-Red yog qhov nws tuaj yeem pom ntawm txhua lub cuab yeej, uas txhais tau tias lub xaib yuav raug hloov pauv rau cov cuab yeej muab uas tab tom saib cov ntsiab lus.

Txhawm rau nruab peb Node-Red programming, saib Kauj Ruam 1 thiab rub daim ntawv hu ua "Node-Red.docx". Tom qab ntawd luam thiab muab cov ntawv tso rau hauv Node-Red ntawm qhov ua haujlwm ntshuam nyob rau sab xis saum toj.

Tom qab ntawd hloov DB nqis rau koj MySQL DB.

Pom zoo: