# 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:** 11
**Page:** 3

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

</div>

1. Where did you got the topic `command///req/#` from?  
Hint: It is nonsense.
2. Why does it have repeated `/` characters?
3. Do you know the special meanings of `#` and `+` in mqtt topics?  
If not, you need to do some reading about mqtt. I don't know your native language so I cannot recommend suitable material.
4. What do you expect that a message published to `command///req/#` will do?  
You cannot publish to a wildcard topic.

---

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

</div>

> [@Naveen](#):
>
> can you provide me mqtt and test nodes (server, topic, connection and security) details.

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

---

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

</div>

[quote="Naveen, post:46, topic:82207"]

> [@Naveen](#):
>
> can you provide me examples of mqtt and test nodes (server, topic, connection and security) details

Yes of course. I have an mqtt broker running on a Raspberry Pi at 192.168.1.11. It is Mosquitto.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/86ce9ecbd3e9fbe32704309fb7163add1c8feff6.png)

I have to use a username and password to connect to it. My username is jbudd and my password is Password1.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/3/e3e93062eac0c5a9451fd9c22fbcb9309e3e902b.png)

In this simple flow the inject node sets msg.payload "Hello" and msg.topic "test".  
The mqtt-out node accepts the topic from msg.topic.  
The mqtt-in node subscribes to topic "test".  
For more complicated setups I might use a topic like reactor1/coretemperature or reactor1/radiation  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3f434283d189abecea9f0d04a9f2e89abeb17a93.png)

So that's my setup. Since I have no idea what your setup is like you might find you need different settings.  
**But since your mqtt node is Connected, all you need is a sensible 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: [22 November 2023 14:21 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/48 "2023-11-22T14:21:51Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c055ce7a13d149f3415bf67b1b33fa862ef6a68c.png)

Please note @Naveen , if you ignore my questions again I will not try and help you in future.

---

<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 15:34 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/49 "2023-11-22T15:34:40Z")

</div>

The flow you posted above looks nothing like the Test-Flow I posted as item-23 of this thread.

Are you sure you 'imported' the Node-RED flow and tried it out as it should work without any problems with the test-server at Eclipse?? I suggest you get the basic flow working before getting more complicated.

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

Here is the basic flow again, I assume you know how to 'import' the Node-RED flow from here?

```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":""}]

```

---

<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: [23 November 2023 09:27 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/50 "2023-11-23T09:27:56Z")

</div>

Hii, i'm using this topic in mqtt broker, it's not the issue with this topic, i have connected mqtt broker with node-red, i'm able to receive the command & control messages in the node-red.

---

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

</div>

So if you are now able to connect, is the problem solved?

---

<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: [23 November 2023 09:59 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/52 "2023-11-23T09:59:17Z")

</div>

yes, it's solved but i have a doubt that how to connect and emit the device in node-red

---

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

</div>

yes i tried, it's working fine.  
Thanks

---

<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: [23 November 2023 14:49 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/54 "2023-11-23T14:49:04Z")

</div>

So since you say you have got my test flow working your next step is to sort out your own MQTT broker.

You can either install a local broker on your Raspberry Pi (e.g. Mosquitto) or sign-up with a remote broker.  
There are a number of companies that offer a "free-tier" - one of them (that I use) is [BeeBotte](https://beebotte.com/).  
The choice will depend on the location (local or remote) of where your data originates.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [22 January 2024 14:50 UTC](https://discourse.nodered.org/t/how-to-connect-node-red-with-mqtt-broker/82207/55 "2024-01-22T14:50:02Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.

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