How To Create Node Red Flow For MQTT Message Publish

Introduction

In this article, we will explore how to start publishing MQTT messages continuously every hour and stop the action with Node-RED to create powerful IoT applications.

What is Message Queuing Telemetry Transport(MQTT)?

MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol commonly used in IoT (Internet of Things) applications to send and receive messages between devices. Node-RED is a flow-based programming tool that makes connecting IoT devices, APIs, and other services easy.

Prerequisite

  1. Installation of Node-Red, which is up and running.
  2. Add a New MQTT broker server; in our case, we will use HIVEMQBroker, which is free for testing.
  • Server: broker.hivemq.com
  • Protocol: MQTT V3.1.1
  • Port: 1883

How To Create Node Red Flow For MQTT Message Publish

STEP 1

Drag an Inject input node onto the workspace and double-click on it to configure it. Specify the message to be injected and the interval at which the node should repeat the injection.

How To Create Node Red Flow For MQTT Message Publish

STEP 2

Drag the Trigger node onto the workspace and double-click on it to configure it. Specify the message to be injected and the reset trigger information to stop the process based on the matched payload. The trigger will be reset when the payload matches the string "stop".

How To Create Node Red Flow For MQTT Message Publish

STEP 3

To start publishing MQTT messages in your Node-RED application, you must drag and drop the appropriate nodes onto the workspace. For example, to publish messages to the MQTT broker, you would drag an MQTT publish node onto the workspace, double-click on it to configure it, and specify the MQTT topic that you want to publish and connect the input node( Trigger node), where the message will be injected.

How To Create Node Red Flow For MQTT Message Publish

With this flow, when the input node button is pressed, the MQTT input node will send the message and trigger the flow. The flow will then publish a message to the trigger node, where the message will be sent to the MQTT publish node, which then publishes the message to the topic sensor/1, which the MQTT client can consume.

How To Create Node Red Flow For MQTT Message Publish

How To Create Node Red Flow For MQTT Message Publish

Conclusion

MQTT is a powerful messaging protocol that is widely used in IoT applications. Using Node-RED with MQTT, you can easily create complex IoT applications connecting devices, APIs, and other services. With the MQTT input and output nodes, you can easily subscribe to and publish messages to MQTT topics, making integrating MQTT into your Node-RED flows easy. So, if you're building an IoT application, consider using MQTT and Node-RED to make your life easier!


Recommended Free Ebook
Similar Articles