Cov txheej txheem:
- Kauj Ruam 1: MQTT Yog Dab Tsi thiab Nws Ua Haujlwm Li Cas
- Kauj ruam 2: Raspberry Pi
- Kauj Ruam 3: Yuav Teeb Li Cas Qhov Chaw Nyob IP
- Kauj Ruam 4: NodeMCU
- Kauj ruam 5: Python Script
- Kauj Ruam 6: Kev Sib Txuas thiab Daim Duab Duab
- Kauj Ruam 7: Qhov tshwm sim
Video: Raspberry Pi Tham Nrog ESP8266 Siv MQTT: 8 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:29
Hauv qhov haujlwm no, kuv yuav piav qhia tias MQTT raws tu qauv yog li cas thiab nws siv los sib txuas lus ntawm cov cuab yeej li cas, Tom qab ntawd, raws li qhov ua piv txwv, kuv yuav ua kom pom kev teeb tsa tus neeg siv khoom thiab cov txheej txheem brocker, qhov twg ESP8266 module nrog rau RPi tham rau ib leeg lossis xa xov thaum lub pob raug thawb.
Cov khoom siv xav tau
1. Raspberry Pi 3
2. NodeMCU
3. LED
4. Khawm
5. Resistors (10k, 475 ohm)
Kauj Ruam 1: MQTT Yog Dab Tsi thiab Nws Ua Haujlwm Li Cas
MQTT
MQTT yog lub tshuab-rau-tshuab (M2M) cov ntaub ntawv hloov chaw raws tu qauv. MQTT tau tsim nrog lub hom phiaj ntawm kev khaws cov ntaub ntawv los ntawm ntau lub cuab yeej thiab tom qab ntawd thauj cov ntaub ntawv ntawd mus rau IT kev tsim vaj tsev. Nws yog lub teeb yuag, thiab yog li ntawd zoo tshaj rau kev saib xyuas tej thaj chaw deb, tshwj xeeb tshaj yog hauv M2M kev sib txuas uas xav tau tus lej me me hneev taw lossis qhov twg bandwidth hauv network txwv.
Yuav ua li cas MQTT ua haujlwm
MQTT yog kev tshaj tawm/sau npe txheej txheem uas tso cai rau ntug-ntawm-cov cuab yeej siv network tshaj tawm rau tus tswv lag luam. Cov neeg siv khoom txuas rau tus broker no, uas tom qab ntawd ua kom muaj kev sib txuas lus nruab nrab ntawm ob lub cuab yeej. Txhua lub cuab yeej tuaj yeem sau npe, lossis sau npe, rau cov ncauj lus tshwj xeeb. Thaum lwm tus neeg siv tshaj tawm cov lus ntawm cov ncauj lus uas tau sau npe, tus tswv lag luam xa cov lus mus rau txhua tus neeg siv khoom uas tau sau npe.
MQTT yog ob txoj hauv kev, thiab tswj hwm kev paub txog kev sib tham hauv xeev. Yog tias cov cuab yeej txuas-ntawm-network poob kev sib txuas, txhua tus neeg tau txais kev tso npe yuav raug ceeb toom nrog "Qhov Yuav Tseeb thiab Lus Nug" qhov tshwj xeeb ntawm MQTT server kom txhua tus neeg tau txais kev tso cai hauv qhov system tuaj yeem tshaj tawm tus nqi tshiab rov qab mus rau ntug-ntawm- cov cuab yeej network, tswj kev sib txuas ob tog.
Txoj haujlwm tau muab faib ua 3 ntu
Ua ntej tshaj, peb tsim MQTT server ntawm RPi thiab teeb tsa qee lub tsev qiv ntawv.
Qhov thib ob, peb yuav teeb tsa cov tsev qiv ntawv hauv Arduino IDE rau NodeMCU kom ua haujlwm nrog MQTT, upload cov cai thiab tshawb xyuas seb server puas ua haujlwm lossis tsis yog.
Thaum kawg, peb tsim tsab ntawv hauv Rpi, xa cov cai uas xav tau hauv NodeMCU thiab khiav cov ntawv nab nab los tswj leds los ntawm ob tus neeg rau zaub mov thiab cov neeg siv khoom. Ntawm no, server yog RPi thiab tus thov yog NodeMCU.
Kauj ruam 2: Raspberry Pi
1. Txhawm rau teeb tsa qhov tseeb MQTT server thiab cov neeg siv khoom hauv RPi, txhawm rau siv lub chaw cia khoom tshiab koj yuav tsum xub xub xa cov pob khoom ntim kos npe.
wget https://repo.mosquitto.org/debian/mosquitto-repo.gpg.keysudo apt-key ntxiv mosquitto-repo.gpg.key
2. Ua kom lub chaw cia khoom muaj rau apt.
cd /etc/apt/sources.list.d/
3. Nyob ntawm seb koj siv Debian version twg.
sudo wget https://repo.mosquitto.org/debian/mosquitto-wheezy.listsudo wget
sudo wget
sudo apt-tau hloov tshiab
4. Nruab Mosquitto server siv cov lus txib.
sudo apt-tau nruab mosquitto
Yog tias koj tau txais qhov yuam kev hauv kev txhim kho Mosquitto zoo li no.
#################################################################
Cov pob hauv qab no muaj qhov tsis txaus ntseeg nyob rau hauv: mosquitto: Nyob ntawm: libssl1.0.0 (> = 1.0.1) tab sis nws tsis tuaj yeem teeb tsa tau nyob ntawm: libwebsockets3 (> = 1.2) tab sis nws tsis tuaj yeem teeb tsa E: Tsis tuaj yeem kho qhov teeb meem, koj tau tuav tawg pob khoom
#################################################################
Tom qab ntawd siv cov lus txib no los kho cov teeb meem.
sudo apt -fix-tawg nruab
5. Tom qab teeb tsa MQTT server, teeb tsa tus neeg siv siv cov lus txib
sudo apt-tau nruab mosquitto-cov neeg siv khoom
Koj tuaj yeem tshawb xyuas cov kev pabcuam siv cov lus txib.
systemctl xwm txheej mosquitto.service
Raws li peb MQTT server thiab cov neeg siv khoom tau teeb tsa. Tam sim no, peb tuaj yeem tshawb xyuas nws siv kev sau npe thiab tshaj tawm. Txog rau npe thiab tshaj tawm koj tuaj yeem tshawb xyuas cov lus txib lossis mus saib lub vev xaib raws li tau hais hauv qab no.
Mosquitto Sub
Mosquitto Pub
Txhawm rau teeb tsa tsev qiv ntawv paho-mqtt siv cov lus txib hauv qab no.
sudo pip nruab paho-mqtt
Paho
Kauj Ruam 3: Yuav Teeb Li Cas Qhov Chaw Nyob IP
Mus rau phau ntawv teev npe cd /lwm yam thiab qhib cov ntaub ntawv dhcpcd.conf siv ib tus kws kho mob. Thaum kawg, sau plaub kab no.
interface eth0 zoo li qub ip_address = 192.168.1.100 // ip koj xav siv
wb wl0
ip_address zoo li qub = 192.168.1.68
routers zoo li qub = 192.168.1.1 // koj lub rooj vag Default
zoo li qub domain_name_servers = 192.168.1.1
Tom qab ntawd txuag nws thiab rov pib dua koj tus pi.
Kauj Ruam 4: NodeMCU
Txhim kho cov tsev qiv ntawv xav tau hauv Arduino IDE rau NodeMCU
1. Mus rau Sketch ==> Suav nrog tsev qiv ntawv ==> Tswj cov tsev qiv ntawv.
2. Tshawb nrhiav mqtt thiab teeb tsa tsev qiv ntawv los ntawm Adafruit lossis koj tuaj yeem nruab ib lub tsev qiv ntawv.
3. Nws vam khom sleepydog lub tsev qiv ntawv yog li peb xav tau lub tsev qiv ntawv no ib yam.
Qhov kev zov me nyuam tau muab rau saum toj no, tsuas yog txhawm rau txheeb xyuas seb nws ua haujlwm lossis tsis. Ntawm no kuv tsis tau tsim ib tsab ntawv hauv RPi. Peb tsuas yog siv cov lus txib txhawm rau sau npe thiab tshaj tawm. Peb yuav tsim tsab ntawv rau kev tswj hwm tom qab.
mosquitto_pub -h raspberrypi -t "/leds/pi" -m "ON"
mosquitto_pub -h raspberrypi -t "/leds/pi" -m "OFF"
mosquitto_pub -h raspberrypi -t "/leds/pi" -m "TOGGLE"
mosquitto_pub -h raspberrypi -t "/leds/esp8266" -m "ON"
mosquitto_pub -h raspberrypi -t "/leds/esp8266" -m "OFF"
mosquitto_pub -h raspberrypi -t "/leds/esp8266" -m "TOGGLE"
-h ==> host name-t ==> ncauj lus
-m ==> lus
Tom qab txheeb xyuas Mqtt_check program upload tiav qhov program hauv NodeMCU
Kauj ruam 5: Python Script
Raws li kuv tau tham saum toj no peb xav tau tsab ntawv nab nab rau kev tswj cov leds siv cov nyees khawm. Yog li, peb tab tom yuav tsim tsab ntawv. Tsab ntawv tau muab rau saum toj no.
Thaum koj khiav cov ntawv koj tsab ntawv yuav tsum zoo li zoo li tau qhia hauv duab, yog tias cov lej tshwm sim tsis yog xoom ces lawv yog qhov yuam kev koj tuaj yeem tshawb xyuas qhov ua yuam kev ntawm paho lub vev xaib.
Kauj Ruam 6: Kev Sib Txuas thiab Daim Duab Duab
Kev cuam tshuam ntawm khawm, LED nrog NodeMCU
NodeMCU ===> ButtonGnd ===> Gnd
3.3V ===> PIN1
GPIO4 (D2) ===> PIN2
NodeMCU ===> LED
Gnd ===> Cathode (-ve)
GPIO5 (D1) ===> Anode (+ve)
Kev cuam tshuam ntawm khawm, LED nrog RPi
RPi ===> ButtonGnd ===> PIN1
GPIO 23 ===> PIN2
RPi ===> LED
Gnd ==> Cathode (-ve)
GPIO 24 ===> Anode (+ve)
Kauj Ruam 7: Qhov tshwm sim
Nco ntsoov tias koj tsab ntawv ua haujlwm tsis yog nws yuav tsis tuaj yeem tswj coj siv cov nyees khawm.
Pom zoo:
Kev Sib Tham Sib Tham Punching Hnab: 3 Cov Kauj Ruam (nrog Duab)
Interactive Reflex Punching Bag: Cov lus qhia no yog rau txhua tus neeg uas xav txhim kho lawv cov kev txawj ntse thiab kev txawj ntaus nrig thaum tau txais kev paub ntau dua, siv Arduino, LED's thiab MK 2125 Accelerometer
THIAB LUB NEEJ !! (Sib tham sib tham rooj sib tham): 4 Kauj Ruam
THIAB LUB NEEJ !! (sib tham sib tham txog Thruth Table): Nyob zoo cov phooj ywg, Kuv vam tias koj txhua tus nyob hauv koj lub tsev zoo thiab xav tsis thoob dab tsi ntawm cov ntaub ntawv uas muaj ?? Nkag siab cov rooj vag logic yog qhov tseem ceeb heev rau ob leeg
Tham nrog De thiab Artificial Intelligence Tham Nrog Cleverbot: 14 Cov Kauj Ruam (nrog Duab)
Tham nrog De thiab Artificial Intelligence Tham Nrog Cleverbot: Ntawm no kuv sim tsis tsuas yog lub suab hais kom ua tab sis kuj yog Artificial Intelligence Tham nrog Lub Computer siv Cleverbot. Qhov tseeb lub tswv yim tuaj thaum pom cov menyuam sib xyaw xim hauv lub thawv xim thaum coj xim ntawm ib xim mus rau qhov ze tshaj plaws. Tab sis thaum kawg ua raws
Cov Neeg Siv Yooj Yim Sib Tham Sib Tham rau Kev Qhia thiab Kev Ntsuam Xyuas: 11 Kauj Ruam
Cov Neeg Siv Yooj Yim Sib Tham Sib Tham rau Kev Qhia thiab Kev Ntsuam Xyuas: Txoj haujlwm no tau tsim los ua ib feem ntawm chav kawm hauv tsev kawm qib siab, lub hom phiaj yog ua kom muaj kev sib tham sib tham los qhia thiab ntsuas qee yam ncauj lus. Rau nws peb tau siv Kev Ua Haujlwm ntawm PC rau lub interface thiab Arduino NANO rau lub khawm arcade thiab LEDs, yog li
Yuav Ua Li Cas Siv IRC (Internet Sib Tham Sib Tham): 5 Kauj Ruam
Yuav Ua Li Cas Siv IRC (Sib Tham Sib Tham Hauv Is Taws Nem): [Kho] Qhov no yog Cov Lus Qhia uas yog lub hauv paus rau cov uas tseem tsis tau nkag siab txog Kev Sib Tham Hauv Is Taws Nem, lossis IRC. Txoj haujlwm no tsis yog npaj los npog tag nrho cov peev txheej ntawm IRC thiab txhua tus neeg siv khoom lub peev xwm, tab sis yog lub hom phiaj kom yeej