Cov txheej txheem:

Kev Tswj Chaw Taws Teeb thiab Kev Tshawb Fawb Duab hla MQTT: 8 Kauj Ruam
Kev Tswj Chaw Taws Teeb thiab Kev Tshawb Fawb Duab hla MQTT: 8 Kauj Ruam

Video: Kev Tswj Chaw Taws Teeb thiab Kev Tshawb Fawb Duab hla MQTT: 8 Kauj Ruam

Video: Kev Tswj Chaw Taws Teeb thiab Kev Tshawb Fawb Duab hla MQTT: 8 Kauj Ruam
Video: Tswv Yexus lub neej thaum pib txug thaum xaus 2024, Kaum ib hlis
Anonim
Kev Tswj Chaw Taws Teeb thiab Kev Tshawb Fawb Duab hla MQTT
Kev Tswj Chaw Taws Teeb thiab Kev Tshawb Fawb Duab hla MQTT

Nyob zoo.

Hnub no kuv xav tham txog yuav ua li cas thiaj ua lub chaw taws teeb tswj thiab saib xyuas qhov system uas tuaj yeem siv tau, piv txwv li, los tswj lub qhov rooj qhov rooj, teeb pom kev zoo, cua sov, tswj lub siab, ntsuas kub thiab ntau yam ntxiv. Tab sis lub ntsiab tseem ceeb ntawm cov kab ke no yog tias koj tuaj yeem tau txais cov duab los ntawm cov khoom siv nyob deb. Ua ntej koj pib zaj dab neeg, luv luv lus qhia. Ua ntej kuv xav ua kom lub koos pij tawj saib xyuas siv lub Arduino M0-SD sib xws, lub VC0706 lub koob yees duab thiab 3G/GPRS/GSM/GPS daim thaiv rau Arduino. Arduino M0 -SD lub rooj sib tham tau xaiv los ntawm cov xwm txheej uas nws yooj yim heev rau kev ua haujlwm (ib yam li Arduino UNO), kev siv hluav taws xob yog 3.3V - qhov no yooj yim heev rau kev ua haujlwm nrog VC0706 lub koob yees duab, ntau ROM thiab RAM, ntau qhov chaw nres nkoj UART, cais qhov chaw nres nkoj virtual ntawm USB, tab sis qhov txiaj ntsig tseem ceeb yog muaj micro SD txuas ncaj qha rau ntawm lub rooj tsavxwm (Nws yooj yim heev rau khaws cov ntaub ntawv ntau, xws li cov duab).

3G/GPRS/GSM/GPS daim thaiv rau Arduino yog qhov yooj yim heev rau kev siv nrog Arduino M0-SD pawg thawj coj. Muaj ntau lub tsev qiv ntawv hauv Is Taws Nem, nrog rau ntau yam piv txwv rau kev ua haujlwm nrog daim ntaub thaiv no. Cov ntaub ntawv hloov pauv tus nqi (3G) ntau dua li ntawm GPRS cov ntaub thaiv npog (tshwj xeeb tshaj yog yooj yim rau xa cov duab). Qhov muaj ntawm GPS module yog qhov txiaj ntsig ntxiv.

Kuv xaiv tus nqi qis los ntawm tus neeg siv xov tooj ntawm tes rau cov ntaub ntawv (duab) xa hauv Is Taws Nem. Tab sis cov lus nug tau tshwm sim: yuav xa cov ntaub ntawv li cas? MMS? FTP? Yuav ua li cas thiaj tau txais kev ceeb toom txog kev tau txais cov ntaub ntawv (duab)? Raws li qhov tshwm sim, kuv tau txiav txim siab xa cov ntaub ntawv (duab) rau e-mail thiab saib cov tsiaj ntawv los ntawm daim ntawv thov teeb tsa ntawm lub xov tooj ntawm tes. Nws muab tawm kom yooj yim heev!:-) Txoj haujlwm tiav tuaj yeem pom ntawm qhov txuas no.

Kuj tseem muaj qhov haujlwm zoo sib xws rau Arduino UNO los ntawm kev siv.

