# MQTT Out Node Constantly Disconnecting

**URL:** <https://discourse.nodered.org/t/mqtt-out-node-constantly-disconnecting/14251>\
**Category:** General\
**Created:** [12 August 2019 13:10 UTC](https://discourse.nodered.org/t/mqtt-out-node-constantly-disconnecting/14251 "2019-08-12T13:10:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cheese](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@Cheese](https://discourse.nodered.org/u/Cheese)\
**Post date:** [12 August 2019 13:10 UTC](https://discourse.nodered.org/t/mqtt-out-node-constantly-disconnecting/14251/1 "2019-08-12T13:10:00Z")

</div>

Hi all,

I've been playing with Node-Red for just a little while. I have a flow that reads from SQLite and outputs to MQTT. This was working fine for several months but at some point recently the MQTT Out Node started playing up.

When deployed, it connects for a little while, then disconnects, then reconnects again.

- Connecting --\> Connected --\> Disconnected --\> Connecting --\>...

It loops through the 3 states continuously, staying in each state for a few seconds at a time. When connected, it does work, but I miss many messages during the Disconnected and Connecting periods.

Any idea why this is happening now when it wasn't in the past?

Thanks,  
Cheese

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [12 August 2019 13:11 UTC](https://discourse.nodered.org/t/mqtt-out-node-constantly-disconnecting/14251/2 "2019-08-12T13:11:21Z")

</div>

Do you have access to the broker logs to see if there's any information there?

---

<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:** [12 August 2019 13:17 UTC](https://discourse.nodered.org/t/mqtt-out-node-constantly-disconnecting/14251/3 "2019-08-12T13:17:30Z")

</div>

Is the broker on the same machine as NR?  
if not, is it wireless? Anything change in your network?

---

<div class="post-metadata">

**Author:** ![Cheese](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@Cheese](https://discourse.nodered.org/u/Cheese)\
**Post date:** [12 August 2019 13:55 UTC](https://discourse.nodered.org/t/mqtt-out-node-constantly-disconnecting/14251/4 "2019-08-12T13:55:29Z")

</div>

> [@knolleary](#):
>
> Do you have access to the broker logs to see if there's any information there?

No obvious errors on the console. But then I'm still trying to work out how to get it to log details. I do have a few other publishers on the network and I don't seem to be losing any messages form them. Just the Node-Red flows.

> [@zenofmud](#):
>
> Is the broker on the same machine as NR?

Yes same machine.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [12 August 2019 13:56 UTC](https://discourse.nodered.org/t/mqtt-out-node-constantly-disconnecting/14251/5 "2019-08-12T13:56:28Z")

</div>

> [@Cheese](#):
>
> No obvious errors on the console.

What does the log say when the node-red client disconnects? Is it a timeout? Is it a duplicate client id? Or does it appear as a 'clean' disconnect?

---

<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:** [12 August 2019 20:48 UTC](https://discourse.nodered.org/t/mqtt-out-node-constantly-disconnecting/14251/6 "2019-08-12T20:48:34Z")

</div>

This sounds as if you might have multiple clients specifying the same client id. Make sure each one has a different id, or you leave it blank. Also make sure that in each node-red (if you have multiple) that you only have one config node for each MQTT broker (or at least that again they do not specify the same client id).  
If it is not that then as suggested, you should look at the mosquitto log (if it is mosquitto you are using).

---

<div class="post-metadata">

**Author:** ![Cheese](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@Cheese](https://discourse.nodered.org/u/Cheese)\
**Post date:** [13 August 2019 03:58 UTC](https://discourse.nodered.org/t/mqtt-out-node-constantly-disconnecting/14251/7 "2019-08-13T03:58:51Z")

</div>

> [@Colin](#):
>
> you might have multiple clients

Ahhh yes. I think that was it. I had copied a flow to another Node-red server and modified it without changing the client ID.

So if I leave the client ID blank then will it set it to something unique automatically? An if so, will it remain consistently named if it restarts?

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [13 August 2019 05:52 UTC](https://discourse.nodered.org/t/mqtt-out-node-constantly-disconnecting/14251/8 "2019-08-13T05:52:50Z")

</div>

> [@Cheese](#):
>
> So if I leave the client ID blank then will it set it to something unique automatically? An if so, will it remain consistently named if it restarts?

If you don't set a client id, a random identifier will be generated by the MQTT client library, usually a combination of host/username and the current timestamp, if I remember correctly. That id will change with every reconnect.

However, if you rely on message QoS levels 1 or 2, or a last-will topic, you should set a unique fixed client id yourself to ensure consistent behavior across reconnects/connection failures.

---

<div class="post-metadata">

**Author:** ![Cheese](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@Cheese](https://discourse.nodered.org/u/Cheese)\
**Post date:** [13 August 2019 13:28 UTC](https://discourse.nodered.org/t/mqtt-out-node-constantly-disconnecting/14251/9 "2019-08-13T13:28:54Z")

</div>

Thankyou all.

---

<div class="post-metadata">

**Author:** ![GerardWassink](https://avatars.discourse-cdn.com/v4/letter/g/a3d4f5/32.png) [@GerardWassink](https://discourse.nodered.org/u/GerardWassink)\
**Post date:** [16 November 2020 13:12 UTC](https://discourse.nodered.org/t/mqtt-out-node-constantly-disconnecting/14251/10 "2020-11-16T13:12:17Z")

</div>

Same problem here. Leaving the client-id blank seems to have solved it.

Thanks a 10^6 ...

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 November 2020 18:15 UTC](https://discourse.nodered.org/t/mqtt-out-node-constantly-disconnecting/14251/11 "2020-11-16T18:15:36Z")

</div>


