Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

13/05/2024, 13:19 Connect Node-RED to HiveMQ Cloud an MQTT Broker • FlowFuse

ARTICLE

Connect Node-RED to HiveMQ


Cloud an MQTT Broker
A Guide to Connecting HiveMQ with Node-RED

Back to Blog Posts

In the world of IIoT (Industrial Internet of Things), effective and efficient


communication between devices is crucial. One protocol that has gained
significant popularity for its lightweight and scalable nature is MQTT (Message
Queuing Telemetry Transport). This post explains what MQTT is, highlight its
relevance in IIoT, and walk you through the process of connecting a broker
(HiveMQ) with Node-RED in FlowFuse.

Understanding MQTT
MQTT, of which development started in 1999, is a publish-subscribe-based
messaging protocol designed to enable efficient communication between IoT
https://flowfuse.com/blog/2023/06/connect-to-hivemq-in-flowforge/ 1/6
13/05/2024, 13:19 Connect Node-RED to HiveMQ Cloud an MQTT Broker • FlowFuse

devices. It operates on top of TCP/IP like for example HTTP, and provids a
lightweight approach
SIGN IN to messaging. MQTT follows a client-server
FREEmodel,
TRIAL where
devices, known as clients, publish messages to a central server called the broker.
Other clients, interested in receivingTALK
thoseTOmessages,
SALES subscribe to specific topics
on the broker.

The Advantages of MQTT in IIoT


There are several reasons why MQTT has become a preferred choice for IoT and
industrial IoT applications:

1. Low Overhead: MQTT uses a small packet size, minimizing bandwidth


consumption and reducing network traffic, making it suitable for low-power
devices and networks.
2. Reliability: MQTT incorporates a Quality of Service (QoS) mechanism that
ensures message delivery, making it ideal for applications that require reliable
data transmission.
3. Asynchronous Communication: MQTT enables asynchronous
communication, allowing devices to operate independently, reducing latency
and increasing system responsiveness.

Sending messages to a MQTT broker with


Node-RED
As broker we'll use a Cloud MQTT broker provided by HiveMQ. We'll use FlowFuse
to host and manage the Node-RED instance for us. After opening the editor the
MQTT nodes are pre-installed as these are "Core Nodes" in Node-RED.

Drag in the "Inject" node, as well as the "MQTT out" node and connect the Injects
output to the MQTT out node. Now it's time to configure the MQTT node to
connect to the broker. On HiveMQ you should generate both a username and
password, afterwards copy and paste those to the Node-RED MQTT Server config
pane, along with the server details:

https://flowfuse.com/blog/2023/06/connect-to-hivemq-in-flowforge/ 2/6
13/05/2024, 13:19 Connect Node-RED to HiveMQ Cloud an MQTT Broker • FlowFuse

SIGN IN FREE TRIAL

TALK TO SALES

After saving the config, and deploying the changes, the flow should tell display a
green status bubble under the MQTT node which tells you it's connected and
configured properly.

If we than set the Inject node to send a message every say 1 second, the
timestamp will be sent to the broker through MQTT!

Receiving message from a MQTT broker with


Node-RED
Drag in the "mqtt in" node, and connect it to the "Debug" node. Open the MQTT in
node, and select the server configured. Do note that the topic this node is listening
on must match what was previously selected.

https://flowfuse.com/blog/2023/06/connect-to-hivemq-in-flowforge/ 3/6
13/05/2024, 13:19 Connect Node-RED to HiveMQ Cloud an MQTT Broker • FlowFuse

SIGN IN FREE TRIAL

TALK TO SALES

When deployed you should again see the status bubble turn green, and have a
timestamp appear in the sidebar every second!

Conclusion
MQTT has emerged as a lightweight and efficient messaging protocol for IIoT
applications. Its low overhead, reliability, and asynchronous communication make
it an good choice. By following the steps outlined above, you can easily connect
MQTT using HiveMQ with Node-RED and leverage the power of MQTT in your
applications.

For the sake of simplicity we've sent messages from one Node-RED to another
Node-RED. Sending data from and to a Node-RED is much easier achieved with the
FlowFuse Project Nodes.

Written By:
ZJ van de Weg
CEO

Published on: 13 Jun, 2023

https://flowfuse.com/blog/2023/06/connect-to-hivemq-in-flowforge/ 4/6
13/05/2024, 13:19 Connect Node-RED to HiveMQ Cloud an MQTT Broker • FlowFuse

Recommended
SIGN INArticles: FREE TRIAL
Comprehensive guide: Node-RED
TALK TO SALES
Dashboard 2.0 layout, sidebar, and styling
FlowFuse 2.4: making it easier to work
with Snapshots, Blueprints & Devices
Run FlowFuse on Robustel EG5120
Understanding Node, Flow, Global, and
Environment Variables in Node-RED
Using Webhooks with Node-RED

Sign up for updates


Email*

Enter your email

SIGN UP

https://flowfuse.com/blog/2023/06/connect-to-hivemq-in-flowforge/ 5/6
13/05/2024, 13:19 Connect Node-RED to HiveMQ Cloud an MQTT Broker • FlowFuse

SIGN IN FREE TRIAL

About Privacy TALK TO SALES Contact Us

Team Partnerships Sign Up to Mailing List

Jobs Service Status

Handbook Request Support

Copyright 2024 FlowForge Inc. DBA FlowFuse. All Rights Reserved.


This site uses cookies. Click here to manage your preferences.

https://flowfuse.com/blog/2023/06/connect-to-hivemq-in-flowforge/ 6/6

You might also like