# 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:** 2

<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 12:23 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/21 "2023-10-20T12:23:46Z")

</div>

I have corrected the flow formatting. You should have used the `</>` button at the top of the forum entry window. In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````) . The `</>` button provides those

````auto
``` 
   code goes here 
```

````

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<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 12:29 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/22 "2023-10-20T12:29:57Z")

</div>

> [@Naveen](#):
>
> ```auto
> "broker": "c2e-mqtt.eclipse.com",
> "port": "30883",
> 
> ```

Is that the same broker and port that you have used successfully in mqtt explorer?

> [@Naveen](#):
>
> ```auto
> "topic": "command///req/#",
> 
> ```

That does not look like a valid topic.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [20 October 2023 12:33 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/23 "2023-10-20T12:33:55Z")

</div>

> [@jbudd](#):
>
> What MQTT broker are you using? In the cloud eg hivemq, or on a local machine?

I'm confused... in reply to the question asked above by @jbudd you said... 'local machine'.  
Now you are showing a reference to [mqtt.eclipse.org](http://mqtt.eclipse.org)  
Where is the MQTT broker - local or remote?

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [20 October 2023 12:48 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/24 "2023-10-20T12:48:04Z")

</div>

If you are using the test-server at Eclipse, then try this very simple flow and see if it works for you.

![eclipse](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/b/bb9b8669ae3959c45d97766a67802058e4e1c860.png)

![clipse_debug](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5cc4b50442e2726994a11140f1c85201d28a8ea9.png)

```auto
[{"id":"a4261bec1cbf0778","type":"tab","label":"Flow 39","disabled":false,"info":"","env":[]},{"id":"1678825c5d940452","type":"mqtt in","z":"a4261bec1cbf0778","name":"","topic":"test","qos":"2","datatype":"auto-detect","broker":"2d2f5234db1e57bd","nl":false,"rap":true,"rh":0,"inputs":0,"x":150,"y":220,"wires":[["9ef778879f8ca7c5"]]},{"id":"981d13a9a47220e3","type":"mqtt out","z":"a4261bec1cbf0778","name":"","topic":"test","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"2d2f5234db1e57bd","x":330,"y":140,"wires":[]},{"id":"e553550126382b67","type":"inject","z":"a4261bec1cbf0778","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Hello World","payloadType":"str","x":170,"y":140,"wires":[["981d13a9a47220e3"]]},{"id":"9ef778879f8ca7c5","type":"debug","z":"a4261bec1cbf0778","name":"repsonse","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":340,"y":220,"wires":[]},{"id":"2d2f5234db1e57bd","type":"mqtt-broker","name":"Eclipse","broker":"test.mosquitto.org","port":"1883","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":""}]

```

Note:  
As this is a **test-broker** , anyone can publish and subscribe to it (see example below).  
 ![clipse_debug_a](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/47f2e044f9e44da99d4e4191fddfcfb9dd9a1fa8.png)

You will probably want to think about this issue and maybe organise a private-broker for your project.

---

<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 14:28 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/25 "2023-10-20T14:28:20Z")

</div>

I blame myself. I should have asked the questions like this

> 1. What is the name of the MQTT broker you are using?
> 2. Is it in the cloud (eg hivemq), or on a local machine (eg Mosquitto)?
> 3. If the MQTT broker is on a local machine, what is it's IP address (eg 192.168.1.10)?
> 4. What is the local IP address of your Node-red machine (eg 192.168.1.2)?
> 
> I wanted to know if Node-red and MQTT broker are installed on the same machine because there are extra setup steps for the broker if it's on a different machine.

Note that "localhost" doesn't tell us anything useful regarding MQTT, though it does indicate that you access Node-red from a browser on the same machine it's installed on.

---

<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 November 2023 10:02 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/26 "2023-11-20T10:02:10Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/66a54c584b6da1b8b60352cd9b6c0ad0fe0ed821.png)  
i have created these nodes, when i deploying these nodes, it was showing connecting but it's not connecting, can you help me why it is not connecting.

---

<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 November 2023 10:05 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/27 "2023-11-20T10:05:27Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/2/5250e41cfb25e6f47dd7c2d86bfd883a35243d9a.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/27f1d33ff4c378b98bf6947cf1b278231b16a073.png)

---

<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 November 2023 10:32 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/28 "2023-11-20T10:32:11Z")

</div>

Have you successfully connected to the broker using MQTTExplorer?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 November 2023 10:41 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/29 "2023-11-20T10:41:35Z")

</div>

> [@Naveen](#):
>
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/27f1d33ff4c378b98bf6947cf1b278231b16a073.png)

Also, that subscription topic is **invalid** and will likely cause any broker to disconnect the client (in this case, the client is your node-red MQTT nodes)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 November 2023 10:47 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/30 "2023-11-20T10:47:42Z")

</div>

As @Steve-Mcl said, your topic is invalid. I suggest you go to this link and read about MQTT topics.

> **[MQTT Topics, Wildcards, & Best Practices – MQTT Essentials: Part 5](https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices/)**
>
> Learn about MQTT Topics, naming conventions, MQTT $SYS topics, MQTT Prefix, MQTT Topic Wildcards, and more in this MQTT Essentials article.

---

<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 November 2023 10:57 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/32 "2023-11-20T10:57:31Z")

</div>

yes, i connected to the broker using MQTTExplorer.

---

<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 November 2023 10:59 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/33 "2023-11-20T10:59:04Z")

</div>

Note that I pointed out on October 20 that you were trying to use an invalid topic.

---

<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 November 2023 12:02 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/34 "2023-11-20T12:02:57Z")

</div>

A while ago you showed us this to demonstrate that you were using the Eclipse broker.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/6/46a73385c1fdad55261627d14d4ccd6f8a0cc494.png)

Now you show us this  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8ed9f2c4cda0da1ded9b145b73f557376e6d8459.png)  
I can find no reference to a public MQTT service at InfyOm Technologies.  
I am dubious about the first part of each server's URL being the same and the port number being different but similar.

In short, you are unable to connect because the URL or the port number or the security credentials in your MQTT broker config node are wrong. Or just possibly, because your machine does not have free access to the internet due to a corporate proxy server.

Since we know almost nothing about your setup and you keep changing without explanation the information you give us, it is IMPOSSIBLE TO HELP YOU.

Incidentally I tried mqtt topics such as test///test and test///test/# using Mosquitto. It did not complain, but repeated / characters are not ignored (as they would be in a Linus pathname for instance)

---

<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:** [22 November 2023 07:03 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/35 "2023-11-22T07:03:53Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/7/d79b5aada667be3362ce054951b5558985d61411.png)  
i connected my local mqtt broker with Node-red iot simulator, i have a doubt that, here i'm sending command & control messages through postman to Node-red simulator.  
is it possible to recieve the command & control messages in the Node-red using postman.  
can you tell me how to see server logs on Node-red simulator.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [22 November 2023 07:41 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/36 "2023-11-22T07:41:48Z")

</div>

Did you ever try out the test flow I posted above (item 23 in this thread) that uses the Eclipse test-server??

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 November 2023 09:26 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/38 "2023-11-22T09:26:29Z")

</div>

> [@johnsmithe34](#):
>
> **1. Install the MQTT Node**
> 
> Before you can use the MQTT nodes, you'll need to install the MQTT node package. You can do this by following these steps:
> 
> 1. Open the Node-RED admin page.
> 2. Click on the "Manage palette" button.
> 3. Search for "mqtt" and click on the "Install" button.

MQTT nodes come as part of the core installation. Please dont instruct the user to install non core MQTT nodes without good reason.

* * *

I hope you dont mind me asking was this written by an AI bot for you? It looks suspiciously like a ChatGPT / Bard / AI generated response.

---

<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:** [22 November 2023 12:33 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/40 "2023-11-22T12:33:12Z")

</div>

yes, i tried.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7dc4395d1324b95262f95456ba87e4725e530b78.png)  
i was getting missing broker configuration, how to provide broker configuration in the node-red simulator.  
i'm able to send command & control messages sent successfully through postman, but i'm not getting anything in the node-red simulator.

---

<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:** [22 November 2023 12:51 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/41 "2023-11-22T12:51:16Z")

</div>

> [@Naveen](#):
>
> i was getting missing broker configuration

The debug message shows you which node issued the error message.  
Is your node ThingsUniverse related to MQTT?

> [@Naveen](#):
>
> node-red simulator.

You are using the Node-red editor.  
There is no such thing as a Node-red simulator.

> [@Naveen](#):
>
> i was getting missing broker configuration, how to provide broker configuration in the node-red simulator.

You already know how to configure the mqtt broker in Node-red.  
The status of your mqtt-in showing "Connected" proves that it is correctly set up and working.

> [@Naveen](#):
>
> i'm not getting anything in the node-red

Do you still have the flow which tests your mqtt setup?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/a/2a3c7661105fadafce183d5b339cf62cc804eec2.png)

---

<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:** [22 November 2023 13:05 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/43 "2023-11-22T13:05:23Z")

</div>

can you provide me mqtt and test nodes (server, topic, connection and security) details.

---

<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:** [22 November 2023 13:12 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/44 "2023-11-22T13:12:59Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/c/ec4ed07d2714d142b6fc6e5b29b56c3e2d4fc5dd.png)  
i was getting like disconnected when i hit test:Hello.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/c/dcb38627b8e513151f613d96baf1bf10e19fb6f8.png)  
in the mqtt out node, it was showing invalid topic

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

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