Cov txheej txheem:

RaspberryPi thiab NodeMCU (esp8266) -MQTT: 3 Cov Kauj Ruam
RaspberryPi thiab NodeMCU (esp8266) -MQTT: 3 Cov Kauj Ruam

Video: RaspberryPi thiab NodeMCU (esp8266) -MQTT: 3 Cov Kauj Ruam

Video: RaspberryPi thiab NodeMCU (esp8266) -MQTT: 3 Cov Kauj Ruam
Video: Расшифровка пультов дистанционного управления гаражными воротами 2024, Kaum ib hlis
Anonim
RaspberryPi thiab NodeMCU (esp8266) -MQTT
RaspberryPi thiab NodeMCU (esp8266) -MQTT

Peb tab tom teeb tsa MQTT server thiab cov neeg siv khoom ntawm Raspberry Pi siv Mosquitto thiab paho-mqtt tsev qiv ntawv. Peb yuav nyeem lub pob thiab yog nws raug nias peb yuav Toggle LED ntawm Arduino sab.

Whereas, ntawm Arduino peb yuav siv Adafruit MQTT lub tsev qiv ntawv. Peb yuav siv lub ntsuas zoo li LDR (Koj tuaj yeem siv lwm lub ntsuas), nyeem nws thiab tshaj tawm sai li sai tau thaum nws hloov pauv rau Raspberry Pi.

Peb xav tau:

Raspberry Pi

NodeMCU

Kauj Ruam 1: Ntxiv Cov Tsev Qiv Ntawv rau Esp8266

Ntxiv Tsev Qiv Ntawv rau Esp8266
Ntxiv Tsev Qiv Ntawv rau Esp8266

Mus rau "Tswj Cov Tsev Qiv Ntawv …" siv koj li Arduino IDE thiab tshawb rau "MQTT" los ntawm Adafruit.

Tom qab ua tiav kev teeb tsa, Ntxiv "MQTT_NodeMCU.ino" los ntawm qhov txuas hauv qab no:

Arduino Txoj Cai

Ua cov kev hloov hauv qab no los ntawm kev hloov wifi ssid, password thiab RPi IP Address.

#define WLAN_SSID " #397" #define WLAN_PASS "farmhouse397" #define MQTT_SERVER "192.168.0.108" #define "led_pin" #define "sensor_input"

Upload cov duab kos thiab qhib Serial Monitor ntawm 115200

Kauj Ruam 2: Nruab MQTT Sever thiab Client ntawm Raspberry Pi

Nruab MQTT Sever thiab Client ntawm Raspberry Pi
Nruab MQTT Sever thiab Client ntawm Raspberry Pi

Ua ntej, Nruab Mosquitto server siv:

sudo apt-tau nruab mosquitto

Nruab Mosquitto Client siv:

sudo apt-tau nruab mosquitto-cov neeg siv khoom

Koj tuaj yeem lees paub Kev Txhim Kho siv:

systemctl xwm txheej mosquitto.service

Tam sim no, peb yuav teeb tsa paho-MQTT siv:

sudo apt-tau nruab python python-pipsudo pip nruab RPi. GPIO paho-mqtt

Siv cov lus txib no tshaj tawm -messages los ntawm raspberry pi (-hostname) rau esp8266-leds (-topic).

mosquitto_pub -h raspberrypi -t "/leds/esp8266" -m "ON"

mosquitto_pub -h raspberrypi -t "/leds/esp8266" -m "OFF"

-h ==> host name ==> raspberrypi (tshwj tsis yog koj tau hloov nws)

-t ==> ntsiab lus

-m ==> lus

Kauj ruam 3: Khiav Python Script

Koj tuaj yeem rub tawm MQTT_Pi los ntawm

github.com/anuragvermaa/MQTT_NodeMCU

Yog tias txhua yam zoo, koj yuav tsum tuaj yeem pom cov ntaub ntawv sensor hauv lub davhlau ya nyob twg.

Nias Ctrl+C kom tawm mus.

Pom zoo: