# MQTT node - messages received twice!?

**URL:** <https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727>\
**Category:** General\
**Tags:** mqtt\
**Created:** [16 November 2022 16:47 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727 "2022-11-16T16:47:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![PPASSL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppassl/32/70851_2.png) [@PPASSL](https://discourse.nodered.org/u/PPASSL)\
**Post date:** [16 November 2022 16:47 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/1 "2022-11-16T16:47:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mudwalker](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mudwalker](https://discourse.nodered.org/u/mudwalker)\
**Post date:** [16 November 2022 17:01 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/2 "2022-11-16T17:01:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 November 2022 17:17 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/3 "2022-11-16T17:17:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mudwalker](https://avatars.discourse-cdn.com/v4/letter/m/47e85d/32.png) [@mudwalker](https://discourse.nodered.org/u/mudwalker)\
**Post date:** [16 November 2022 17:34 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/4 "2022-11-16T17:34:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 November 2022 17:52 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/5 "2022-11-16T17:52:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PPASSL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppassl/32/70851_2.png) [@PPASSL](https://discourse.nodered.org/u/PPASSL)\
**Post date:** [16 November 2022 18:12 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/6 "2022-11-16T18:12:38Z")

</div>

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:

 ![NR-MQTTBug-Screenshot 2022-11-16 114320](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/39c87d64032b6e4fa1d61431d89170277a85ec48.jpeg)

---

<div class="post-metadata">

**Author:** ![PPASSL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppassl/32/70851_2.png) [@PPASSL](https://discourse.nodered.org/u/PPASSL)\
**Post date:** [16 November 2022 18:16 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/7 "2022-11-16T18:16:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PPASSL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppassl/32/70851_2.png) [@PPASSL](https://discourse.nodered.org/u/PPASSL)\
**Post date:** [16 November 2022 18:20 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/8 "2022-11-16T18:20:30Z")

</div>

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

 ![NR-MQTTBug-2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/1/a1a4d7291049ce5d8da33b38420d7e8c65991f52.jpeg)

and the debug node:

 ![NR-MQTTBug-3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/8/0855e058f5981b924ebdd6c3f978da3a53da499a.jpeg)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 November 2022 18:42 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/9 "2022-11-16T18:42:10Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![PPASSL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppassl/32/70851_2.png) [@PPASSL](https://discourse.nodered.org/u/PPASSL)\
**Post date:** [16 November 2022 19:10 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/10 "2022-11-16T19:10:36Z")

</div>

@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](https://github.com/terrorsl/sMQTTBroker) deployed on an ESP8266.

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 November 2022 20:30 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/11 "2022-11-16T20:30:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PPASSL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppassl/32/70851_2.png) [@PPASSL](https://discourse.nodered.org/u/PPASSL)\
**Post date:** [16 November 2022 21:24 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/12 "2022-11-16T21:24:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 November 2022 21:53 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/13 "2022-11-16T21:53:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 November 2022 23:30 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/14 "2022-11-16T23:30:29Z")

</div>

> [@Colin](#):
>
> I vaguely remember a bug like that

It is a feature 😉

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.

---

<div class="post-metadata">

**Author:** ![PPASSL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppassl/32/70851_2.png) [@PPASSL](https://discourse.nodered.org/u/PPASSL)\
**Post date:** [17 November 2022 01:36 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/15 "2022-11-17T01:36:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 November 2022 08:32 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/16 "2022-11-17T08:32:36Z")

</div>

> [@Steve-Mcl](#):
>
> It is a feature

I can't replicate the issue using

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/2/12ee5629a77820b94874662cc8950263e70e0826.png)

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

```auto
[{"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":{}}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [17 November 2022 08:38 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/17 "2022-11-17T08:38:57Z")

</div>

I also forgot to mention Colin, this only happens with certain brokers. 🤷‍♂️

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.

---

<div class="post-metadata">

**Author:** ![PPASSL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppassl/32/70851_2.png) [@PPASSL](https://discourse.nodered.org/u/PPASSL)\
**Post date:** [17 November 2022 13:58 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/18 "2022-11-17T13:58:45Z")

</div>

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

 ![REpro-NR-Screenshot 2022-11-17 084909](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c05afc0de41cce14ee69552e6d54d80cdeb954ec.jpeg)

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

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [17 November 2022 14:23 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/19 "2022-11-17T14:23:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 November 2022 15:03 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/20 "2022-11-17T15:03:27Z")

</div>

> [@PPASSL](#):
>
> I confirm I can repro the issue with my broker

What broker are you using? Is it Aedes perhaps?

[Next page](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727.md?page=2)
