How to connect node-red with mqtt broker

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

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

To add a server

Then click on the pencil icon/button

Then enter the details as needed

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

Hope that helps.

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

Did you set up the server as I showed?

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.

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

This is an EXAMPLE on how to use it.

##  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.

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.

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.

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.

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

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

I can't read your mind.

SCREEN SHOT
Export the node

Something.

1 Like

Open read and study this link:

Or even this one which is THE home of mosquitto.

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?

local machine
local IP address of Node-red machine:
http://localhost:1880


in the above screenshot, 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.

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

Click the button labelled Deploy.

Since it seems you are an absolute beginner, I recommend watching this playlist: Node-RED Essentials. 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.


ti's already 10 mins but still it's showing connecting

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.

[
    {
        "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