Tom qab ntawd kuv txiav txim siab nthuav kev ua haujlwm ntawm kuv lub cuab yeej. Piv txwv li, ntxiv lub peev xwm los tswj LEDs (txawm hais tias qhov tseeb muaj peev xwm ua tau dav dua). E-mail rau qhov no tsis tsim nyog heev. Kev xaiv SMS yog kim thiab tsis xis nyob. Thiab tom qab ntawd kuv tau kawm txog MQTT. Kuv yuav tsis piav qhia nws yog dab tsi. Cia kuv tsuas hais: Qhov no yog qhov zoo tshaj plaws!:-) Nrog kev pab los ntawm MQTT, koj tuaj yeem sib pauv tsis yog cov lus, tab sis kuj yog cov ntaub ntawv binary (duab). Hauv daim ntawv thov rau lub xov tooj, koj tuaj yeem yooj yim tsim koj tus kheej lub interface.

Kuv tau saib ua piv txwv ntawm kev ua raws li MQTT raws tu qauv rau kuv 3G/GPRS/GSM/GPS daim thaiv (SIM5320) thiab, hmoov tsis, tsis pom qhov ua tiav uas kuv xav tau. Tab sis qhov ntawd tsis tau tso kuv ib leeg. Kuv txiav txim siab los ntawm nws tus kheej siv qhov tsim nyog ua haujlwm. Raws li qhov tshwm sim, kuv tau tswj los tsim cov cuab yeej uas tau tswj hwm (qhia los ntawm peb lub LEDs) hla MQTT los ntawm daim ntawv thov teeb tsa ntawm lub xov tooj ntawm tes, thiab tseem xa ib daim duab rau lub xov tooj ntawm kev hais kom ua los ntawm lub xov tooj. (Kuv yuav qhia koj qhov zais cia uas kuv tsis tau pom dua ib qho piv txwv ntawm kev xa cov duab los ntawm MQTT broker ua ntej thiab tau ua nws thawj zaug. yog li, kuv tshaj tawm kom ncaj mus rau thawj qib - cov npe ntawm cov khoom tsim nyog.

Kauj Ruam 1: Daim Ntawv Teev Npe

Cov npe ntawm Cheebtsam
Cov npe ntawm Cheebtsam
Cov npe ntawm Cheebtsam
Cov npe ntawm Cheebtsam
Cov npe ntawm Cheebtsam
Cov npe ntawm Cheebtsam
Cov npe ntawm Cheebtsam
Cov npe ntawm Cheebtsam

Peb xav tau cov khoom ntxiv:

1) Arduino M0-SD tau tshaj.

2) TTL-lub koob yees duab VC0706.

3) 3G/GPRS/GSM/GPS daim thaiv rau Arduino.

4) Liab, ntsuab, daj LEDs, 3 tus tiv thaiv (100-500 Ohm), xov hlau, tus pin txuas txuas nrog 2.54 hli suab.

5) AC-DC zog adapter (6V 1A), 3G kav hlau txais xov, thiab lwm yam.

Kauj Ruam 2: Npaj Lub Koob Yees Duab

Kev Npaj Lub Koob Yees Duab
Kev Npaj Lub Koob Yees Duab
Kev Npaj Lub Koob Yees Duab
Kev Npaj Lub Koob Yees Duab
Kev Npaj Lub Koob Yees Duab
Kev Npaj Lub Koob Yees Duab

Lub koob yees duab muaj qhov tso tawm RS-232 rau kev txuas ncaj qha rau PC. Nws yog qhov tsim nyog kom tshem tawm MAX232 (RS-232 hloov pauv) thiab kaw cov ntawv sib txuas ntawm cov koob sib xws 7-10 (TX), 8-9 (RX).

Rau-xaim cable uas tuaj nrog lub koob yees duab yuav tsum tau rov kho dua me ntsis:

  • Tshem ob lub xov hlau los ntawm qhov txuas.
  • Rearrange liab (+ 5V) thiab dub (GND) xov hlau raws li qhia hauv daim duab.

Ntawm qhov kawg ntawm cov xov hlau yuav tsum tau muab cov lus qhia ntxaws zoo li "poj niam".

Kauj Ruam 3: Kev Npaj Ua Tau Zoo Arduino M0-SD

