# How to connect node-red with mqtt broker

**URL:** https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207
**Category:** Dashboard
**Tags:** node-red-dashboard
**Created:** [20 October 2023 07:05 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207 "2023-10-20T07:05:05Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.nodered.org/u/Naveen)
#### Post date: [20 October 2023 07:05 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/1 "2023-10-20T07:05:05Z")

</div>

Hi everyone,  
i'm new to node-red,  
i have installed node-red and node-red is running in my local.  
i'm using mqtt explorer, there i'm giving mqtt broker credentials for sending and recieving control and command messages.  
here, i was confused that how to connect node-red with mqtt.  
i have given mqtt credentials in node-red but how to check it is connected or not with mqtt broker.  
can anyone please help me

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 October 2023 07:14 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/2 "2023-10-20T07:14:47Z")

</div>

Hi and welcome to the forum.

First off you need to have MQTT installed on one of your machines. Unless you are using an external MQTT broker.

If on a local machine, you need to be sure it is running/active.

Put either a `MQTT IN` or `MQTT OUT` node in your flow.

Double click on it and click on the `v`

 ![Screenshot from 2023-10-20 18-08-37](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/e/1eef64555b17bdee207a97523f514ec2cc0b15fc.png)

To add a server

Then click on the pencil icon/button

 ![Screenshot from 2023-10-20 18-11-17](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c8158f06fba9d56e824728c3c80dfc560e6997a.png)

Then enter the details as needed

 ![Screenshot from 2023-10-20 18-11-27](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/a/aa30b8e0771941252ec02519d6f6029e0a688555.png)

Then you should be able to connect to it fairly easily.

Hope that helps.

---

<div class="post-metadata">

### Author: ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.nodered.org/u/Naveen)
#### Post date: [20 October 2023 07:29 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/3 "2023-10-20T07:29:04Z")

</div>

i was getting this error, when i click the mqtt out node  
Invalid properties  
Invalid topic specified  
Server: invalid configuration node

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 October 2023 07:29 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/4 "2023-10-20T07:29:45Z")

</div>

Did you set up the server as I showed?

---

<div class="post-metadata">

### Author: ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.nodered.org/u/Naveen)
#### Post date: [20 October 2023 07:31 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/5 "2023-10-20T07:31:38Z")

</div>

yes i have set up the server, can you tell me how to delete that connection, i will create new connection in mqtt in node.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 October 2023 07:34 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/6 "2023-10-20T07:34:21Z")

</div>

I would suggest you study a bit more on how MQTT works.

This is an EXAMPLE on how to use it.

```auto
## How to send MQTT messages

-h HOST
-t TOPIC
-m MESSAGE

mosquitto_sub -h 192.168.1.10 -t armtronix_mqtt

mosquitto_pub -h 192.168.1.10 -t armtronix_mqtt -m "Hi this is Armtronix_server"

```

The IP address will need to be changed depending on what your broker's address is.  
And you will need TWO CLI's open.  
~~One to send and one to receive.~~  
One to receive. (Do that first of course)  
One to send.

---

<div class="post-metadata">

### Author: ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.nodered.org/u/Naveen)
#### Post date: [20 October 2023 07:52 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/7 "2023-10-20T07:52:31Z")

</div>

i have one doubt, i'm using mqtt explorer, i have given mqtt broker credentials such as username, password, host and port and also subscribing the topic in the mqtt explorer.  
i'm connecting mqtt broker by using above credentials.  
i'm sending command and control messages through postman, those messages will appear in the mqtt explorer.  
here, in the node-red simulator, i'm giving mqtt broker credentials to connect mqtt with node-red, if i send the command and control messages through postman, will those messages appear in the node-red.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 October 2023 07:59 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/8 "2023-10-20T07:59:41Z")

</div>

POSTMAN - outside program.  
NODE-RED SIMULATOR - I don't want to know.

If you have MQTT EXPLORER running and post a message, you should see it.

But given you are also using encryption that is only slightly more complicated. But not impossible.  
You just include the password in the line/example I showed you.

In/on the MQTT configuration you click on the SECURITY tab.

As you didn't really declare that in your first post, I didn't know to include it in my reply.

 ![Screenshot from 2023-10-20 18-57-00](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/f/2f42a14e5c9b4334186ed6d27e32b86368ad0d57.png)

I am not a smart person but even I got it working with security.

Establish a basic thing before you start complicating things with other programs.

---

<div class="post-metadata">

### Author: ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.nodered.org/u/Naveen)
#### Post date: [20 October 2023 08:05 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/9 "2023-10-20T08:05:05Z")

</div>

i tried this in the mqtt out node flow, when i click on the mqtt out node flow, it was showing like below:  
Invalid properties  
Invalid topic specified  
Server: invalid configuration node

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 October 2023 08:06 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/10 "2023-10-20T08:06:07Z")

</div>

It would go A LONG WAY if you actually SHOWED me something.

I can't read your mind.

SCREEN SHOT  
Export the node

Something.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 October 2023 08:08 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/11 "2023-10-20T08:08:32Z")

</div>

Open read and study this link:

> **[Introducing the MQTT Protocol - MQTT Essentials: Part 1](https://www.hivemq.com/blog/mqtt-essentials-part-1-introducing-mqtt/)**
>
> What is MQTT, what does MQTT stand for, why should you use MQTT in IoT or IIoT? Get answers to all these questions here.

Or even this one which is **THE** home of mosquitto.

> **[Eclipse Mosquitto](https://mosquitto.org/)**
>
> Eclipse Mosquitto is an open source (EPL/EDL licensed) message broker that
> implements the MQTT protocol versions 5.0, 3.1.1 and 3.1. Mosquitto
> is lightweight and is suitable for use on all devices

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [20 October 2023 08:11 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/12 "2023-10-20T08:11:48Z")

</div>

What MQTT broker are you using? In the cloud eg hivemq, or on a local machine?  
If it's on a local machine, what it it's IP address?  
What is the local IP address of your Node-red machine?

---

<div class="post-metadata">

### Author: ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.nodered.org/u/Naveen)
#### Post date: [20 October 2023 10:27 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/13 "2023-10-20T10:27:26Z")

</div>

local machine  
local IP address of Node-red machine:  
[http://localhost:1880](http://localhost:1880)

---

<div class="post-metadata">

### Author: ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.nodered.org/u/Naveen)
#### Post date: [20 October 2023 10:30 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/14 "2023-10-20T10:30:50Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/7152f0ff6c04d1e13f468e92fdb2f5c2c3a360f8.png)  
in the above screenshot, [mqtt.eclipse.org](http://mqtt.eclipse.org) name indicating as blue means is it connected ?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [20 October 2023 10:37 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/15 "2023-10-20T10:37:36Z")

</div>

> [@Naveen](#):
>
> in the above screenshot, [mqtt.eclipse.org](http://mqtt.eclipse.org) name indicating as blue means is it connected

No, that means you have not clicked Deploy to deploy the flow. If the node connects the broker it will say Connected under it.

---

<div class="post-metadata">

### Author: ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.nodered.org/u/Naveen)
#### Post date: [20 October 2023 10:47 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/16 "2023-10-20T10:47:19Z")

</div>

how to deploy, before deploying is there anything to do.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [20 October 2023 10:49 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/17 "2023-10-20T10:49:31Z")

</div>

> [@Naveen](#):
>
> how to deploy,

Click the button labelled Deploy.

Since it seems you are an absolute beginner, I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

### Author: ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.nodered.org/u/Naveen)
#### Post date: [20 October 2023 11:08 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/18 "2023-10-20T11:08:27Z")

</div>

![Screenshot from 2023-10-20 16-36-29](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/0/10de1c7211ccf465f31d73047f08baf5d78209f7.png)  
ti's already 10 mins but still it's showing connecting

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [20 October 2023 11:11 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/19 "2023-10-20T11:11:57Z")

</div>

With that node selected export it to the clipboard (using Export in the menu dropdown) and paste it here. When pasting use the `</>` button at the top of the forum entry window and paste it where indicated. The export will not include your login credentials.

---

<div class="post-metadata">

### Author: ![Naveen](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@Naveen](https://discourse.nodered.org/u/Naveen)
#### Post date: [20 October 2023 11:58 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/20 "2023-10-20T11:58:47Z")

</div>

```auto
[
    {
        "id": "4ded4991b2855626",
        "type": "mqtt in",
        "z": "6c089015cb59fe9b",
        "name": "mqtt.eclipse.org",
        "topic": "command///req/#",
        "qos": "2",
        "datatype": "json",
        "broker": "0fa35b472b900473",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 140,
        "y": 80,
        "wires": [
            []
        ]
    },
    {
        "id": "0fa35b472b900473",
        "type": "mqtt-broker",
        "name": "",
        "broker": "c2e-mqtt.eclipse.com",
        "port": "30883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]

```

Admin edit, added backticks around flow to make it usable

[Next page](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207.md?page=2)
