MQTT protocol is light weight and popular internet of things protocol that works on the subscribe/publish model. The popularity of MQTT is because of the its performance on unreliable networks. Many giant companies has been using MQTT protocol for different purposes. Read more about What is MQTT protocol and the terminologies of MQTT protocol.
MQTT broker using Raspberry piIn order to use MQTT protocol, we need to have MQTT broker, which is brain of MQTT protocol and is responsible for receiving all the messages and then forward the messages to the subscribed devices. The broker is also responsible for deciding which message to send to which devices, as it already has the information of devices, i.e., devices have already subscribed to different topics.
Raspberry pi zero is a cheapest way you can use to set up your own MQTT broker.
ESP8266 Communicates with Pi using MQTT Local BrokerLocal MQTT Broker, which we used in last project is a MQTT broker within the network. That means, All the devices and things should be in the same network.
Here is operation flow,
- We will install the libraries of the MQTT protocol in nodemcu.
- We will write the code to publish DHT11 sensor data as an MQTT message from esp8266 to nodemcu.
- Then we will subscribe to a topic to receive the MQTT message sent from raspberry pi to esp8266 and depending on that message we will control the LED.
- We will use the shell terminal in raspberry pi to publish-subscribe MQTT messages.
Read this to get code and complete circuit diagram, How to make ESP8266 talk with Raspberry pi using MQTT protocol.
or watch video,
Using Cloud MQTTMQTT broker on cloud is a broker on cloud. That means, It does not matter where you are. You will just need internet connection to connect to the broker.
The other components will remain same. How to use ESP8266 with MQTT Cloud will help you understand the differnces.
Comments
Please log in or sign up to comment.