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