Kev Npaj Ua Tau Zoo Tshaj Arduino M0-SD
Kev Npaj Ua Tau Zoo Tshaj Arduino M0-SD
Kev Npaj Ua Tau Zoo Tshaj Arduino M0-SD
Kev Npaj Ua Tau Zoo Tshaj Arduino M0-SD
Kev Npaj Ua Tau Zoo Tshaj Arduino M0-SD
Kev Npaj Ua Tau Zoo Tshaj Arduino M0-SD

Raws li tau hais dhau los, kev sib xyaw Arduino M0-SD yog kho vajtse thiab software sib xws nrog thawj Arduino M0, tab sis nws kuj tseem muaj lub hauv microSD txuas rau txuas daim npav nco.

Txhawm rau txuas lub koob yees duab mus rau Arduino M0-SD sib xws ntawm lub rooj tsavxwm nws yog qhov tsim nyog yuav tsum txuas lub qhov txuas txuas mus rau lub dav hlau TXD, RXD (txuas X6) raws li qhia hauv daim duab. Qhov chaw nres nkoj no sib phim rau "Serial".

Dawb (Lub Koob Yees Duab RX) thiab daj (Lub koob yees duab TX) cov xov hlau los ntawm lub koob yees duab yuav tsum txuas nrog rau lub dav hlau ntawm TXD thiab RXD (txuas X6) raws li qhia hauv daim duab.

Kauj Ruam 4: Kev npaj 3G/GPRS/GSM/GPS Shield SIM5320

Kev npaj ntawm 3G/GPRS/GSM/GPS Shield SIM5320
Kev npaj ntawm 3G/GPRS/GSM/GPS Shield SIM5320
Kev npaj ntawm 3G/GPRS/GSM/GPS Shield SIM5320
Kev npaj ntawm 3G/GPRS/GSM/GPS Shield SIM5320
Kev npaj ntawm 3G/GPRS/GSM/GPS Shield SIM5320
Kev npaj ntawm 3G/GPRS/GSM/GPS Shield SIM5320

Ua ntej txhim kho daim npav SIM hauv qhov, koj yuav tsum xiam tus lej PIN thov. Tom qab ntawd teeb tsa daim npav SIM hauv lub qhov rau sab hauv qab ntawm pawg thawj coj raws li qhia hauv daim duab, ob tus dhia yuav tsum tau teeb tsa hauv txoj haujlwm RX-1 (D1), TX-0 (D0).

Kauj ruam 5: Khoos phis tawj sib dhos

Khoos phis tawj sib dhos
Khoos phis tawj sib dhos
Khoos phis tawj sib dhos
Khoos phis tawj sib dhos
Khoos phis tawj sib dhos
Khoos phis tawj sib dhos

Kev sib dhos kho vajtse muaj ntau txoj haujlwm yooj yim:

  • Txhawm rau tswj cov LEDs, thawj zaug koj yuav tsum tau tsim cov qauv me me ntawm LEDs thiab tam sim no txwv kev tiv thaiv (100-500 Ohm) raws li qhia hauv daim duab. Them sai sai rau qhov sib txawv ntawm cov LEDs - qhov anode yuav tsum tau muab muag rau cov neeg tawm tsam (+). Txhawm rau txo qhov kev kis kab mob ntawm LEDs, Kuv tau ua lub vijtsam dub tawm ntawm cov duab los tsis tu ncua.
  • С txuas cov LEDs thiab lub koob yees duab mus rau Arduino M0-SD pawg thawj coj raws li qhia hauv daim duab. Lub zog fais fab ntawm lub koob yees duab (xaim liab "+ 5V" thiab xaim dub "GND") yuav tsum raug coj los ntawm "+ 5V" thiab "GND" cov dav hlau los ntawm lub qhov. Koj tseem tuaj yeem siv lub kaum sab xis txuas rau qhov no.
  • Tom qab ntawd, txuas 3G/GPRS/GSM/GPS daim thaiv mus rau Arduino M0-SD pawg thawj coj. Tsis txhob hnov qab txuas lub kav hlau txais xov 3G.

Kauj Ruam 6: Teeb MQTT Broker

Teem MQTT Broker
Teem MQTT Broker
Teem MQTT Broker
Teem MQTT Broker
Teem MQTT Broker
Teem MQTT Broker

Kuv xaiv qhov yooj yim heev thiab meej www.cloudmqtt.com ua MQTT broker. Nws muab kev sim dawb. Nws tseem tuaj yeem tau txais thiab xa xov ncaj qha ntawm lub xaib.

Cov txheej txheem teeb tsa yog raws li hauv qab no:

  1. Sau npe hauv online.
  2. Nias lub pob "Tsim Tus Txheej Txheem Tshiab".
  3. Teeb lub npe, piv txwv li "MqttCamera".
  4. Nias lub pob "Xaiv Cheeb Tsam". Piv txwv li, xaiv "US-East-1 (Northern Virginia)".
  5. Nias lub pob "Ntsuam xyuas".
  6. Nias lub pob "Tsim Tus Txheej Txheem". Saib cov lus "Cov xwm txheej tsim tau zoo".
  7. Nyem "MqttCamera".
  8. Nco ntsoov cov ntaub ntawv: Tus neeg siv khoom, Tus neeg siv, Tus lej zais, Chaw nres nkoj, API yuam sij (Peb yuav xav tau nws ntawm qib 7 thiab 8).
  9. Tom qab ntawd koj tuaj yeem mus rau "WEBSOCKET UI" qhov rai, qhov twg koj tuaj yeem sim thiab debug, saib thiab xa lus (Peb yuav xav tau lub qhov rai no hauv cov kauj ruam tom ntej).

Kauj Ruam 7: MQTT Dash App

MQTT Dash App
MQTT Dash App
MQTT Dash App
MQTT Dash App
MQTT Dash App
MQTT Dash App

Txhawm rau tsim cov tswj vaj huam sib luag hauv lub xov tooj ntawm tes, Kuv tau xaiv tus neeg siv zoo heev thiab meej MQTT Dash app.

Nruab lub app MQTT Dash ntawm koj lub xov tooj thiab teeb tsa cov hauv qab no:

  1. Qhib daim ntawv thov.
  2. Hauv MQTT lub qhov rais qhib, nyem (+) ntxiv lub vaj huam sib luag tswj tshiab.
  3. Hauv lub qhov rai uas tshwm, sau rau hauv cov lus uas yuav tsum tau ua, xws li: Lub Npe (piv txwv li, MqttCamera), Chaw Nyob, Chaw Nres Nkoj, Tus Neeg Siv Npe, Tus Neeg Siv Tus Kheej (Siv cov ntaub ntawv los ntawm kauj ruam 6).
  4. Tom qab sau rau hauv cov teb, nyem rau lub cim diskette (ua haujlwm "Txuag").
  5. Hauv lub qhov rai nrog cov npe ntawm cov tswj vaj huam sib luag, nyem rau ntawm kab uas tshwm "MqttCamera".
  6. Hauv lub vaj huam sib luag tswj qhov rai uas qhib, nyem lub cim xub kom thauj cov ntsuas.
  7. Tom qab ntawv nyob rau hauv lub qhov rai pop-up, nyem rau ntawm lub pob "SUBSCRIBE AND WAIT FOR THE METRIC".
  8. Ntawm lub khoos phis tawj ntiag tug, qhib tus as khauj hauv MQTT-broker (saib cov kauj ruam dhau los), qhib lub "WEBSOCKET UI" qhov rai, teeb tsa "ntsuas/pauv" cov ncauj lus hauv "Xa lus" qhov rai, thiab sau cov ntawv los ntawm txuas cov ntaub ntawv metrics.txt hauv "Message" qhov rai, nyem khawm "Xa".
  9. Tos 10 vib nas this, nco ntsoov tias lub ntsuas tau txais hauv lub xov tooj thiab cov tswj vaj huam sib luag tau hloov kho tshiab.

Tom qab ntawd koj tuaj yeem npaj mus rau txoj haujlwm sib xws Arduino M0-SD.

Kauj Ruam 8: Programming thiab Ua Haujlwm

Programming thiab Ua Haujlwm
Programming thiab Ua Haujlwm
Programming thiab Ua Haujlwm
Programming thiab Ua Haujlwm
Programming thiab Ua Haujlwm
Programming thiab Ua Haujlwm
Programming thiab Ua Haujlwm
Programming thiab Ua Haujlwm

