MQTT node - messages received twice!?

Using NR v3.0.2

I'm using a MQTT in Node and keep getting the messages received twice.
It might be a trivial issue... tried changing the QOS from the default 0 to 2 but didn't change anything.

Thought it was the broker but ruled it out as other clients just receive the message once.

This is annoying because the node is suppose to create a database entry and the results is all the entries get duplicated...

Any ideas what it might be happening?
thanks in advance!
-p

If you add a Debug node to the MQTT In node, do you get two messages there?

If not then I would suggest that your MQTT Sender might be sending the message twice as you have eliminated the broker.

I think there must be a typo in your post somewhere @mudwalker

Also the OP days that other clients only receive one message. But we do need to know what is seen in a debug node directly on the MQTT In Node

By MQTT Sender, I mean the originating MQTT device.

Of course, the OP may mean that all the MQTT messages come from the same device, but that didn't seem absolutely clear to me. If they do all come from the same origin, sorry for the confusion.

Ah yes, I see what you mean. @PPASSL if another client subscribers to exactly the same topic does that client see just one message?

All other clients (Python, iOS MQTT tool) just get one message.

My MQTT node subscribes to 'events/#'
Let me try to upload the capture of the debug node:

Interesting to notice that the _msgid: are different between the duplicates.
Where is that ID created? By the node?

In case you ask, the MQTT in node looks like this:

and the debug node:

how many subscriptions do you have and what are they?

For example, I can see a subscription to events/# - is that all? or do you also subscribe to events/testIP?

Once more question, what broker (what version broker) are you using?

2 Likes

@Steve-Mcl you got it!
I had another node subscribed to events/testIP (it was on different flow!)
As soon as I disable that flow I'm now seeing NO duplication.

Can someone explain?
The duplication doesn't seem correct to me because it originates from the same debug node...

To answer you about the broker, I'm using sMQTT Broker deployed on an ESP8266.

Thanks everyone for your help. I'm new to Node-RED and just getting used to it.

2 Likes

Do you mean that the second mqtt node was causing duplicated output from the first?

I vaguely remember a bug like that. What version of node red are you using? Look at the bottom of the drop down menu in the editor.

Using NR v3.0.2

Do you mean that the second mqtt node was causing duplicated output from the first?

That's exactly what I've been seeing, I realized because my database had all the entries coming from this node duplicated.

Show us how you have the broker node configured please. Also stop node red and start it again in a terminal and post the full startup output here, up to the point where a repeated debug output is seen.

It is a feature :wink:

There is a technical reason under the hood that I try to explain below however, if you have a v5 capable broker, switching to v5 will avoid this issue.

In as short a terms I can, the MQTT client provides single stream of values for topics subscribed to. There is no other associative info provided with these, so when you subscribe to abc/# and abc/def there are 2 packets sent. The MQTT config receives these 2 packets & send them to the 2 nodes.

With MQTT v5, we can add additional info to determine which packet is for which subscription & thus avoid the duplicate messages.

2 Likes

Thanks @Steve-Mcl, that makes it clear!
In any case, understanding this feature, I have a workaround and can continue using Node-RED for my deployment.

Appreciate everyone that chimed-in this thread.

I can't replicate the issue using

image

When I click the Inject I just get one message from each debug node. The config nodes are configured mqtt v3.1.1

[{"id":"e2fd254e9f4f9785","type":"mqtt in","z":"e8ef959d13de8230","name":"","topic":"abc/def","qos":"0","datatype":"auto-detect","broker":"adf2dac3.b20fe8","nl":false,"rap":true,"rh":0,"inputs":0,"x":190,"y":180,"wires":[["ef58111c87bb354f"]]},{"id":"ef58111c87bb354f","type":"debug","z":"e8ef959d13de8230","name":"debug 36","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":440,"y":180,"wires":[]},{"id":"6c744506ee7c865e","type":"inject","z":"e8ef959d13de8230","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":260,"wires":[["85e75a480064a2e5"]]},{"id":"85e75a480064a2e5","type":"mqtt out","z":"e8ef959d13de8230","name":"","topic":"abc/def","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"adf2dac3.b20fe8","x":440,"y":260,"wires":[]},{"id":"ed910f876bb06383","type":"mqtt in","z":"e8ef959d13de8230","name":"","topic":"abc/#","qos":"0","datatype":"auto-detect","broker":"adf2dac3.b20fe8","nl":false,"rap":true,"rh":0,"inputs":0,"x":190,"y":120,"wires":[["1db2f953a2e8c8ab"]]},{"id":"1db2f953a2e8c8ab","type":"debug","z":"e8ef959d13de8230","name":"debug 38","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":450,"y":120,"wires":[]},{"id":"adf2dac3.b20fe8","type":"mqtt-broker","name":"localhost","broker":"localhost","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"tigger/LWT","birthQos":"0","birthPayload":"Online","birthMsg":{},"closeTopic":"tigger/LWT","closeQos":"0","closePayload":"Offline","closeMsg":{},"willTopic":"tigger.LWT","willQos":"0","willPayload":"Offline","willMsg":{},"userProps":"","sessionExpiry":"","credentials":{}}]

I also forgot to mention Colin, this only happens with certain brokers. :man_shrugging:

I tried to explain in simple terms that people can understand why it happens but there is a bit more to it.

The part I was trying to get across initially is when you have this situation you can solve it by moving to v5.

I confirm I can repro the issue with my broker, every debug node see the message twice --see below.
And again the broker is not the issue as all the other clients I've tested do not see message duplication (see below my repro).

If you need data I can collect on my end to debug, I'm happy to help (note that I wont be able to collect it till next week as I'm quite behind in my work this week...)

I suggest this issue/known bug of mqtt in node with MQTT v3.1.1 is documented because I'm guessing other people will scratch their head with this.
-p

Events-TopicAll is subscribed to 'events/#'
Events-Topic-Broker is subscribed to 'events/ESP8266MQTTBroker/#'

I've tried your flow with NR v2.1.3 and MQTT V3.1.1 on my local broker and BeeBotte remote broker - they both give the same (correct) results as your setup.

What broker are you using? Is it Aedes perhaps?