Cov txheej txheem:
- Kauj Ruam 1: Kev Txhim Kho Tsev Qiv Ntawv
- Kauj ruam 2: Code
- Kauj Ruam 3: Kho MQTT Client (MQTTBOX)
- Kauj Ruam 4: Txoj Haujlwm Khiav Haujlwm
Video: NodeMCU - MQTT Piv Txwv Piv Txwv: 4 Cov Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:27
Zaj lus qhia no yuav qhia qhov pib siv MQTT raws tu qauv ntawm NodeMCU board. Peb siv MQTTBox ua MQTT tus neeg siv khoom ntawm no, thiab peb yuav siv NodeMCU kom ua tiav cov haujlwm hauv qab no:
Tshaj tawm "nyob zoo ntiaj teb" rau cov ncauj lus "tawmTopic" txhua ob vib nas this. Sau npe rau lub ncauj lus "inTopic", luam tawm cov lus tau txais. onboards LED. Tsov tawm onboard LED yog cov lus sau npe yuav yog "0".
Kev npaj: Osoyoo NodeMCU x1
USB Cable x1
Pc1 xwm
Arduino IDE (Versin 1.6.4+)
Txuas NodeMCU rau PC ntawm USB cable.
Kauj Ruam 1: Kev Txhim Kho Tsev Qiv Ntawv
Nruab PubSubClientlibrary
Peb xav tau nruab MQTT lub tsev qiv ntawv kawg (PubSubClient) sib txuas lus nrog MQTT tus tswv lag luam, thov rub lub tsev qiv ntawv los ntawm qhov txuas hauv qab no:
Unzip cov ntaub ntawv saum toj no, txav daim nplaub tshev unzipped rau Arduino IDE lub tsev qiv ntawv tais ceev tseg.
Qhib Arduino IED, koj tuaj yeem pom "pubsubclient" ntawm kab ntawv "Piv txwv".
Nruab MQTT Client:
peb yuav siv MQTTBox ua MQTT cov neeg siv khoom. thov rub tawm los ntawm:
Kauj ruam 2: Code
qhib Arduino IDE–> File–> Piv txwv li> pubsubclient–> mqtt esp8266, koj yuav tau txais cov qauv piv txwv.
Kho qhov chaws kom haum rau koj tus kheej WiFi thiab MQTT teeb tsa raws li kev ua haujlwm hauv qab no: 1) Hotspot Configration: Nrhiav hauv qab kab kab, tso koj tus kheej ssid thiab password rau ntawd.
const char* ssid = "your_hotspot_ssid"; const char* password = "your_hotspot_password";
2) MQTT Server Chaw Nyob, ntawm no peb siv dawb MQTT broker "broker.mqtt-dashboard.com". Koj tuaj yeem siv koj tus kheej MQTT tus broker URL lossis IP chaw nyob los teeb tsa saum mqtt_server tus nqi. Koj kuj tseem tuaj yeem siv qee tus pub dawb MQTT server los sim qhov haujlwm xws li "broker.mqtt-dashboard.com", "iot.eclipse.org" thiab lwm yam.
const char* mqtt_server = “broker.mqtt-dashboard.com”;
3) MQTT Client SettingsIf koj li MQTT broker xav tau clientID, lub npe siv thiab tus password lees paub tseeb, koj xav tau
hloov
yog (client.connect (clientId.c_str ()))
Rau
yog (client.connect (clientId, userName, passWord)) // tso koj tus clientId/userName/passWord ntawm no
Yog tias tsis yog, cia li khaws lawv ua lub hauv paus Tom qab ua li ntawd, xaiv hom pawg thawj coj saib xyuas thiab hom chaw nres nkoj raws li hauv qab no, tom qab ntawd rub cov duab kos rau NodeMCU.
- Pawg thawj coj: "NodeMCU 0.9 (ESP-12 Module)"
- CPU Zaus: "80MHz" Flash Loj: "4M (3M SPIFFS)"
- Upload Ceev: "115200 ″
- Chaw nres nkoj: Xaiv koj tus kheej Serial Port rau koj NodeMCU
Kauj Ruam 3: Kho MQTT Client (MQTTBOX)
Hauv theem no, peb yuav qhia yuav ua li cas thiaj tsim tau MQTT tus neeg siv khoom ntawm MQTTBox.
Qhib koj lub MQTTBox thiab nyem lub pob xiav kom ntxiv MQTT tus neeg siv khoom tshiab.
Kho qhov MQTT CLIENT SETTINGS raws li hauv qab no:
- MQTT Client Name - Xaiv ib lub npe uas koj nyiam
- Raws tu qauv - Xaiv “mqtt/tcp”
- Tus tswv tsev - Ntaus koj "mqtt_server" hauv kab ntawv no, xyuas kom nws zoo ib yam li koj daim duab. (Peb siv "broker.mqtt-dashboard.com" ntawm no)
- Khaws lwm qhov chaw raws li lub neej ntawd
- Nyem rau txuag koj qhov kev hloov pauv.
Tom ntej no, koj yuav nkag mus rau nplooj ntawv tshiab yog tias txhua qhov teeb tsa saum toj no raug, "Tsis Txuas" yuav hloov mus rau "Txuas", koj MQTT tus neeg siv lub npe thiab Tus tswv lub npe yuav tshwm nyob rau saum toj ntawm nplooj ntawv no.
Cov ncauj lus teeb tsa: Nco ntsoov tias koj MQTT cov neeg siv tshaj tawm cov ncauj lus zoo ib yam li koj li Arduino kos duab kos npe sau npe cov ncauj lus (inTopic ntawm no). Ua kom ntseeg tau tias koj MQTT cov neeg siv khoom sau npe lub ncauj lus zoo ib yam li koj daim duab Arduino tshaj tawm cov ncauj lus (tawmTopic ntawm no).
Kauj Ruam 4: Txoj Haujlwm Khiav Haujlwm
Thaum qhov upload tiav, yog tias lub npe wifi hotspot thiab tus password nkag mus tau zoo, thiab MQTT broker txuas nrog, qhib Serial Monitor, koj yuav pom cov lus tshaj tawm "nyob zoo ntiaj teb" ntawm tus saib xyuas.
Tom qab ntawd qhib MQTT tus neeg siv khoom thiab tshaj tawm cov nyiaj them "1" rau lub ncauj lus, NodeMCU no yuav tau txais cov lus no los ntawm kev sau npe rau "inTopic", thiab LED yuav taws.
Tshaj tawm cov nqi "0" rau lub ncauj lus no, NodeMCU LED yuav raug muab tua.
Pom zoo:
Niaj hnub nimno thiab Tshiab thiab Yooj Yim Piv Txwv Ntawm Cov Xauv Nrog Arduino Matrix Keypad 4x4: 3 Cov Kauj Ruam
Niaj hnub nimno thiab Tshiab thiab Yooj Yim Piv Txwv Ntawm Lub Xauv Nrog Arduino Matrix Keypad 4x4: Lwm qhov piv txwv ntawm kev siv lub LCD keypad matrix 4x4 nrog I2C Circuit Court
Ua piv txwv koj yog Xyzzy Server ntawm Raspberry Pi: 19 Cov Kauj Ruam
Ua piv txwv Koj yog Xyzzy Server ntawm Raspberry Pi: Phau ntawv qhia no yuav qhia koj yuav teeb tsa li cas ua ntej koj yog Xyzzy (PYX) server ntawm Raspberry Pi. Kuv hu nws XyzzyPiPretend Koj Xyzzy yog online, qhib-daim npav-tiv thaiv Tib neeg clone ua si hauv lub vev xaib. Hauv Android koj tuaj yeem siv Clien
APP INVENTOR 2 - Huv Lub Hauv Paus Qhia (+4 Piv Txwv): 6 Cov Kauj Ruam
APP INVENTOR 2 - Cov Lus Qhia Ua Ntej Ua Ntej (+4 Piv txwv): Peb yuav pom tias peb tuaj yeem ua koj li App ntawm AI2 zoo li cas zoo nkauj :) Tsis muaj tus lej lub sijhawm no, tsuas yog cov lus qhia rau app yooj yim zoo li 4 piv txwv saum toj
IoT Guru Huab - Piv Piv Piv Txwv: 4 Kauj Ruam
IoT Guru Cloud - Piv Txwv Daim Qauv Yooj Yim: IoT Guru Cloud tau muab cov kev pabcuam rov qab los ntawm REST API thiab koj tuaj yeem sib sau cov REST hu rau koj lub vev xaib yooj yim. Nrog Highcharts, koj tuaj yeem tso tawm kab kos ntawm koj qhov kev ntsuas yooj yim nrog AJAX hu
Ua Ntej Qhia Kom Siv Cov Av Huv Huv Sensor W/ Piv Piv Txwv: 7 Kauj Ruam
Ua Ntej Qhia Kom Siv Cov Av Huv Huv Sensor W/ Piv Piv Txwv: Koj tuaj yeem nyeem qhov no thiab lwm yam kev qhia zoo ntawm ElectroPeak lub vev xaib raug cai Cov piv txwv tseem ceeb kuj tau muab los pab koj ua tus coj txoj cai.Koj Yuav Kawm Dab Tsi: Yuav av li cas