MQTT OUT (IN) Diagnosis of connection + Client ID

Hi,

Node RED v1.3.5

I am using the MQTT IN and OUT nodes for different tasks. The most complicated thing is to identify, why a node can't subscribe or send.

Sending by an ivalid topic or bad Client ID result in a disconnect. Since in the WATCH node I receive the "connect/disconnect" events, I see, that there is something - but I don't see why.

Is there a way to get more informations, why a node disconnects than this?
{"status":{"fill":"red","shape":"ring","text":"node-red:common.status.disconnected","source":{"id":"77f5b7fb.eff5a8","type":"mqtt out","name":"MQTT Local Mosquitto"}},"_msgid":"ffbd525c.1a32e8"}

And also if I put a wrong server / credentials to the subscription I get a connecting event ...

{"status":{"fill":"yellow","shape":"ring","text":"node-red:common.status.connecting","source":{"id":"77f5b7fb.eff5a8","type":"mqtt out","name":"MQTT Local Mosquitto"}},"_msgid":"ffbd565c.2e55e8"}

I like robust and speaking diagnosis for IT products - so I think, it would be worth investigating this issue. Actually it's pretty hard to tell, whats wrong. I would like to wheather send me a mail or post it into ELK Diagnosis to make it easy to maintain.

The MQTT v3.1 protocol does not include anyway for the broker to tell the client why it is being disconnected - all it can do is cut the connection.

The only way to know why is to check the broker logs to see what they say.

2 Likes

Hmmm, a pitty. But I have no access to the logs (different department :slight_smile: ). So I have to "guess" why disconnect happened. But thx anyway.

If you have two clients with the same client id then they will keep disconnecting as only one can connect at a time. Either make sure they are unique or leave them blank.
Sending an invalid topic should not cause a disconnect.

@Colin .... yes I found this already as one reason. Blanking them is with our broker not possible, since our IT implemented some rules (<23 chars, no "-" and so on ...).
Another are reboots of server and changing firewalls. Since my NodeRED is 4 networks away from the broker, there can be a lot of reasons for problems. Anyway, as knolleary said, MQTT in this version does not support feedback.

Is there a way to send the client ID by msg?

No, not with the current nodes, though I believe there are enhancements being worked on that may allow that in the future.

In MQTT V5, you can add user properties

image

Is your broker V5 compatible?

Failing that, a common recommendation is to to embed the client ID in the topic

The Client ID still exists in the broker config doesn't it? As I understand it @lostbits problem is that his IT department enforces rules on the client ID so he can't leave it blank, and wants to set it up dynamically rather than at config time.

The client id can be set by an env variable...
image
... but it is not runtime dynamic (env vars only read at node-red start-up)

At some point, a dynamic setting of client id will be possible via a "connect" action in a new mqtt_control node (PR)

Yes, @lostbits have you considered that as a solution?

That's what I thought, and mentioned earlier. Thanks for confirming.

1 Like

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