MQTT Out Node Constantly Disconnecting

Hi all,

I've been playing with Node-Red for just a little while. I have a flow that reads from SQLite and outputs to MQTT. This was working fine for several months but at some point recently the MQTT Out Node started playing up.

When deployed, it connects for a little while, then disconnects, then reconnects again.

  • Connecting --> Connected --> Disconnected --> Connecting -->...

It loops through the 3 states continuously, staying in each state for a few seconds at a time. When connected, it does work, but I miss many messages during the Disconnected and Connecting periods.

Any idea why this is happening now when it wasn't in the past?

Thanks,
Cheese

Do you have access to the broker logs to see if there's any information there?

Is the broker on the same machine as NR?
if not, is it wireless? Anything change in your network?

No obvious errors on the console. But then I'm still trying to work out how to get it to log details. I do have a few other publishers on the network and I don't seem to be losing any messages form them. Just the Node-Red flows.

Yes same machine.

What does the log say when the node-red client disconnects? Is it a timeout? Is it a duplicate client id? Or does it appear as a 'clean' disconnect?

This sounds as if you might have multiple clients specifying the same client id. Make sure each one has a different id, or you leave it blank. Also make sure that in each node-red (if you have multiple) that you only have one config node for each MQTT broker (or at least that again they do not specify the same client id).
If it is not that then as suggested, you should look at the mosquitto log (if it is mosquitto you are using).

Ahhh yes. I think that was it. I had copied a flow to another Node-red server and modified it without changing the client ID.

So if I leave the client ID blank then will it set it to something unique automatically? An if so, will it remain consistently named if it restarts?

If you don't set a client id, a random identifier will be generated by the MQTT client library, usually a combination of host/username and the current timestamp, if I remember correctly. That id will change with every reconnect.

However, if you rely on message QoS levels 1 or 2, or a last-will topic, you should set a unique fixed client id yourself to ensure consistent behavior across reconnects/connection failures.

2 Likes

Thankyou all.