Étape 3 - What is MQTT?
MQTT stands for Message Queuing Telemetry Transport. MQTT is a machine-to-machine connectivity protocol. It is useful for connections with remote locations where we want to send just a few bytes of data or our sensor values. It is a system where you can publish and receive messages as a client.
By using MQTT you can send commands to control outputs, read and publish data from sensors and much more. Therefore, by using MQTT you can establish communication between multiple devices. Using MQTT you can send a command to a client to control output, or you can read data from a sensor and publish it to a client. There are two main terms in MQTT i.e. Client and Broker. Let’s discuss what client and broker are.
MQTT Client: An MQTT client is any device that runs an MQTT library and connects to an MQTT broker over a network. Both publisher and subscriber are MQTT clients. The publisher and subscriber refer that whether the client is publishing messages or subscribing to messages.
MQTT Broker: The broker receives all messages, filters the messages, determines who is subscribed to each message, and sends the message to these subscribed clients.
In the last Node Red series, we have seen how to install and use the Node Red on Raspberry Pi. Just use that one to get started with the Node Red
Now just start the Node Red in Raspberry Pi by using this command.
node-red
Next, in your browser, go to the URL mentioned above. The Node-RED dashboard is now visible.
This is how the Node-RED Dashboard page appears.
First, we must install the MQTT Plugin for Node-RED. To do so, go to the menu option.
Choose "Manage Palette" from the drop-down menu.
Install MQTT Plugin by going to Palette and searching for it.
After successful installation, the MQTT In and MQTT Out menus appear in the network section.
Select MQTT Out and add it to the flow, then select Injection Palette and add it to the flow, making a connection between MQTT Out and Injection Palette.
The next stage is to connect the Node-Red to the cloud. For this, we have to use MQTT nodes. You can see those nodes in the node pallets.
We can use the mqtt out node to send our data to the cloud. Open the mqtt out node's properties. We have to add our MQTT broker's credentials.
And click on the edit new mqtt broker.
Now we have to add our server details.