Cov txheej txheem:
- Kauj Ruam 1: Txhim Kho Mqtt Broker:
- Kauj Ruam 2: Xeem MQTT (Mosquitto)
- Kauj Ruam 3: Ua Haujlwm Nrog Armtronix Board & Mqtt
Video: MQTT ntawm Armtronix Boards: 3 Cov Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:24
Hauv cov lus qhia no peb xav pib qhia koj li cas koj tuaj yeem siv Linux (Debian lossis Ubuntu) raws li kab ke thiab teeb tsa Mosquitto (Mqtt Broker) rau nws, tseem qhia koj li cas siv Mqtt tus thov kev pab ntawm koj lub Xov Tooj (Android)/ Linux Raws system, xa thiab tau txais cov lus ntawm Mqtt. Tom qab tau paub txog qhov no, peb xav qhia koj yuav ua li cas koj tuaj yeem teeb tsa thiab txuas peb pawg thawj coj nrog qhov teeb tsa Mqtt broker. Kuj tseem xav qhia koj li cas koj tuaj yeem ntxiv kev txheeb xyuas qhov tseeb rau Mqtt broker thiab qee cov lus qhia yooj yim thiab cov lus qhia kom debug. Yog li cia peb pib ………
Kauj Ruam 1: Txhim Kho Mqtt Broker:
Muaj ntau tus Mqtt brokers uas koj tuaj yeem teeb tsa. Qee tus paub yog raws li tau hais hauv qab no. Ib txhia ntawm lawv yog cov kev pabcuam huab.
- HiveMQ
- MosquittoCloud
- MQTT
- Adafruit.io
Peb yuav qhia koj yuav ua li cas rau nruab Mosquitto ntawm Linux raws li kab ke (Ubuntu 18.04). Ua qhov no ua ntej ntxiv Mosquitto rau ubuntu qhov chaw npe. Thaum Mosquitto muaj nyob hauv Ubuntu chaw cia khoom koj yuav tuaj yeem nruab nws nrog apt-get.
Tsuas yog qhib Terminal. Txhawm rau qhib lub davhlau ya nyob twg, mus rau sab laug tes hauv qab kaum ntawm Ubuntu Desktop, Nyem rau Qhia daim ntawv thov (Dotted 3X3 daim phiaj). Qhov rai yuav qhib. Muaj koj tshawb rau Terminal. Nyem rau ntawm lub davhlau ya nyob twg koj yuav tsum tuaj yeem pom lub qhov rai qhib raws li qhia hauv cov duab hauv qab no.
- Qhia Daim Ntawv Thov (Duab 1).
- Nrhiav rau Terminal (Duab 2).
- Qhov rai Terminal (Duab 3).
Nkag mus rau cov lus txib hauv qab no tom qab koj qhib Terminal
sudo apt-add-repository ppa: mosquitto-dev/mosquitto-ppa
sudo apt-tau hloov tshiab
sudo apt-tau nruab mosquitto
Koj tseem tuaj yeem nruab Mqtt tus thov kev pabcuam. Hais kom ua qhov ntawd yuav yog
sudo apt-tau nruab mosquitto-cov neeg siv khoom
Qee cov duab rau koj siv
- Ntxiv ppa (Duab 4).
- Hloov kho repo (Duab 5).
- Txhim Kho Mosquitto (Duab 6).
- Txhim Kho Mosquitto Client (Duab 7).
Kauj Ruam 2: Xeem MQTT (Mosquitto)
Txhawm rau sim mqtt ntawm ubuntu (tib lub kaw lus lossis lwm yam txheej txheem) koj yuav tsum teeb tsa mqtt tus thov kev pabcuam uas tau teeb tsa ua ntej los ntawm kev hais kom ua sudo apt-tau nruab mosquitto-cov neeg siv khoom. Yog tias koj xav sim nws siv lub xov tooj ntawm tes (hauv xov tooj), koj tuaj yeem nruab MyMqtt app los ntawm khw ua si.
Mqtt ua haujlwm ntawm qee yam hu ua Topics. Txhawm rau kom nkag siab yooj yim xav txog cov ncauj lus no raws li daim nplaub tshev ntawm lub computer hard drive. Cia peb kho lub khoos phis tawj no ua lub khoos phis tawj computer (uas nyob hauv mqtt ntiaj teb yog Mqtt Broker). Hauv cov neeg rau zaub mov no cia peb txiav txim siab muaj ib daim nplaub tshev.
Lub npe nplaub tshev: /Folder_one /
Tam sim no cia peb txiav txim siab ob tus neeg los ntawm ob lub tshuab sib txawv (PC/Laptop) nkag mus rau lub server no los nyeem cov ntaub ntawv lossis xa/pov tseg cov ntaub ntawv lossis ua ob qho haujlwm.
Peb yuav sau npe ob tus neeg/kab ke ua System X, System Y (Cov no yog Mqtt Cov Neeg Siv Khoom hauv Mqtt Ntiaj Teb).
Tam sim no, hais tias System X xa/Dump qee cov ntaub ntawv (npe lub npe: kub) rau hauv "/Folder_one/" nplaub tshev, qhov no hauv mqtt ntiaj teb peb tuaj yeem hu qhov tshaj tawm no (peb xa qee cov lus/them nyiaj tsis siv cov ntawv).
Tam sim no, hais tias System Y xav tau/nyeem cov ntawv no lossis ib qho ntaub ntawv tshiab lossis hloov tshiab hauv daim nplaub tshev no, thawj qhov nws xav tau yog kom paub lub npe nplaub tshev thiab txoj hauv kev, uas hauv peb qhov xwm txheej yog "/Folder_one/". Yog li tam sim no nws yuav mus rau daim nplaub tshev no thiab nyeem/tau txais cov ntawv ntawd (npe lub npe: kub). Paub txog txoj hauv kev/Cov ncauj lus thiab txheeb xyuas qhov hloov pauv ntawm cov ntaub ntawv/cov ntaub ntawv tshiab hauv Mqtt ntiaj teb yog kev tso npe rau lub ncauj lus ntawd.
Xav txog qhov piv txwv saum toj no, System X tshaj tawm rau “/Folder_one” thiab System Y tau sau npe rau “/Folder_one”
Tsis tas li nco ntsoov tias System X tseem tuaj yeem sau npe rau "/Folder_one" thiab System Y tseem tuaj yeem tshaj tawm rau "/Folder_one". Zoo li txawj ntse txawm tias Tus Neeg rau zaub mov (Tus Mqtt Broker) tuaj yeem tshaj tawm/sau npe rau "/Folder_one" los ntawm kev txhim kho Mqtt tus thov kev pab rau nws zoo li peb tau ua tam sim no. Lwm qhov uas yuav tsum nco ntsoov yog tshaj tawm lossis sau npe rau lub ncauj lus koj yuav tsum paub tus IP chaw nyob ntawm Mqtt Broker.
Ua ntej peb yuav sim nws los ntawm ubuntu tus thov kev pabcuam uas tau teeb tsa ntawm tib lub system zoo li tus broker yog. Peb yuav qhib ob lub davhlau ya nyob twg windows ib ntawm nws yuav tshaj tawm thiab lwm qhov yuav sau npe rau nws. Rau qhov piv txwv Peb yuav siv /Folder_one raws li lub ncauj lus. Ua ntej pub/sub rau lub ncauj lus koj yuav tsum tau nrhiav tus IP chaw nyob ntawm ubuntu. Txhawm rau ua qhov no nyem rau ntawm sab xis sab saum toj ntawm lub vijtsam, xaiv teeb tsa wifi, los ntawm qhov ntawd koj yuav tuaj yeem nrhiav tus IP chaw nyob ntawm ubuntu system (tam sim no tus broker IP). Screenshort qhia rau siv (Duab 8).
Los yog txhawm rau nrhiav tus IP chaw nyob ntawm tus broker koj tuaj yeem nrhiav tus IP chaw los ntawm kev txhim kho cov cuab yeej siv cov lus txib hauv qab no hauv lub davhlau ya nyob twg
sudo apt nruab net-cuab yeej
Txhim kho net-cuab yeej (Duab 9). Tom qab ntawd tsuas yog ntaus qhov hais kom ua ipconfig koj yuav tau txais cov npe network sib cuam tshuam nrog mac thiab IP chaw nyob
sudo ipconfig
IP chaw nyob ntawm kuv qhov system yog 192.168.1.67 (Duab 10)
Tshaj tawm
mosquitto_pub -h 192.168.1.67 -t /Folder_one -m pub_to_folderone
Ntawm no, mosquitto_pub yog cov lus txib, ua raws los ntawm tus lej ntsuas tus lej -h uas yog tus tswv tsev /tus tswv IP chaw nyob (Hauv peb qhov xwm txheej 192.168.1.67), ua raws los ntawm -t uas yog lub npe rau tus tshaj tawm (Hauv peb cov ntaub ntawv /Folder_one), ua raws los ntawm -m uas txhais tau tias cov lus/them nyiaj yuav raug xa mus (Hauv peb qhov xwm txheej yog pub_to_folderone).
Txhawm rau sau npe yuav
mosquitto_sub -h 192.168.1.67 -t /Folder_one
Cov lus xa los ntawm tus tshaj tawm: pub_to_folderone
Piv txwv rau kev tshaj tawm
mosquitto_pub -h 192.168.1.67 -t /Folder_one -m "nyob zoo mqtt"
mosquitto_pub -h 192.168.1.67 -t /Folder_one -m "mqtt ua haujlwm"
Piv txwv rau cov lus teb tau txais ntawm kev sau npe rau lub ncauj lus
mosquitto_sub -h 192.168.1.67 -t /Folder_one
Cov lus xa los ntawm tus tshaj tawm:
- pub_to_folderone
- hlo mqtt test
- mqtt ua
Pub Sub hauv ob lub davhlau ya nyob twg qhov rai sib nrug ib sab (Duab 11)
Kuaj Mqtt ntawm Android (kuv mqtt)
Nruab mymqtt app los ntawm khw ua si ntawm koj lub xov tooj Android (Duab 12)
Qhib lub app thiab nyem rau ntawm lub kaum sab laug tes saum toj kawg nkaus (Duab 13, Duab 14).
Nyem rau ntawm Chaw thiab nkag mus rau tus broker tus IP chaw nyob, chaw nres nkoj los ntawm lub neej ntawd yuav yog 1883. Tam sim no peb tsis siv qhov tseeb mqtt broker yog li tus neeg siv lub npe thiab tus lej zais yuav tsis muaj dab tsi. Tsuas yog khaws nws thiab rov nyem rau ntawm lub ces kaum sab saud ntawm lub app (<Chaw) lub tub rau khoom yuav rov qhib dua (Duab 15).
Nyob rau sab saum toj ntawm lub tub rau khoom nws yuav qhia koj tus broker IP chaw nyob thiab chaw nres nkoj app tau txuas nrog (Duab 16).
Tam sim no ntxiv cov ncauj lus koj xav sau npe los ntawm nyem rau Subscribe. Nov peb yuav ntxiv cov ncauj lus raws li /Folder_one (Duab 17, Duab 18).
Tom qab ua qhov no, los ntawm ubuntu system los ntawm kev siv dav hlau peb yuav tshaj tawm rau lub ncauj lus. Ntawm kev tshaj tawm koj yuav tsum tau txais cov nyiaj them poob haujlwm/lus tshaj tawm ntawm no mobile app. Piv txwv li tshaj tawm kev them nyiaj raws li "ARM -Automation Robotics & Mechatronics". Kev hais kom ua yog raws li tau hais ua ntej.
mosquitto_pub -h 192.168.1.67 -t /Folder_one -m "ARM -Automation Robotics & Mechatronics"
tshaj tawm los ntawm ubuntu system (Duab 19).
Tau txais cov lus tshaj tawm ntawm dashboard (Duab 20).
Tam sim no cia peb tshaj tawm los ntawm xov tooj hauv xov tooj (Kuv mqtt) thiab sau npe ntawm ubuntu system. Txog qhov piv txwv no peb tab tom siv lub ncauj lus "/mymqtt_to_pub".
Txhawm rau ua qhov no thawj zaug qhib lub davhlau ya nyob twg los ntawm koj lub ubuntu system thiab sau npe rau lub ncauj lus "/mymqtt_to_pub" siv cov lus txib hauv qab no (Duab 21)
mosquitto_sub -h 192.168.1.67 -t /mymqtt_to_pub
Tam sim no mus rau lub tub rau khoom ntawm mymqtt app thiab nyem rau tshaj tawm. Ntxiv cov ncauj lus tshaj tawm (Hauv peb qhov xwm txheej nws yog "/mymqtt_to_pub") thiab xa qee cov lus zoo li peb yuav xa "nyob zoo Ubuntu", nias lub pob xa (Duab 22, Duab 23).
Cov lus yuav tsum tshwm ntawm koj lub qhov rai qhov rai ntawm ubuntu system (Duab 24).
Nco ntsoov tias ob qho tib si ubuntu thiab lub xov tooj hauv xov tooj yuav tsum nyob hauv tib lub network lossis chaw nres nkoj 1883 yuav tsum raug nthuav tawm thiab koj yuav tsum paub tus IP chaw nyob ntawm koj lub router/rooj vag rau mqtt ua haujlwm. Yog tias koj xav ntxiv kev txheeb xyuas qhov tseeb rau koj tus broker mqtt koj tuaj yeem ua nws los ntawm kev ua raws cov hauv qab no hais txog blog txuas https://medium.com/@eranda/setting-up-authenticat… Ua raws li los ntawm blog no kauj ruam ob. Peb muaj peev xwm txheeb xyuas qhov tseeb ntawm peb tus broker thiab yuav siv tus as khauj pov thawj muaj txiaj ntsig zoo rau peb cov laug cam.
Kauj Ruam 3: Ua Haujlwm Nrog Armtronix Board & Mqtt
Tam sim no rau cov lus qhia no, peb tab tom siv peb Wifi Tib Dimmer Board uas siv Triac txhawm rau txhawm rau lub sine yoj thiab tig qhov muag teeb lossis tswj qhov nrawm ntawm tus kiv cua. Tsis tas li peb tau txuas nws los ntawm mqtt kev txheeb xyuas hom.
Thaum xub thawj peb tau teeb tsa lub rooj tsavxwm. Cov kauj ruam los teeb tsa nws yog raws li tau hais hauv qab no.
Fais fab ntawm lub rooj tsavxwm, nws yuav pib tuav lub Wifi Access Point.
Siv lub xov tooj hauv xov tooj lossis lub laptop txuas rau AP no (Duab 25).
Ib zaug txuas rau AP hom no 192.168.4.1 los ntawm kev qhib lub browser (chrome/firefox) los ntawm AP txuas nrog system/Xov tooj. Nco ntsoov tias koj tsis siv koj cov ntaub ntawv sib txuas (3G/4G).
Ntawm kev ntaus tus IP, lub vev xaib yuav qhib qhov twg hauv qab no yuav tsum nkag mus (Duab 26).
- SSID: Wifi AP npe.
- Lo lus zais: Tus lej SSID.
- IoT hom Mqtt lossis Http (Xaiv Mqtt).
- Mqtt Broker IP (Hauv peb qhov xwm txheej nws yog 192.168.1.67).
- Mqtt tus neeg siv lub npe thiab tus password, raws li peb tab tom siv hom kev lees paub, peb tau siv Naren, xxxx
- Mqtt tshaj tawm cov ncauj lus: Qhov no yuav yog ntawm cov ncauj lus twg uas pawg thawj coj saib xyuas tshaj tawm, peb tau siv /testpub.
- Mqtt sau npe cov ncauj lus: Qhov no yuav yog ntawm cov ncauj lus twg uas pawg thawj coj saib xyuas rau cov lus txib kom ua rau lub triac, peb tau siv /xeem ntawv.
- Ntaus lub npe: Nws yog lub npe koj hu rau alexa rau ua rau pawg thawj coj saib, peb tau siv corvi.
Tom qab nkag mus rau cov ntsiab lus, Nias lub pob xa, ntawm qhov ua qhov no koj yuav tau txais lub vijtsam raws li qhia hauv Duab 27, tos qee lub sijhawm txog thaum lub rooj tsavxwm nres hosting AP.
Thov nco ntsoov tias peb tau txuas peb pawg thawj coj ntawm Uart mus rau tus saib xyuas ntawm Arduino IDE. Yog li ntawm sab laug koj yuav pom cov lus debug nws luam tawm ntawm Uart (qhov no tsuas yog rau koj siv).
Thaum qhov no ua tiav koj tuaj yeem pom qhov debug screen. Feem ntau ntawm cov ntsiab lus yuav pom nyob ntawd. Tom qab qhov no, nws yuav ua tiav txuas rau tus broker ntawm qhov debug (serial) screen koj tuaj yeem pom qhov no.
Txuas nrog MQTT broker nrog kev lees paub tseeb. Sau npe mus rau lub ncauj lus 1.
Tom qab nws luam tawm qhov no koj tam sim no tuaj yeem pib xa nws cov lus txib ntawm mqtt ntawm cov ncauj lus nws tau sau npe rau piv txwv li /testsub /
Rau pawg lus txib no yog:
- R13_ON: Txhawm rau tig lub triac rau 100%.
- R13_OFF: Txhawm rau tua triac rau 0%.
- Dimmer: xx: Qhov twg, xx yog tus nqi dimming thiab tuaj yeem sib txawv ntawm 0 txog 99.
- Pib dua: Txhawm rau teeb tsa kev teeb tsa ntawm pawg thawj coj.
- Cov xwm txheej: Luam tawm qhov xwm txheej dimmer ntawm pawg thawj coj ntawm cov ncauj lus tshaj tawm ntawm pawg thawj coj.
Txhawm rau xa cov lus txib no los ntawm ubuntu raws li qhov system uas mqtt tus thov kev pabcuam tau teeb tsa, tsuas yog ntaus nws raws li qhia hauv qab no. Ob qhov kev ntsuas ntxiv tau ntxiv ntawm no vim yog kev txheeb xyuas tseeb -piv txwv li -u uas yog lub npe siv thiab -P yog tus password, thov nco ntsoov tias cov no yog cov ntaub ntawv rhiab.
mosquitto_pub -h 192.168.1.67 -u Naren -P xxxx -t /testsub -m R13_ON
mosquitto_pub -h 192.168.1.67 -u Naren -P xxxx -t /testsub -m R13_OFF
mosquitto_pub -h 192.168.1.67 -u Naren -P xxxx -t /testsub -m Dimmer: 50
Nco tseg: 50 yog tus nqi dimmer
mosquitto_pub -h 192.168.1.67 -u Naren -P xxxx -t /testsub -m R13_ON
mosquitto_pub -h 192.168.1.67 -u Naren -P xxxx -t /testsub -m Status
Txog qhov xwm txheej tshiab kawg, xwm txheej tau luam tawm ntawm cov ncauj lus tshaj tawm ntawm pawg thawj coj uas hauv peb cov ntaub ntawv yog /testpub. Ntawm peb pawg thawj coj saib xyuas ib qho kev hloov pauv ntawm lub cuab yeej raug luam tawm ntawm cov ntawv tshaj tawm ntawm pawg thawj coj. Piv txwv li, yog tias peb dhau Dimmer: 50 ntawm pawg thawj coj tau sau npe cov ntsiab lus ntau dua ntawm kev ua haujlwm lub cev no, pawg thawj coj yuav xa cov lus hais qhia txog qib qis ntawm qhov tshaj tawm cov ncauj lus. Piv txwv yog qhia hauv qab no, Txhawm rau sau npe los ntawm koj li ubuntu system rau cov ncauj lus tshaj tawm ntawm pawg thawj coj nkag mus rau cov lus txib hauv qab no
mosquitto_sub -h 192.168.1.67 -u Naren -P xxxx -t /testpub
message peb tau txais
DimmerIS50
ob peb lub luv luv ntawm tib yam hauv qab no (Duab 28, Duab 29)
Pom zoo:
Plotting Real-time Graph ntawm Android Los Ntawm Arduino Los Ntawm HC-05: 3 Cov Kauj Ruam
Plotting Real-time Graph ntawm Android Los ntawm Arduino Los ntawm HC-05: Hav nyob ntawm no, ntawm no yog kev qhia qhia yuav ua li cas npaj cov phiaj xwm ntawm lub sijhawm tiag tiag ntawm qhov tseem ceeb los ntawm tus tswj hwm micro xws li Arduino rau lub app. Nws siv Bluetooth qauv xws li HC-05 los ua lub cuab yeej xa xov mus rau kis thiab tau txais cov ntaub ntawv ntawm Ar
Mini 2-player Arcade Los Ntawm Lub Laptops Laus thiab Ikea Chopping Boards: 32 Cov Kauj Ruam (nrog Duab)
Mini 2-neeg uas ua ntawv Arcade Los ntawm Laptops qub thiab Ikea Chopping Boards: Kuv nyiam retro gaming. Tag nrho cov qub arcade tshuab thiab consoles tsuas yog lom zem heev.Kuv xav kuv tus kheej arcade tshuab tab sis kuv tsuas tsis muaj qhov chaw. Ua si nrog gamepad los ntawm lub console hauv TV tsuas yog tsis zoo yog li kuv xav tau
Tsim thiab Ua tiav ntawm Cov Txheej Txheem ntawm Kev Taw Qhia ntawm Photovoltaic Panels: 5 Cov Kauj Ruam
Tsim thiab Ua kom tiav ntawm Cov Txheej Txheem ntawm Kev Taw Qhia ntawm Photovoltaic Panels: Tsim thiab Ua tiav ntawm Cov Txheej Txheem ntawm Kev Taw Qhia ntawm Photovoltaic Panels
Kev tswj hwm tus kheej ntawm RPM ntawm Lub Cav Siv Lub Tswv Yim Los Ntawm IR Raws Li Tachometer: 5 Cov Kauj Ruam (nrog Duab)
Kev Tswj Tus Kheej ntawm RPM ntawm Lub Cav Siv Lub Tswv Yim Los Ntawm IR Raws Lub Tachometer: Muaj ib txwm xav tau rau kev siv tshuab txheej txheem, ua nws yooj yim/tsis txaus ntseeg. cov txheej txheem rau dej/siv dej rau peb daim av me me.Qhov teeb meem ntawm tsis muaj kab khoom siv tam sim no
Zaub Cov Duab Tawm ntawm PSP/Lub Xov Tooj Ntawm Lub Xov Tooj Ntawm Digital Duab: 3 Kauj Ruam
Zaub Cov Duab Tawm PSP/Lub Xov Tooj Ntawm Lub Xov Tooj Ntawm Tus Duab: Zoo … lub npe hais tias txhua yam tiag tiag … Qhov no yog qhov qhia tau yooj yim heev thiab nws tsis xav tau kho vajtse lossis software ntau dua li koj yuav tsum muaj ! Cov Lus Nug Qhia Rau Kuv lossis Tawm Tswv Yim! Koj tsis tas yuav hloov kho kom ua