Cov txheej txheem:

MQTT/Google Tsev Dej Nyab/Dej WIFI Sensor Nrog ESP-01: 7 Cov Kauj Ruam
MQTT/Google Tsev Dej Nyab/Dej WIFI Sensor Nrog ESP-01: 7 Cov Kauj Ruam

Video: MQTT/Google Tsev Dej Nyab/Dej WIFI Sensor Nrog ESP-01: 7 Cov Kauj Ruam

Video: MQTT/Google Tsev Dej Nyab/Dej WIFI Sensor Nrog ESP-01: 7 Cov Kauj Ruam
Video: Google Cloud based IoT system with MQTT - [TUTORIAL 1] 2024, Kaum ib hlis
Anonim
MQTT/Google Tsev Dej Nyab/Dej WIFI Sensor Nrog ESP-01
MQTT/Google Tsev Dej Nyab/Dej WIFI Sensor Nrog ESP-01

Hauv cov lus qhia no, kuv yuav qhia koj yuav ua li cas tsim wifi dej nyab/dej ntsuas nrog tus nqi tsawg. Tag nrho txoj haujlwm raug nqi kuv tsawg dua $ 8 rau ntu uas kuv tau txais los ntawm ebay thiab kuv cov khoom seem uas twb muaj lawm.

Hauv txoj haujlwm no, peb yuav siv ESP-01 los muab Wifi thiab MQTT tus neeg siv kom paub tias muaj dej, thiab xaiv tau ncaj qha txuas nrog tus hais lus/buzzer los muab lub tswb nyob hauv.

Kuv daim ntawv thov tshwj xeeb rau txoj haujlwm yog txhawm rau txheeb xyuas dej nyab/dej hauv kuv lub twj tso kua mis zoo, thaum lub twj tso kua mis tso tsis tau. Thaum pom dej los ntawm 2 qhib xov hlau, nws yuav xa xov mus rau MQTT tus tswv lag luam. MQTT broker yuav xa cov lus mus rau NodeRED. Thaum tau txais MQTT cov lus, NodeRED yuav xa tshaj tawm rau ntau lub cuab yeej google hauv tsev thiab tseem xaiv tau xa xov mus rau xov tooj ntawm tes/browser ntawm pushbullet

Tam sim no tau kawg txoj haujlwm no tsuas yog ua haujlwm yog tias hluav taws xob hauv tsev tau qhib. Hauv cov lus qhia tom ntej no kuv yuav suav nrog lub roj teeb thaub qab Circuit. Tab sis yog tias koj ua lub hwj chim muab tib txoj kev uas kuv tau ua, koj tsuas tuaj yeem ntsaws USB lub txhab nyiaj hauv txhab nyiaj rau roj teeb thaub qab. Yog tias koj muaj lub txhab nyiaj fais fab uas tso cai rau koj them nyiaj thiab muab lub zog rau tib lub sijhawm, tom qab ntawd koj tau teeb tsa tag nrho.

Kuv siv RaspberryPi ZeroW los tuav Mosquitto MQTT server thiab NodeRED. Nws tau ua haujlwm ntau dua ib xyoos yam tsis muaj teeb meem.

Cov ntaub ntawv: Raspberry Pi: https://www.switchdoc.com/2016/02/tutorial-installi …Install NodeRED ntawm Raspberry Pi:

Kauj Ruam 1: Yam Uas Koj Yuav Xav Tau

Qhov Koj Yuav Tsum Xav Tau
Qhov Koj Yuav Tsum Xav Tau
Qhov Koj Yuav Tsum Xav Tau
Qhov Koj Yuav Tsum Xav Tau
Qhov Koj Yuav Tsum Xav Tau
Qhov Koj Yuav Tsum Xav Tau

Daim Ntawv Teev Npe:

(1) ESP-01

(2) 10K ohm Resistor

(1) teeb liab me me generic NPN transistor (Kuv siv 2N3904)

(2) cov xov hlau ntev

(1) 5V cov khoom siv hluav taws xob (lub voj voog no xav tau tsawg dua 300mA tam sim no)

(1) 3.3V tus tswj hwm tus qauv AMS1117

(1) Micro-USB Rau DIP Adapter Poj Niam Txuas Txuas PCB Hloov DIY Cov Khoom

(1) USB-A rau MicroUSB cable.

(1) 8-pin IC lub qhov (socket)-tuaj yeem tshem tawm yog tias koj xav tau txuas ESP-01 ncaj qha rau lub rooj tsav xwm hauv Circuit Court. Txiav cov yas txuas uas tsim qhov sib txawv nruab nrab ntawm kab, thiab tom qab ntawd lo rau 2 kab ua ke, saib daim duab.

(1) Cov ntawv me me rau txoj haujlwm

Hauv qab no yog cov khoom xaiv yog tias koj xav tau lub tswb nrov hauv zos siv tus hais lus/buzzer

(1) Generic PNP Transistor, xaiv raws li tus hais lus/buzzer tam sim no/wattage xav tau. Hauv kuv qhov xwm txheej kuv siv 2N2907 vim tias kuv tus neeg hais lus tsuas yog 0.3W (8 ohm), nws yuav muab lub zog txaus los tsav tus hais lus. Koj tuaj yeem xaiv lub transistor & tus hais lus loj dua yog tias koj xav tau lub suab nrov dua.

(1) Hais lus, saib ceeb toom ntawm PNP Transistor saum toj no

(1) 100 - 110 ohm Resistor

Kauj Ruam 2: Daim duab Circuit Court

Daim duab Circuit Court
Daim duab Circuit Court

Thawj kauj ruam yuav yog tsim cov kab hluav taws xob uas qhia hauv daim duab.

Kuv tsim 3.3VDC lub zog siv siv lub qub 5V lub xov tooj ntawm tes txuas nrog AMS1117 3.3VDC tus tswj hwm. Txog ESP-01 lub qhov (socket), Kuv siv tus lej 8 tus pin tus qauv IC, thiab txiav cov yas txuas uas tsim qhov sib txawv ntawm cov kab, thiab tom qab ntawd lo ob kab ua ke.

Lub Circuit Court uas kuv tsim yog kom paub tias muaj dej nyob nruab nrab ntawm ob lub xov hlau. Thaum dej mus txog qhov kawg ntawm ob lub xov hlau, nws yuav tsim kev tiv thaiv kwv yees li 10K txog 20K ohm. Tom qab ntawd hauv kab ntawv nrog 10K ohm R1, nws muab qhov me me tam sim no rau lub hauv paus ntawm Q1 ua rau Q1 kom saturate, clamping GPIO-2 rau hauv av. R1 yog qhov tsim nyog los muab kev tiv thaiv rau Q1 yog tias muaj qhov yuam kev luv ntawm qhov hnov xov hlau.

R2 yog rub tawm tus tiv thaiv kom tso cai ESP-01 rau khau raj los ntawm nyem.

Tam sim no rau tus neeg hais lus xaiv/buzzer, yog tias koj tsuas xav tau ESP-01 los tham MQTT thiab tsis xav ua qhov kev ceeb toom no hauv ib cheeb tsam, koj tuaj yeem tshem R2, Q2, Hais Lus, thiab tso 10K rub tawm qhov tawm tsam ntawm GPIO-0 thiab VCC.

Yog tias koj tsis xav tias yuav tsum tau siv tus poj niam Micro-USB rau DIP adapter, koj tuaj yeem txuas cov xov hlau ntawm 5V PS mus rau 3.3V tus tswj hwm tus qauv. Kuv nyiam siv tus poj niam MicroUSB adapter yog li kuv tuaj yeem siv txhua lub xov tooj ntawm tes them nyiaj thiab MicroUSB cable.

Kauj Ruam 3: Tsim Circuit Court

Tsim lub Circuit
Tsim lub Circuit
Tsim lub Circuit
Tsim lub Circuit
Tsim lub Circuit
Tsim lub Circuit

Muab tag nrho cov khoom sib txuas thiab cov khoom tso rau hauv PCB raws li daim duab qhia hauv kab lus hauv nplooj ntawv dhau los, thiab txiav PCB kom loj me.

Muab cov PCB tso rau hauv ib lub thawv uas yuav haum rau PCB thiab tus neeg hais lus xaiv tau. Hauv kuv qhov xwm txheej, txhua ntu yuav haum rau sab hauv lub thawv me me ntawm lub xov tooj, txawm hais tias kuv yuav tsum ua kom sov lub npog me ntsis los tsim lub nraub qaum kom ESP-01 tus qauv yuav haum.

Kauj Ruam 4: Teeb ESP-01

Hauv cov kauj ruam no, peb yuav nyem ESP-01 nrog daim duab arduino. Yog tias koj tsis tau pom dua ESP-01 tus qauv, koj tuaj yeem ua raws li kuv cov lus qhia kom koj pib:

Koj tuaj yeem pom kuv cov duab hauv kuv nplooj ntawv github:

Hauv qhov kos duab, yam tsawg kawg koj yuav tsum hloov cov ntaub ntawv hauv qab no ntsig txog koj lub network/teeb tsa hauv tsev:

#define MQTT_SERVER "10.0.0.30" const char* ssid1 = "SSID"; const char* password1 = "MYSSIDpassword"; const char* ssid2 = "SSID1"; const char* password2 = "MYSSIDpassword";

Hauv kuv lub tsev sib txuas, kuv muaj 2 qhov sib txawv nkag mus uas tshaj tawm 2 SSID sib txawv, thiab cov duab kos no yuav tso cai rov ua dua los ntawm kev txuas mus rau SSID tom ntej yog tias kev sib txuas lus mus rau AP tam sim no poob lawm. Yog tias koj tsuas muaj ib tus SSID, ua rau ob qho tib si ssid1 thiab ssid2 nrog tus nqi zoo ib yam.

Thaum koj ua qhov kev hloov kho, xa cov duab kos rau hauv ESP-01, thiab ntsaws rau hauv ESP-01 rau hauv lub rooj sib tham.

Kauj ruam 5: Xeem Khiav

Txhawm rau sim yog tias peb txoj haujlwm ua haujlwm, qhov yooj yim tshaj plaws yog los saib xyuas MQTT cov lus hauv lub network. Txhawm rau ua qhov ntawd, koj yuav tsum qhib ntu SSH rau tus neeg muag khoom mos txwv thiab tshaj tawm cov lus txib hauv qab no:

mosquitto_sub -v -t '#'

Cov lus txib saum toj no yuav tso cai rau peb pom txhua MQTT cov lus los rau hauv tus tswv lag luam.

Tam sim no txhawb peb lub Circuit, thiab yog txhua yam ua haujlwm, hauv ob peb feeb koj yuav tsum tsawg kawg pom cov lus hauv qab no MQTT:

stat/SumpWaterSensor/LWT Online

Tam sim no ntsuas lub ntsuas dej los ntawm kev nqes 2 lub xov tooj cua nkag mus rau hauv lub khob dej, thiab koj yuav tsum pom cov lus no:

tele/SumpWaterSensor WET

Thiab yog tias koj nqa cov xov hlau tawm hauv dej, koj yuav tsum pom cov lus no:

tele/SumpWaterSensor Qhuav

Yog tias koj pom cov lus ntawd, koj txoj haujlwm yog ua tiav.

Kuv kuj suav nrog ntau cov ntsiab lus MQTT muaj txiaj ntsig hauv daim duab uas koj tuaj yeem siv:

"stat/SumpWaterSensorInfo": cov lus no tau xa txhua feeb los qhia sijhawm thiab lwm yam ntaub ntawv.

"cmnd/SumpWaterSensorInfo": ESP-01 yuav xa tawm cov ntaub ntawv yog tias nws tau txais cov ncauj lus no nrog tus nqi ntawm '1' (ascii = 49)

"cmnd/SumpWaterSensorCPUrestart": ESP-01 yuav rov pib dua yog tias nws tau txais cov ncauj lus no nrog tus nqi '1' (ascii = 49)

"cmnd/SumpWaterSensorBeep": ESP-01 yuav ua lub suab hais lus yog tias nws tau txais cov ncauj lus no nrog tus nqi ntawm '1' (ascii = 49)

"cmnd/SumpWaterSensorBeepFreq": Teeb lub zaus ntawm lub tswb hais lus, lub neej = 900 (Hz)

"cmnd/SumpWaterSensorDebug": Pab kom thiab teeb tsa kev debugging theem (lub neej ntawd yog 0 - tsis muaj debugging)

Kauj Ruam 6: Mount Sensor

Mount lub Sensor
Mount lub Sensor
Mount lub Sensor
Mount lub Sensor

Hauv kuv daim ntawv thov, kuv xav tshuaj xyuas cov dej hauv kuv lub twj tso kua mis kom zoo, thiab ceeb toom rau kuv yog tias cov dej mus txog saum lub twj tso kua mis tso dej hloov pauv, uas txhais tau tias kuv lub twj tso kua mis tsis ua haujlwm. Kuv tau khiav cov xov hlau thiab siv cov hlua txuas kom ruaj ntseg nws raws cov kav dej.

Kauj Ruam 7: Kov Kawg

Kov Kawg
Kov Kawg

Tam sim no peb tau txais txoj haujlwm ua haujlwm thiab tuaj yeem tshaj tawm MQTT cov lus rau tus tswv lag luam, cov kauj ruam tom ntej yog xav txog lub tswv yim yuav ua li cas nrog qhov ntawd.

Hauv kuv qhov haujlwm, Kuv siv Node-RED los mloog/sau npe rau "tele/SumpWaterSensor" MQTT lub ncauj lus thiab tshaj tawm rau ntau tus neeg hais lus hauv google hauv tsev yog tias pom muaj dej. Ntxiv rau qhov ntawd, Kuv kuj tseem txuas qhov ntws mus rau lub pob nyem pob kom xa ceeb toom rau kuv lub xov tooj Android.

Kuv kuj tsim lub vev xaib ua ntej-kawg kom pom cov xwm txheej ntawm lub ntsuas cua (ntawm/offline, sijhawm ua haujlwm, thiab lwm yam). Qee zaum kuv pom tias nws mus offline ob peb zaug hauv 1 lub lis piam, los ntawm cov txheeb cais, ntau zaus nws yog vim ESP-01 tau txais kev sib txuas los ntawm wifi lossis MQTT. Tab sis tsis txhob txhawj xeeb, kuv daim duab tau suav nrog niaj hnub rov pib ESP-01 yog tias nws ua tsis tau txuas txuas rau WIFI thiab/lossis MQTT tus tswv lag luam.

Cov duab ntawm cov kauj ruam no, qhia Node-RED ntws kom ua tiav qhov no. Koj tseem tuaj yeem muab cov dej ntws los ntawm kuv nplooj ntawv github rau hauv koj Node-RED:

Kev tshaj tawm hauv Google hauv tsev tsuas yog ib qho piv txwv rau txoj haujlwm no, tab sis kuv xav tias nws yog qhov muaj txiaj ntsig tshaj plaws thiab siv tau. Koj ib txwm tuaj yeem cuam tshuam rau lwm tus mloog MQTT, lossis tseem siv IFTTT los tsav lwm yam khoom thaum dej raug kuaj pom.

Muaj kev lom zem…

Pom zoo: