# 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:** 5\
**Page:** 2

<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 15:05 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/21 "2022-11-17T15:05:34Z")

</div>

As I noted in my response of Nov 16th,

> [@PPASSL](#):
>
> I'm using [sMQTT Broker](https://github.com/terrorsl/sMQTTBroker) deployed on an ESP8266.

---

<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:31 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/23 "2022-11-17T15:31:54Z")

</div>

Where are you running node-red? If that is not on the ESP then you could install mosquitto on the node red server rather than on the ESP.

Otherwise you may just have to put up with this issue. One workaround, I guess, would be to avoid using the # specification and instead have multiple MQTT nodes in parallel, one for each topic.

---

<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 15:42 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/24 "2022-11-17T15:42:11Z")

</div>

> [@Colin](#):
>
> Otherwise you may just have to put up with this issue. One workaround, I guess, would be to avoid using the # specification and instead have multiple MQTT nodes in parallel, one for each topic.

Correct, I'm using non-overlapping subscriptions on the MQTT nodes as a workaround.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 November 2022 18:04 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/25 "2022-11-17T18:04:46Z")

</div>

Please try this test. Add two `inject` nodes and connect them to a single `mqtt-out` node.  
In both `inject` nodes, set msg topic to 'events/ESP8266MQTTBroker/RAM'

In inject1 set the payload to 'from inject 1'  
In inject2 set the payload to 'from inject 2'

Deploy and press inject 1, do you get two msgs from each `mqtt-in` node?  
press inject 2, do you get two msgs from each `mqtt-in` node?

One issue you have is that every msg sent with a topic of 'events/ESP8266MQTTBroker/anything-else' will be received by both `mqtt-in` nodes because of the way you are subscribing to the topics.

You miget be beter off to have one `mqtt-in` node subscribing to 'events/#' and the output of that node going to a `switch` node that checks to see if msg topic contains 'events/ESP8266MQTTBroker' and has an `otherwise` condition to split the msgs to the two outputs based on the contents of the topic.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [1 December 2022 18:05 UTC](https://discourse.nodered.org/t/mqtt-node-messages-received-twice/70727/26 "2022-12-01T18:05:00Z")

</div>

Closed on 1 December 2022 18:05 UTC

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

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