Ua ntej kev teeb tsa ua tau zoo Arduino M0-SD, koj yuav tsum tau teeb tsa hauv computer ntawm txhua lub tsev qiv ntawv tsim nyog (pubsubclient-master, TinyGSM-master), uas kuv hais hauv qab no. Cov tsev qiv ntawv no tau hloov kho me ntsis los ua haujlwm nrog Arduino M0-SD board, lub VC0706 lub koob yees duab, thiab 3G/GPRS/GSM/GPS SIM5320 daim thaiv.

Koj yuav tsum txuas koj lub xov tooj thiab txuas hluav taws xob (6V 1A rau lub zog 3G/GPRS/GSM/GPS daim thaiv) rau Arduino M0-SD sib xws.

Pib Arduino IDE. Hauv Arduino IDE xav tau xaiv: Cuab Yeej-> Pawg: Arduino M0 Pro (Native USB Port).

Qhib daim duab MqttCamera.ino. Sau rau hauv cov teb: Tus neeg siv lub npe, Tus lej siv, tus lej API, Chaw nres nkoj, Tus neeg rau zaub mov (Nqa cov ntaub ntawv los ntawm qib 6).

Qhib Serial Monitor window.

Upload daim duab. Kuv tsis piav qhia ntxaws txog txheej txheem txheej txheem (muaj cov lus qhia txaus hauv Is Taws Nem).

Tom qab ua tiav kev thauj khoom thiab sib dhos kom raug, cov ntaub ntawv hauv qab no yuav tsum tshwm nyob rau hauv Serial Monitor window:

VC0706 Lub Koob Yees Duab + Arduino M0 + SIM5320 + MQTT

Lub koob yees duab pib… version: ----------------- VC0703 1.00 Ctrl infr muaj nyob Tus neeg siv lub ntsuas 525 ----------------- ua tiav ! Initializing modem… Modem: AT+CGMM SIMCOM_SIM5320E Tos rau network… OK Txuas rau internet OK Txuas rau 3.83.68.228 tsis txuas rau 3.83.68.228 OK Ping: 0

Kab "Ping: XX" yog cov lus qhia los ntawm Arduino M0-SD sib xws rau lub server. Hloov chaw ntawm cov ntaub ntawv no, koj tuaj yeem xa cov ntsuas ADC, cov xwm txheej nkag mus, thiab ntau ntxiv.

Hauv MQTT Dash app, nyem rau ntawm lub cim ntawm lub teeb (LED_YELLOW, LED_GREEN, LED_RED) - qhib/tua. Saib hauv lub qhov rais ntawm Serial monitor - yuav tsum muaj cov ntaub ntawv hais txog qee yam zoo li no:

LED_YELLOW Nyob

LED_YELLOW_Off LED_GREEN Ntawm LED_GREEN tawm LED_RED Ntawm LED_RED Tawm

Nyem rau ntawm lub koob yees duab lub cim - xa cov lus txib "SHOOT" thiab tos ib pliag. Cov ntaub ntawv hauv qab no yuav tsum tshwm nyob rau hauv Serial Monitor window:

Pib Tua!

Daim duab coj! tsim IMAGE332-j.webp

Thiab tom qab ib ntus (5-10 vib nas this) hauv lub qhov rai "NYEEM IMAGE" yuav tsum tso saib daim duab.

Txog qhov ua qauv qhia, kuv qhia lub VC0706 lub koob yees duab rau LEDs kom koj tuaj yeem pom lawv li xwm txheej tom qab kuv hloov lawv raws li qhov xav tau. Tab sis hauv kev siv tiag tiag, koj tuaj yeem coj lub koob yees duab mus rau chav, qhov rooj, txoj kev, rooj vag, tsheb, thiab lwm yam (Tau kawg, koj yuav tsum coj mus rau hauv tus as khauj raws li txoj cai lij choj). lub xov tooj ntawm tes, qhov chaw teeb tsa thiab lub xeev tseeb ntawm LEDs tau tshwm.

Kuv vam tias kuv cov lus qhia tau nthuav thiab muaj txiaj ntsig zoo rau koj. Kuv yuav zoo siab rau koj cov lus teb thiab lus pom. Hauv kuv cov phiaj xwm los txhim kho kuv lub cuab yeej thiab qhia rau koj nrog kev hloov pauv tshiab. Tsaug rau saib!

Pom zoo: