Cov txheej txheem:

Dej Los Ntshav Sensor ntawm ESP8266 + Micropython + Domoticz: 16 Cov Kauj Ruam (nrog Duab)
Dej Los Ntshav Sensor ntawm ESP8266 + Micropython + Domoticz: 16 Cov Kauj Ruam (nrog Duab)

Video: Dej Los Ntshav Sensor ntawm ESP8266 + Micropython + Domoticz: 16 Cov Kauj Ruam (nrog Duab)

Video: Dej Los Ntshav Sensor ntawm ESP8266 + Micropython + Domoticz: 16 Cov Kauj Ruam (nrog Duab)
Video: Lub Zog Nruab Nrog (Hmong Dubbed) 2024, Hlis ntuj nqeg
Anonim
Dej Leakage Sensor ntawm ESP8266 + Micropython + Domoticz
Dej Leakage Sensor ntawm ESP8266 + Micropython + Domoticz
Dej Leakage Sensor ntawm ESP8266 + Micropython + Domoticz
Dej Leakage Sensor ntawm ESP8266 + Micropython + Domoticz

Qee lub sij hawm dhau los, kuv tus poj niam hais kom kuv ua lub ntsuas dej ntws tawm. Nws ntshai tias lub qhov dej hauv chav rhaub dej tuaj yeem xau tau, thiab dej yuav nyab rau hauv pem teb ntoo tshiab. Thiab kuv yog tus kws tshaj lij muaj tswv yim tau ua lub ntsuas kom ua.

Los ntawm kuv li 15 xyoos ntawm kev paub ua kws kho mob, kuv paub tias txoj hauv kev yooj yim tshaj plaws ntawm kev kuaj dej yog hlau pins luv los ntawm dej. Lub hauv paus ntsiab lus ntawm kev ua haujlwm ntawm cov ntsuas yooj yim tshaj plaws yog tias dej yuav tsum luv ob (lossis ntau dua) cov hlau hlau, thiab sai li sai tau nws tshwm sim, tswb tswb.

Kauj ruam 1: Kho vajtse

Kho vajtse
Kho vajtse

Rau qhov haujlwm no peb xav tau:

1. ESP8266 - 01 tus qauv

2. HT7333 3.3V MS Low Dropout Linear Regulator Power Supply modu

Peb xav tau cov qauv no txhawm rau txo qhov hluav taws xob los ntawm roj teeb mus rau qib uas lees paub rau ESP8266. Raws li daim ntawv yuav tsum muaj 3V txog 3.6V cov tswv yim. Cov qauv no muab rau peb 3.3V.

3. Roj teeb Kuv siv 3, 7V Li-ion 400mAh roj teeb. Qhov tseeb koj tuaj yeem siv lwm qhov peev txheej tsim nyog. 18650 roj teeb yog qhov kev xaiv zoo thiab. Thaum koj xaiv lub roj teeb nco ntsoov tias ESP "noj" txog 200mA zoo li txuas rau WiFi network, thiab kwv yees li 60mA yog siv thaum pawg thawj coj saib cov ntaub ntawv xa mus rau server.

4. TP4056 Lipo roj teeb them nyiaj txiag.

5. Pololu mini pushbutton Power Switch Txaus luag heev. Nws cia peb hloov ESP module tsuas yog thaum kuaj pom dej. Koj tsis tas yuav khaws ESP ON. Yog li nws yog qhov zoo rau kev txuag lub roj teeb.

6. Vaj Tsev 7. Ob chav micro-hloov ON-OFF. Ib kab ua haujlwm hloov lub cuab yeej rau. Kab thib ob yog rau kev sim - nws luv luv Circuit Court tsis muaj dej, tsuas yog qhia rau peb paub tias lub cuab yeej ua haujlwm lossis tsis ua.

8. Raspberry Pi micro computer

Kuv siv Raspberry Pi Zero. Nws muaj zog txaus rau khiav Domoticz server.

Kauj ruam 2: Software

Hauv koj lub PC:

1. esptool tau teeb tsa, rau kev tshem tawm cov qauv thiab flashing firmware

2. Ampy tau teeb tsa, kom ua rau pom koj lub program

3 Python 3.6 lossis siab dua pom zoo

4. Txhua tus lej editor koj xav tau. Yooj Yim - Python IDLE uas ib txwm tau teeb tsa nrog Python. Kuv tab tom siv Pycharm / Atom lossis Anaconda Spyder Ntawm raspberry Pi

5. Domoticz server tau teeb tsa ntawm Raspberry Pi (lossis ntau lub PC hauv Windows lossis Linux)

Kauj Ruam 3: Npaj Raspberry Pi - Nruab Domoticz

Yog li, coj koj li RPi thiab teeb tsa lub operating system haum rau khiav Domoticz server.

Koj tuaj yeem ua raws cov lus qhia no.

Kuv siv Raspbian Stretch nrog Desktop los ntawm no:

Cov kauj ruam tom ntej yog teeb tsa Domoticz server rau hauv koj lub PC. Koj tuaj yeem siv cov lus qhia ntawm no lossis ntawm no:). Tsis txhob ntshai, nws tsis nyuaj li. Pom tseeb koj yuav tsum tau khiav hauv koj lub davhlau ya nyob twg:

curl -L install.domoticz.com | sudo tsoo

Thiab qhov ntawd yog nws:) ntau dua lossis tsawg dua. Kev teeb tsa Domoticz

Tam sim no tias peb cov neeg rau zaub mov tau npaj tiav, peb tuaj yeem nkag mus los ntawm txhua lub vev xaib, suav nrog los ntawm ib lub ntsiav tshuaj los ntawm kev nkag mus rau URL hauv qab no: https:// IP_domoticz: 8080

Kauj Ruam 4: Teeb Domoticz

Kev teeb tsa Domoticz
Kev teeb tsa Domoticz

Tam sim no tias peb cov neeg rau zaub mov tau npaj tiav, peb tuaj yeem nkag mus los ntawm txhua lub vev xaib, suav nrog los ntawm cov ntsiav tshuaj los ntawm kev nkag mus rau URL hauv qab no: https:// IP_domoticz: 8080

Kauj Ruam 5: Kho Cov Ntawv Thov

Kho Cov Ntawv Thov
Kho Cov Ntawv Thov
Kho Cov Ntawv Thov
Kho Cov Ntawv Thov

Muaj ntau daim ntawv thov teeb tsa uas tuaj yeem teeb tsa los ntawm Teeb | Cov ntawv qhia zaub mov.

Kev teeb tsa cov ntawv qhia zaub mov nrog ntau lub tab tso cai rau koj nkag mus rau tus kheej tsis tsim nyog rau kev ua haujlwm zoo dua qub. Tom qab nkag mus rau cov ntaub ntawv hauv cov teb, koj yuav tsum txuag lawv los ntawm nias lub pob liab liab "Thov Chaw". Tom qab qhov kev ua no txhua lo lus zais, uas tau khoob ntawm qhov nkag mus thawj zaug, yuav tshwm nrog cov hlua ntev ntawm lub hnub qub, txawm tias lawv tsis tau siv los.

Tom qab koj tau teeb tsa lub ntsiab ntawm "System" nplooj ntawv, nyem "Cov ntawv ceeb toom". Ntawm no peb yuav tsum hloov kho yam kev ceeb toom twg peb yuav siv.

Kauj Ruam 6: Teeb Cov Ntawv Ceeb Toom

Teeb Cov Ntawv Ceeb Toom
Teeb Cov Ntawv Ceeb Toom

Cov ntawv ceeb toom tuaj yeem xa mus piv txwv thaum hloov pauv raug thawb, kev siv hluav taws xob ntau dhau, kub kom siab thiab rau ntau qhov kev xaiv.

Hauv peb cov ntaub ntawv ceeb toom yuav tsum xa sai li sai tau thaum dej tau pom los ntawm lub ntsuas. Yog li tsuas yog hloov cov ntawd, koj xav siv. Kuj ib txwm koj xav tau tus lej API rau ceeb toom kom ua haujlwm. Ua ntej me ntsis, Kuv yuav hais tias kuv sim Pushover, Pushsafer thiab Pushbullet. Thiab kuv nyob nrog Pushover. Thaum kawg kuv yuav qhia vim li cas.

Ob peb lo lus hais txog kev ceeb toom ua haujlwm li cas. Koj yuav tsum muaj tus as khauj ntawm Pushbullet, Pushover lossis lwm nplooj ntawv uas koj xav siv. Tsis tas li koj yuav xav tau app ntawm koj lub xov tooj ntawm tes lossis PC.

Tau txais API tus yuam sij, thiab ntxig rau ntawm nplooj ntawv saum toj no. Koj tuaj yeem sim ceeb toom los ntawm txhaj "Test". Yog tus yuam sij API raug, koj yuav tsum tau txais ntawv ceeb toom sim rau koj lub xov tooj ntawm tes.

Sai li sai tau lub ntsuas dej nkag siab, ESP hloov pauv thiab xa thov mus rau Domoticz server hauv JSON hom ntawv. Tshaj yog tias cov xwm txheej ua rau muaj kev tshwm sim (xa ntawv ceeb toom rau koj lub xov tooj ntawm tes) txaus siab, Domoticz xa ntawv ceeb toom.

Tom qab ntawd kuv yuav rov qab los rau "xwm txheej".

Kauj Ruam 7: Teeb Kev Sib Txuas Lus rau Cov Khoom Kho Vajtse (s)

Teeb Kev Sib Txuas Lus rau Cov Khoom Kho Vajtse (s)
Teeb Kev Sib Txuas Lus rau Cov Khoom Kho Vajtse (s)
Teeb Kev Sib Txuas Lus rau Cov Khoom Kho Vajtse (s)
Teeb Kev Sib Txuas Lus rau Cov Khoom Kho Vajtse (s)
Teeb Kev Sib Txuas Lus rau Cov Khoom Kho Vajtse (s)
Teeb Kev Sib Txuas Lus rau Cov Khoom Kho Vajtse (s)

Ua ntej koj tuaj yeem siv daim ntawv thov Domoticz los tswj cov cuab yeej lossis nyeem cov cim koj yuav tsum teeb tsa kev sib txuas lus rau cov cuab yeej kho vajtse (s). Xaiv Teeb | Kho vajtse ntxiv hardware. Cov cuab yeej yuav tsis tshwm sim kom txog thaum tsim kho vajtse tsim nyog.

Daim ntawv thov Domoticz txhawb nqa ntau yam khoom siv kho vajtse ib txwm muaj. Hauv peb rooj plaub los nyeem peb lub ntsuas dej nyab peb yuav tsum tau ntxiv qhov hu ua "Dummy" kho vajtse los ntawm cov npe khoom kho vajtse.

Thaum kho vajtse ntxiv qhov kev saib xyuas ntawm txhua qhov kho vajtse tau hais tseg yuav raug qhia. Kho vajtse tuaj yeem xiam lossis tshem tawm.

Kho vajtse tshiab yuav tsum muaj nyob hauv cov npe thiab yuav tsum muaj lub pob "Tsim Kev Pom Zoo Virtual".

Nyem rau lub pob no thiab xaiv Sensor Hom "Alert". Tam sim no peb yuav tsum ntxiv cov cuab yeej hauv Domoticz los ua haujlwm.

Kauj Ruam 8: Ntxiv Cov Khoom Siv hauv Domoticz kom dhau los ua haujlwm

Ntxiv Cov Khoom Siv hauv Domoticz los Ua Haujlwm
Ntxiv Cov Khoom Siv hauv Domoticz los Ua Haujlwm
Ntxiv Cov Khoom Siv hauv Domoticz los Ua Haujlwm
Ntxiv Cov Khoom Siv hauv Domoticz los Ua Haujlwm
Ntxiv Cov Khoom Siv hauv Domoticz los Ua Haujlwm
Ntxiv Cov Khoom Siv hauv Domoticz los Ua Haujlwm

Thov nco tseg tus lej hauv qab no "IDX". Nov yog qhov tshwj xeeb siv rau lub cuab yeej no thiab peb xav tau nws tom qab hauv peb cov ntawv Python txhawm rau hais qhia. Hauv qhov no tus lej IDX yog 1.

Pab kom lub cuab yeej los ntawm nyem lub xub xub ntsuab ntawm sab laug (ntawm kuv daim duab hauv qab no nws yog xiav, vim hais tias ntawm lub cuab yeej enabed).

Sau lub npe ntawm lub cuab yeej, thiab nyem "ntxiv".

Nkag mus rau cov ntawv qhia zaub mov "Utilities" thiab koj lub cuab yeej yuav tsum tau teev nyob ntawd.

Tam sim no peb yuav tsum tau program "xwm txheej" rau peb lub sensor. Nws txhais tau tias, peb yuav tsum qhia rau tus neeg rau zaub mov, yuav ua li cas yog tias nws tau txais cov lus los ntawm lub sensor. Thiab nws tau hais tias qhov chaw nyuaj tshaj plaws rau kuv:).

Kauj Ruam 9: Nws Tsis Ua Haujlwm Li No …

Nws Tsis Ua Haujlwm Li No …
Nws Tsis Ua Haujlwm Li No …

Kuv pib los ntawm kev sim ua qhov kev tshwm sim ntawm / ntaus ntawv / nplooj ntawv. Qhov no hauv qab no tsis yog kuv li, tab sis nws zoo los ua piv txwv.

Yog tias koj ntseeg tias koj yuav txheeb xyuas qee lub thawv ntawv thiab nws yuav ua haujlwm, koj yuam kev:) Nws tsis ua haujlwm li no. Kuv xav tias qhov tshwj xeeb ntawm no tseem tsis tau tiav. Tsis txhob hnov qab - nws yog qhov qhib software. Ok, tom qab ob peb teev kuv pom cov tshuaj. Peb yuav tsum siv "Cov Txheej Txheem" los ntawm "Teeb" cov ntawv qhia zaub mov nco-down.

Tom qab txhaj "Txheej xwm" koj tuaj yeem tsim koj li kev tshwm sim. Koj tuaj yeem ua nws yuav sau cov lej hauv Python lossis LUA, lossis tsuas yog siv qhov khoom hu ua "Blockly". Kuv xaiv los siv Blockly. Muaj ob txoj hauv kev yuam tus neeg rau zaub mov ua qhov koj xav tau.

Kauj Ruam 10: Tsim Kev tshwm sim hauv Txoj Cai Zoo 1

Tsim Kev tshwm sim hauv Txoj Cai Zoo 1
Tsim Kev tshwm sim hauv Txoj Cai Zoo 1

1. Ua tiav cov ntawv sab nraud ntawm "Txheej Txheem", los ntawm kev siv Blockly lus "Pib sau ntawv"

Qhov no ua haujlwm rau kuv ntawm Windows tshuab zoo kawg nkaus. Tab sis kuv tsis ua tiav nrog qhov no ntawm Raspbian ntawm kuv Raspberry Pi. Kuv xav tias muaj teeb meem nrog kev tso cai.

Kauj Ruam 11: Tsim Kev tshwm sim hauv Txoj Cai Zoo 2

Tsim Kev tshwm sim hauv Txoj Cai Zoo 2
Tsim Kev tshwm sim hauv Txoj Cai Zoo 2

2. Use "Xa ntawv ceeb toom nrog kev kawm" lus. Nws ua haujlwm ntawm Raspbian. Qhov kev xaiv no txhawb nqa xa ntawv ceeb toom rau Pushsafe thiab Pushover.

Qhov zoo ntawm kev siv 1st txoj kev, yog tias nws yoog raws ntau dua. Koj tuaj yeem xaiv lub cim kom pom ntawm koj cov zaub, suab thiab lwm yam. Kuv "kev tshwm sim" tau qhia ntawm daim duab saum toj no.

Tom ntej no, cia qhov program ESP module.

Kauj Ruam 12: Programming ESP8266-01 Module

Programming ESP8266-01 Module
Programming ESP8266-01 Module

Cia peb pib los ntawm nyem peb lub ESP8266 module. Feem ntau cov modules los nrog lub Hoobkas tsim khoom. nws tuaj yeem sib txuas lus nrog cov qauv los ntawm kev siv hu ua AT cov lus txib. Thiab qhov software no tsis pub siv cov qauv xws li cov tswj ib leeg. Txhawm rau siv lawv zoo li cov tswj ib leeg peb yuav tsum tau lwv lub Hoobkas firmware thiab teeb tsa ib qho tshiab.

Txhawm rau ua qhov no peb yuav siv esptool. Tshaj li qhov peb xav tau txuas peb cov qauv rau PC kom tshem tawm cov firmware. Txhawm rau ua qhov no koj xav tau TTL hloov pauv + ob peb yam ntxiv. Tab sis muaj txoj hauv kev yooj yim dua:). Tsuas yog yuav ntawm aliexpress lossis ebay USB rau ESP8266 ESP-01 Wi-Fi Adapter Module w/ CH340G Tsav Tsheb.

Txuas tus ESP8266 tus qauv rau hauv TTL hloov pauv raws li qhia hauv daim duab, thiab txuas nws mus rau USB chaw nres nkoj.

Yog tias koj muaj tus hloov pauv tib yam li kuv, tom qab ntawd los ntawm nws tus kheej koj yuav tsum hloov pauv mus rau "Prog" txoj haujlwm. Nrhiav qhov twg esptool tau teeb tsa (ib txwm nyob qhov twg zoo li C: / Program Files (x86) Python36-32 / Scripts.

Tau kawg xaiv qhov chaw nres nkoj raug. Hauv kuv qhov xwm txheej nws yog COM5. Koj tuaj yeem tshawb xyuas qhov chaw nres nkoj uas ESP tau teeb tsa los ntawm Tswj vaj huam sib luag - Txheej Txheem - Tus Thawj Tswj Ntaus Ntawv.

Nruab firmware (Kuv coj nws los ntawm no: https://micropython.org/download#esp8266) los ntawm kev ntaus ntawv:

nab hab sej esptool.exe --port COM5 --baud 460800 write_flash --flash_size = ntes 0 C: / path_to_firmware / esp8266-20180511-v1.9.4.bin

Ok, tam sim no peb tau npaj rau upload cov ntawv micropython rau ESP8266.

Kuv tab tom siv Adafruit MicroPython Tool (ampy) rau qhov no.

Tab sis niaj hnub no muaj lwm txoj hauv kev hu ua Esplorer. Nov yog app nrog cov neeg siv cuam tshuam, tso cai rub tawm cov ntaub ntawv rau ESP cov qauv.

Koj tuaj yeem pom cov lus qhia yuav ua li cas rau nruab ampy ntawm no. Yog li, muab qhov hloov pauv ntawm TTL hloov mus rau "UART" txoj haujlwm. Peb yuav tsum upload cov ntaub ntawv:

  • wifimgr.py - tus tswj hwm wifi rau txuas rau wifi network
  • main.py - peb tsab ntawv tseem ceeb

Hauv kab hais kom ua hom: ampy --port COM5 muab C: / path rau koj cov ntaub ntawv

Ntaus "enter". Tom qab ob peb feeb koj yuav tsum pom kab hais kom ua. Nws txhais tau hais tias cov ntaub ntawv tau muab rub tawm. Koj tuaj yeem tshawb xyuas cov npe ntawm cov ntaub ntawv ntawm ESP los ntawm ampy hais kom ua:

ampy --port COM5 ls

Los ntawm kuv qhov kev paub nws zoo dua los upload main.py tom qab koj tau rub tawm txhua cov ntaub ntawv tsim nyog. nws yog li ntawd, vim tias sai li sai tau koj yuav upload main.py - ESP8266 module yuav rov pib dua thiab pib ua haujlwm main.py cov ntaub ntawv. Yog li hauv qhov no yog tias koj sim xa lwm cov ntawv, qee zaum txheej txheem upload yuav ua tsis tiav. Tab sis nws tsis txhais tau tias txhua yam ploj:), tsuas yog sim zaum ob, thiab koj yuav ua tiav (dua, los ntawm kuv qhov kev paub dhau los).

Txhua cov ntaub ntawv rau txoj haujlwm no muaj nyob ntawm no:

Kauj Ruam 13: Txuas rau Koj Lub Network WiFi. Tau ceeb toom

Txuas rau Koj Lub Network WiFi. Tau ceeb toom
Txuas rau Koj Lub Network WiFi. Tau ceeb toom
Txuas rau Koj Lub Network WiFi. Tau ceeb toom
Txuas rau Koj Lub Network WiFi. Tau ceeb toom

yog tias txhua yam ua tau zoo, rov pib dua tus qauv, rov txuas lub TTL hloov mus rau USB chaw nres nkoj ntawm koj lub PC.

Tom qab ESP pib, nrhiav WiFi network tshiab hu ua "Wifimanager". Txuas rau nws nrog koj lub PC lossis xov tooj, tom qab ntawd mus rau IP chaw nyob 192.168.4.1.. Ntawm no koj tuaj yeem txuas koj li ESP mus rau WiFi network hauv zos. Xaiv WiFi network koj yuav siv, ntaus tus password, ntaus "Xa".

Yog tias txhua yam raug, koj yuav pom cov lus "ESP ua tiav txuas nrog XXXX network". Koj ESP tam sim no txuas nrog koj lub network WiFi thiab npaj tau. Thaum nws txuas nrog WiFi nws yuav txuas rau Domoticz server. Shorty koj yuav tsum tau txais ntawv ceeb toom ntawm koj lub xov tooj ntawm tes.

Koj tuaj yeem taug qab cov txheej txheem hauv "Teeb"/"Log".

Ua lia!:) Nws ua haujlwm. Tam sim no peb tuaj yeem npaj ua txhua ntu ua ke, raws li daim duab thaiv hauv qab no.

Kauj Ruam 14: Thaiv Daim Duab

Thaiv daim duab
Thaiv daim duab

Tsis muaj ntau yam hais txog daim duab no. Yooj yim heev. Hloov lub zog nrog S1 hloov. Cov cuab yeej sawv hauv lub xeev kom txog thaum cov dej luv "Dej sensor" pins. Tom qab ntawd "Pololu board" hloov pauv, thiab muab lub zog rau qhov hloov pauv hluav taws xob. Lub zog hluav taws xob no raws li HT7333 nti, hloov qhov hluav taws xob kom ruaj khov 3.3V rau ESP8266. Tom ntej ESP hloov pauv, thiab xa xov mus rau Domoticz server.

Kauj Ruam 15: Cov txiaj ntsig thiab Cov Lus Xaus

Cov txiaj ntsig thiab Cov lus xaus
Cov txiaj ntsig thiab Cov lus xaus
Cov txiaj ntsig thiab Cov lus xaus
Cov txiaj ntsig thiab Cov lus xaus
Cov txiaj ntsig thiab Cov lus xaus
Cov txiaj ntsig thiab Cov lus xaus
Cov txiaj ntsig thiab Cov lus xaus
Cov txiaj ntsig thiab Cov lus xaus

Nws ua haujlwm. Kev xa ntawv ceeb toom siv sijhawm ntev txog 10 vib nas this: txuas rau WiFi, xa ntawv ceeb toom, tau txais xov xwm ceeb toom rau koj lub xov tooj.

Kuv tau teeb tsa lub ntsuas cua kom xa lub tswb txhua 30s, yog tias pom muaj dej. Lub sensor tuaj yeem xa mus txog 5 - 6 cov ntawv ceeb toom kom txog thaum lub roj teeb yuav raug tso tawm. Cov cuab yeej zoo li no tseem tuaj yeem siv los txiav txim qib dej. Yam kuv xav txhim kho.

1. Kom nws ua haujlwm sai dua. Kuv xav tias kuv yuav sim siv ESP-Tam sim no thev naus laus zis, uas cia kuv txuas ntau ESPs ncaj qha. Hauv qhov no kev siv hluav taws xob thaum lub sijhawm sib txuas yog tsawg heev thiab nws nrawm dua. Yog li lub tswv yim yog siv ib qho ESP zoo li lub hub rau txuas lwm ESPs.

2. Siv lub roj teeb qib tswb. Tam sim no koj tsis tuaj yeem paub tias muaj lub zog txaus los xa xov ceeb toom lossis tsis yog. Kuv xav tias nyob rau tiam tom ntej ntawm lub ntsuas cua no yuav muaj lub pob tshwj xeeb rau ntsuas cov roj teeb.

Tus neeg siv yuav tsum nias lub pob, thiab qib roj teeb yuav raug qhia.

Pom zoo: