Cov txheej txheem:

Tus Pab Tsev Geiger Counter Integration: 8 Kauj Ruam
Tus Pab Tsev Geiger Counter Integration: 8 Kauj Ruam

Video: Tus Pab Tsev Geiger Counter Integration: 8 Kauj Ruam

Video: Tus Pab Tsev Geiger Counter Integration: 8 Kauj Ruam
Video: Аудиокнига «Рождественская история» Чарльза Диккенса 2024, Hlis ntuj nqeg
Anonim
Image
Image
Txoj Cai Ua Haujlwm
Txoj Cai Ua Haujlwm

Hauv qhov kev qhia no kuv yuav qhia koj yuav ua li cas ntxiv cov cim kev cai rau HASS (tus pabcuam hauv tsev) tshwj xeeb tshaj yog cov txee geiger tab sis cov txheej txheem zoo ib yam rau lwm lub ntsuas ib yam nkaus.

Peb yuav siv NodeMCU pawg thawj coj saib, arduino raws geiger txee thiab twb tau teeb tsa tus pabcuam hauv tsev.

Kev koom ua ke yuav ua raws MQTT server (pej xeem lossis ntiag tug) thiab kuv yuav coj koj ib qib zuj zus nrog qhov no.

Yog tias koj tsis paub dab tsi yog tus pabcuam hauv tsev thov mus saib lawv nplooj ntawv https://www.home-assistant.io/. Nws yog lub tsev paub zoo automation platform uas tau tswj tau zoo heev thiab kho tau zoo heev.

Koj yuav kawm txog:

- kev teeb tsa qib siab rau Tsev Pabcuam

- NodeMCU (pawg thawj coj loj) thiab yuav ua haujlwm li cas nrog Arduino IDE

- OTA (tshaj qhov hloov pauv huab cua) siv Arduino IDE rau NodeMCU pawg thawj coj

- yuav ua li cas txuas cov cuab yeej txuas mus rau NodeMCU

- txhim kho tus kheej MQTT server ntawm linux (xaiv tau)

Cov kev xav yooj yim:

- koj muaj Tus Pab Tsev thiab ua haujlwm

- koj paub me ntsis txog hluav taws xob

- koj tau teeb tsa Arduino IDE

Kauj Ruam 1: Qhov Chaw thiab Cov Cuab Yeej

Qhov:

1. NodeMCU pawg thawj coj saib

2. qhob cij

3. txiv neej-txiv neej thiab txiv neej-poj niam juper xov hlau

3. usb rau micro usb cable

4. arduino geiger txee nrog serial interface

(tshawb Ebay rau "arduino geiger couter")

5. cov khoom siv hluav taws xob (xaiv cov qauv ntsuas me me)

Cov Cuab Yeej:

1. Arduino IDE

2. Lub Tsev Pabcuam tau teeb tsa

Kauj Ruam 2: Txoj Cai Ua Haujlwm

Peb lub hom phiaj yog los qhia rau ntawm HomeAssistat (HASS) kev nyeem los ntawm tus lej geiger. Ntawm ib sab peb muaj HASS server nce thiab khiav qee qhov nws yuav yog raspberry pi lossis lwm yam cuab yeej thiab ntawm lwm sab peb muaj lub txee geiger.

Geiger txee muaj qhov chaw nres nkoj txuas, ib qho kev daws teeb meem yuav yog txuas ncaj qha mus rau qhov chaw nres nkoj txuas mus rau RaspberryPi uas HASS khiav.

Qee qhov laj thawj yog vim li cas nws yuav tsis yog qhov ua tau zoo:

- tsis muaj chaw nyob ntawm lub cev

- peb muaj qee qhov lwm yam cuab yeej ntawm qhov chaw nres nkoj

- peb xav muab lub ntsuas hluav taws xob ib puag ncig uas yuav tsum tau muab tso rau sab nraud es tsis txhob siv tus lej geiger

Ok yog li peb tab tom tshawb nrhiav lwm qhov ua tau kom txuas nrog WIFI:

HASS txhawb kev nyeem ntawv cov ntaub ntawv thiab ua kom pom qhov ntawd los ntawm MQTT server, hom neeg rau zaub mov no yog qhov sib txuas me me rau cov cuab yeej me me ib lub cuab yeej tshaj tawm cov lus ntawm "ncauj lus" lwm yam mloog ntawm lub ncauj lus kom tau txais cov lus. Yog li HASS yuav mloog, thiab peb xav tau qee yam uas yuav tshaj tawm cov lus.

Peb lub sensor paub tsuas yog tham txog kab ntawv txuas ntxiv yog li peb yuav siv lub rooj tsav xwm uas tuaj yeem nyeem kab ntawv txuas thiab uas tuaj yeem txuas dua WIFI thiab tham nrog MQTT server. Ib lub rooj tsavxwm pheej yig uas ua qhov no yog NodeMCU.

NodeMCU tuaj yeem ua haujlwm nrog Arduino IDE. Daim duab yog yooj yim zoo nkauj, nws ua cov hauv qab no:

- txuas rau WIFI

- tswj hwm MQTT kev sib txuas nrog tus neeg rau zaub mov thiab rov txuas qhov txuas thaum ua tsis tiav lossis txuas nrog

- mloog cov ntaub ntawv nkag mus raws li cov lej ntawm cov lej

- thaum tus lej lej tuaj txog nws xa nws los ntawm MQTT rau cov ncauj lus tshwj xeeb

Kauj Ruam 3: Sib Sau Cov Ntaus

Sib Sau Cov Ntaus
Sib Sau Cov Ntaus

Peb yuav siv lub rooj noj mov thiab cov xov hlau yog li nws yooj yim heev, peb muaj ob peb kauj ruam:

- muab NodeMCU tso rau ntawm daim ntawv tais

- txuas lub geiger raj mus rau lub txee geiger (saib xyuas kom pom tseeb)

- VIN mus rau geiger txee +

- GND mus rau geiger txee -

- NodeMCU D7 (tus pin 13) mus rau geiger TX

- NodeMCU D8 (tus pin 15) mus rau geiger RX

- fais fab NodeMCU los ntawm micro USB los ntawm lub khoos phis tawj

Kauj ruam 4: Upload Code

Rub tawm Txoj Cai
Rub tawm Txoj Cai
Rub tawm Txoj Cai
Rub tawm Txoj Cai
Rub tawm Txoj Cai
Rub tawm Txoj Cai
Rub tawm Txoj Cai
Rub tawm Txoj Cai

Peb yuav siv Arduino IDE thiab peb yuav ua kom ntseeg tau tias peb tau teeb tsa NodeMCU board thiab Adafruit_MQTT lub tsev qiv ntawv teeb tsa.

1. Clone lub github repository: https://github.com/danionescu0/arduino thiab luam daim duab kos los ntawm cov haujlwm/HASSGeigerIntegration rau koj qhov chaw sketchbook qhov chaw

2. Qhib Arduino IDE thiab teeb tsa NodeMCU

- mus rau Cov Ntaub Ntawv -> Nyiam, hauv Tus Thawj Saib Xyuas Ntxiv URLs ntxiv https://arduino.esp8266.com/stable/package_esp8266com_index.json yog tias koj twb muaj qee yam muaj qhov tsis nco qab lawm thiab nyem ok

-los ntawm Cov Cuab Yeej -> Pawg Thawj Coj -> Tus Thawj Saib Xyuas Haujlwm hom "nodemcu" thiab xaiv qhov nkag esp8266 los ntawm ESP8266 Zej Zog, thiab nias nruab

3. Nruab Adafruit_MQTT

-mus rau Cov Cuab Yeej -> Tswj Lub Tsev Qiv Ntawv -> tshawb "Adafruit_MQTT" thiab nruab "Arduino MQTT lub tsev qiv ntawv"

4. Txuas lub USB cable hauv koj lub computer thiab teeb tsa lub rooj tsavxwm:

-mus rau Cov Cuab Yeej -> Pawg Thawj Coj -> xaiv NodeMcu 1.0

-Cov cuab yeej -> Chaw nres nkoj -> koj lub USB chaw nres nkoj

- tso lwm qhov chaw tsis hloov pauv

4. Hauv daim duab hloov pauv koj li ntaub ntawv pov thawj WIFI kom phim koj tus kheej:

#define STASSID "ssid" // Hloov nrog koj li WIFI SSID

#define STAPSK "hla" // Hloov nrog koj li WIFI password

5. Tshaj tawm daim duab kos rau koj lub rooj tsavxwm thiab tom qab kev xa rov pib dua lub rooj tsavxwm los ntawm khawm

6. Qhib cov ntawv saib, yog tias txhua yam tau mus zoo koj yuav tsum pom qee qhov tso tawm zoo li no:

Khau raj

IP chaw nyob: 192.168.1.168 OTA qhib kev Txuas rau MQTT… MQTT Txuas! {"hluav taws xob": 0.03}..

Kauj Ruam 5: teeb tsa HomeAssistant

Configure HomeAssistant
Configure HomeAssistant
Configure HomeAssistant
Configure HomeAssistant

Peb yuav xav tias koj muaj tus pabcuam hauv tsev tuaj thiab ua haujlwm. Ntawm kuv qhov system kuv muaj HASSOS version 3.12 ntawm RaspberryPi. Yog tias koj tus pab cuam hauv tsev laus dhau los lossis tshiab heev qee qhov tshwj xeeb yuav txawv. Cov ntawv qhia no ua haujlwm kom paub tseeb nrog 3.12 version.

Yog tias koj tsis muaj Lub Tsev Pabcuam teeb tsa, txheeb xyuas lawv cov ntawv qhia kev teeb tsa raug cai:

Ua ntej nce qib nrog kev teeb tsa kom ntseeg tau tias NodeMCU tau ntsaws thiab nws tshaj tawm cov ntaub ntawv.

Ok peb yuav muaj cov theem ntawm no ib yam nkaus rau kev teeb tsa:

1. Nruab "editor file" yog tias koj tsis muaj nws hauv cov ntawv qhia zaub mov, ntawm no yog cov lus qhia ua haujlwm:

2. Kho kom raug "/config/configuration.yaml" cov ntaub ntawv thiab ntxiv cov hauv qab no thiab txuag nws

- ntu mqtt yog tias koj tsis muaj nws lawm

mqtt:

broker: broker.hivemq.com kev tshawb pom: qhov tseeb pom_prefix: ha

- ntu sensors

sensor:

- platform: mqtt name: "Radiation" state_topic: "ha/radiation" unit_of_measurement: 'uSv' unique_id: "radiation" value_template: "{{value_json.radiation}}"

3. Los ntawm Kev teeb tsa -> Tswj cov neeg rau zaub mov: nias "Txheeb teeb tsa" kos cov yaml teeb tsa cov ntaub ntawv rau qhov ua yuam kev, thiab tom qab ntawd nias "rov pib dua" thiab tos kom txog thaum nws rov pib dua

4. Los ntawm Txheej Txheem -> Sab xis saum toj ntawv qhia zaub mov -> Kho UI -> nias lub pob + los ntawm hauv qab txoj cai

5. Xaiv "sensor" los ntawm daim ntawv -> hauv "entity" field search rau "sensor.radiation", hauv lub npe teb sau "Radiation" thiab nyem ok, nws yuav tsum nyob rau ntawm nplooj ntawv tam sim no

Kauj Ruam 6: Kho Koj Tus Kheej MQTT Server [Yeem Tau]

Cia peb tham me ntsis txog MQTT

"MQTT yog Client Server tshaj tawm/sau npe cov ntawv xa cov txheej txheem. Nws yog lub cev nyhav, qhib, yooj yim, thiab tsim los kom yooj yim rau siv. Cov yam ntxwv no ua rau nws zoo siv rau ntau qhov xwm txheej, suav nrog kev txwv ib puag ncig xws li kev sib txuas lus hauv Tshuab rau Tshuab (M2M) thiab Internet ntawm Yam (IoT) cov ntsiab lus uas yuav tsum muaj tus lej me me hneev taw thiab/lossis kev sib txuas hauv network yog nyob ntawm tus nqi."

Citation los ntawm kev ua haujlwm MQTT 3.1.1 qhov tshwj xeeb.

Yog li ntawd peb tuaj yeem tshaj tawm cov lus nyob rau ib qho ntawm ib sab thiab ntawm lwm sab peb tuaj yeem mloog cov lus ntawd thiab ua qee yam nrog cov ntaub ntawv. MQTT txhawb nqa "ncauj lus", cov ncauj lus yog cov hlua uas tus tswv lag luam siv los lim cov lus rau txhua tus neeg siv khoom yog li yog peb tshaj tawm cov lus rau "/hluav taws xob" lub ncauj lus tus mloog yuav tsum sau npe rau tib lub ncauj lus kom tau txais cov lus uas peb xa tuaj.

Nov yog cov lus qhia zoo txog MQTT kom ntxaws:

Siv cov neeg rau zaub mov pub dawb muaj qee qhov tsis zoo xws li:

- leej twg mloog koj lub ncauj lus yuav tau txais koj cov lus

- yog tias nws nqis qis lossis xav tau kev them nyiaj tom qab koj yuav tsis tuaj yeem siv nws (tshwj tsis yog koj them)

- yog tias leej twg tshaj tawm cov lus rau tib lub ncauj lus koj yuav tau txais lawv cov lus ib yam nkaus, lawv tuaj yeem tshaj tawm cov lus tsis sib xws thiab ua txhaum koj li kab lus HASS

Siv tus kheej server

Yog tias koj tsis xav siv cov neeg rau zaub mov pub dawb rau pej xeem koj muaj kev xaiv ntawm tus kheej server. Peb tab tom yuav nruab Mosquitto MQTT ntawm ubuntu / debian server zoo li raspberry pi lossis khoos phis tawj.

Mosquitto yog tus server uas siv MQTT raws tu qauv thiab nws yog dawb xwb.

Txhawm rau nruab nws nkag mus rau hauv koj li raspnerry pi lossis lwm yam debian raws server thiab khiav:

sudo apt hloov tshiab

sudo apt install -y mosquitto mosquitto -cov neeg siv sudo systemctl pab tau mosquitto.service

Qhov no yuav hloov kho qhov chaw cia khoom, teeb tsa cov neeg rau zaub mov mosquiito thiab cov neeg siv khoom thiab ua kom nws cov kev pabcuam ua haujlwm thaum pib

Txhawm rau kom tau txais tus IP server ua:

hostname -Ib

thiab nws yuav tso tawm qee yam xws li:

192.168.1.52 172.17.0.1 172.18.0.1

Yog li kuv tus ip yog 192.168.1.52, hauv cov lus txib hauv qab no hloov nws nrog koj tus ip

Koj tuaj yeem sim MQTT server los ntawm kev tshaj tawm cov lus thiab tau txais nws nrog lub cuab yeej console, rau ob lub dav hlau no yuav tsum qhib ib qho uas mloog cov lus, ib qho uas yuav tshaj tawm cov lus.

Ua ntej hauv lub davhlau ya nyob twg khiav cov lus txib no los mloog cov lus ntawm "/qee qhov ncauj lus"

mosquitto_sub -h 192.168.1.52 -t /qee cov ncauj lus

Qhib lwm lub davhlau ya nyob twg thiab tshaj tawm cov lus rau lub ncauj lus ntawd:

mosquitto_pub -h 192.168.1.52 -t /qee qhov ncauj lus -m '{"av noo": 74.0}'

Hauv thawj lub dav hlau koj yuav tsum pom '{"av noo": 74.0}' luam tawm.

Tshwj xeeb mloog:

- qhov teeb tsa no xav tias HASS, Mosquitto thiab NodeMCU tau txuas nrog tib lub WIFI network thiab tsis muaj txoj cai firewall thiab lawv tuaj yeem sib tham tau dawb

-Mosquitt MQTT server tsis muaj username/password, yog tias koj xav teeb tsa daim ntawv pov thawj txheeb xyuas qhov no: https://www.steves-internet-guide.com/mqtt-username-password-example/ Tsis tas li koj yuav xav teeb tsa cov ntaub ntawv pov thawj hauv Tsev Pabcuam thiab hauv daim duab arduino

Kauj Ruam 7: OTA (Tshaj Tawm Cov Cua Tshiab) rau NodeMCU

Tshaj tawm cov huab cua hloov tshiab txhais tau tias pawg thawj coj saib xyuas kev txhim kho tuaj yeem ua rau xaim xaim tsis tas yuav xav tau lub cev cable.

Arduino IDE txhawb nqa qhov ua haujlwm no rau ESP8266 series thiab qee lwm cov laug cam:

- yuav tsum tau nyem thawj zaug hla USB cable

- tsim qhov chaw nres nkoj virtual hla WIFI thiab nws tsuas pom los ntawm Arduino IDE

- tsis muaj Serial debug cov ntaub ntawv

- txhawb kev tiv thaiv nrog tus password

Txhawm rau pab OTA hauv ESP8266 kos duab ua ntej suav nrog lub tsev qiv ntawv:

#suav nrog "ArduinoOTA.h"

Kuj txhais qhov kev kos duab lo lus zais tas li:

#define SKETCHPASS "some_password"

Hauv ntu teeb tsa ntxiv cov kab no:

thaum (WiFi.waitForConnectResult ()! = WL_CONNECTED) {

Serial.println ("Kev sib txuas tsis tau tiav! Rebooting …"); ncua (5000); ESP.restart (); } ArduinoOTA.setPassword (SKETCHPASS); ArduinoOTA.onStart ( () {String type; if (ArduinoOTA.getCommand () == U_FLASH) {type = "sketch";} else {// U_FS type = "filesystem";} Serial.println ("Pib kho dua tshiab " + hom);}); ArduinoOTA.onEnd ( () {Serial.println ("\ nEnd");}); ArduinoOTA.onProgress ( (tsis tau kos npe kev nce qib, tsis tau kos npe tag nrho) {Serial.printf ("Kev nce qib:%u %% / r", (kev nce qib / (tag nrho / 100)));}); ArduinoOTA.onError ( (ota_error_t yuam kev) {Serial.printf ("Yuam kev [%u]:", yuam kev); yog (yuam kev == OTA_AUTH_ERROR) {Serial.println ("Auth Failed");} ntxiv yog (yuam kev == OTA_BEGIN_ERROR) {Serial.println ("Pib Failed");} lwm qhov yog (yuam kev == OTA_CONNECT_ERROR) {Serial.println ("Txuas Tsis Tau");} lwm qhov yog (yuam kev == OTA_RECEIVE_ERROR) {Serial.println (" Tau Txais Ua Tsis Tau ");} lwm qhov yog (yuam kev == OTA_END_ERROR) {Serial.println (" Xeem Ua Ntej ");}}); ArduinoOTA.begin (); Serial.print ("IP chaw nyob:"); Serial.println (WiFi.localIP ());

Thiab hauv ntu ntu ntxiv kab no:

ArduinoOTA.handle ();

Tom qab koj tus lej pib tso tom qab lub rooj tsav nkoj pib koj yuav tsum pom hauv Arduino IDE hauv Cov Cuab Yeej-> Chaw seem ob hom chaw nres nkoj:

Serial ports: /dev /ttyUSB0 (piv txwv)

Network chaw nres nkoj: esp8266-xxxxx ntawm 192.168.1.xxx

Tam sim no koj tuaj yeem xaiv qhov chaw nres nkoj hauv network thiab xa cov duab kos rau tej thaj chaw deb, koj yuav tau txais kev ceeb toom rau tus lej kos duab (tus uas koj tau hais tseg nyob rau saum toj no)

Kauj Ruam 8: Xaus, Ua Haujlwm Yav Tom Ntej

Cov ntawv qhia no tuaj yeem hloov kho yooj yim kom xa cov ntaub ntawv hais txog lwm hom kev ntsuas:

- yog tias koj lub sensor tau txais kev txhawb nqa ncaj qha los ntawm NodeMCU los ntawm lub tsev qiv ntawv, tsuas yog sau cov ntaub ntawv los ntawm lub sensor thiab ncaj qha thawb nws los ntawm MQTT

- yog tias lub tsev qiv ntawv sensor tsis ua haujlwm nrog NodeMCU tab sis nws tsuas yog rau Arduino ces xa koj cov cai mus rau arduino, tso tawm tus nqi dhau los ntawm kab ntawv txuas thiab nyeem nws hauv NodeMCU thiab thawb nws (ib yam li peb tau ua nrog geiger txee)

Peb tuaj yeem hloov kho nws kom xa cov ntaub ntawv los ntawm ntau lub cim zoo li:

- txuas koj lub ntsuas pa mus rau NodeMCU

- cov ntaub ntawv pov npav los ntawm txhua lub sensor

- rau txhua tus sensor tshaj tawm cov ntaub ntawv rau lwm lub ncauj lus

- hauv HASS txhais ntau yam ntsuas (zoo li peb tau ua nrog geiger) uas yuav mloog cov ncauj lus sib txawv

Pom zoo: