Node-RED and MQTT, some basic(?) help please

Having failed miserably :frowning_face: to bridge my Mosquitto add-on to CloudMQTT because the add-on wouldn’t open my conf file for some reason I am now trying Node-RED.

I have an MQTT-in node correctly connected to CloudMQTT and reading everything published there.

I am injecting the payload form that node directly into an MQTT-out node which is connected to my Mosquitto.
Every time something is passed to it though it disconnects for a few seconds and then re-connects. I’ve tried just injecting it as a string but it does the same.

Has anyone got any pointers please?

NodeRed disconnects?

Change the out node for debug? Do you get the same?

It is the MQTT-out node that disconnects from Mosquitto.

The debug node which I have attached to the CloudMQTT-in node shows that it is receiving the published messages properly.

Here it is connected,

And here it is disconnected when I either inject the data manually or the CloudMQTT gets a new message and injects it,

Thanks for looking.

So if you delete your “Inject MQTT” the debug works? Sound like an error on the outgoing MQTT.

do you have MQTT running on this system? so you can send to

Open your “Inject Message” and show us where your publishing the message.

Both debug nodes always show exactly the same, and correct output.

I did this to confirm that the MQTT-in was actually forwarding the message correctly and also to prove to myself that I had set up the inject to injecting the correct message.

There is definitely a problem with the MQTT-out. I am using localhost rather than but that should be the same thing. Yes? I don’t understand why it disconnects whenever it receives a message from either the inject or the MQTT-out (and therefore doesn’t receive the message).

I’m not sure what you mean about where I publish the message, the inject node looks like this:


Try a simple test

and on the same machine subscribe

mosquitto_sub -t “#”

you should see

or as many times as you press inject

The other thing you need to check is that on the machine with NodeRed you can publish and subscribe…

open two tabs on the local system (One running NodeRed)

or two instances of ssh to this box

in one paste the following

mosquitto_sub -h -t This/is/a/topic

(Press Enter - it will wait for incoming messages)

in the other

mosquitto_pub -h -t This/is/a/topic -m “Testing MQTT”

When pasting check the quotes are correct

I take it you have install a MQTT broker on this system?

what is it your running it on? Docker? Pi? Mac?

If the above all works you should also be getting anything you publish from the cli in NodeRed

Using your idea of injecting a test string works fine as I can see it appearing on MQTT.fx
The data I want to inject is the data that Owntracks is passing to CloudMQTT.
So there must be something about that message being injected into the MQTT-out that is causing it to disconnect.

I need to add I am running this on hassio with the Mosquitto add-on.

I appreciate your help.

Your MQTT out node looks something like this?

There should be no issues with passing the data from CloudMQTT in the way your doing. I have just tried on a test PI and changed nothing but the topic without issues. So my out node…

and my overview

which as I would expect gives


Can you setup a test pi and just install mosquitto and nodered… I suspect you will see things work as they should. Should only take 20mins or so to prove. I suspect this is to do with your MQTT broker add-on… If you pass a string, as your “inject” is doing, it should be almost impossible to break.

Make sure every client that connects to a broker has a unique ID. If anything is using the same Client ID, it will cause behavior like you’re seeing

Why don’t you just point owntracks to your mosquitto broker, I know it requires you to open up a port to the world but it will save you needing to do this?

@anon59013933, @flamingm0e
Thanks to both of you. I have it working now, I started again from scratch. it was a combination of errors/misunderstandings on my part but your suggestions pointed me in the right direction.

Thanks again.

@jimpower Yes I did have everything working perfectly with an open port but have recently closed it for security reasons. I tried bridging Mosquito to CloudMQTT using:

  "customize": {
    "active": true,
    "folder": "mosquitto"

in the hassio Mosquitto add-on but for some reason Mosquitto errored, saying it couldn’t open my conf file so refused to start.

Installing the Node-RED add-on just for this one thing seems a bit clunky but it works and maybe it will encourage me to use it for other things too.

You’ve added a folder named mosquitto below share and added a file like klogg.conf to that folder?

Below is an example that gets the latest Sonoff Tasmota release version from a public broker. You could try it with that file if you want to :slight_smile:

connection maddox
remote_clientid create-your-own-unique-id-here
cleansession true
topic sonoff-version in 0

I have, yes. I posted about this a few days ago (CloudMQTT - Mosquitto - bridge) with full details and the error message but got no responses - I’d be grateful if you’d look :slight_smile: