# MQTT Time Out / Random Disconnect

**URL:** <https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463>\
**Category:** General\
**Created:** [11 January 2022 11:55 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463 "2022-01-11T11:55:44Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [11 January 2022 11:55 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/1 "2022-01-11T11:55:44Z")

</div>

Hello Folks,

I have recently came across an issue with the MQTT nodes on node Red.

Randomly the mqtt node will disconnect requiring a restart or reboot of Node Red- I was wondering if this has to do with the keep alive time or if its something else but similar?

Any advice would be much appreciated,

Thank you

---

<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:** [11 January 2022 12:06 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/2 "2022-01-11T12:06:24Z")

</div>

Odd. The connection should recover automatically.

- What version of node-red are you using?
- What version of node-js are you using?
- What broker are you using and where is your broker? (local? Lan? Cloud?)
- Have you specified a client id in your MQTT config node? If so - is this necessary? is it duplicated elsewhere?

When it is disconnected, do you wait at least 1 minute for reconnection?

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [11 January 2022 12:30 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/3 "2022-01-11T12:30:55Z")

</div>

node.js V12.18.2  
node red V1.2.7  
AWS broker, lan then through to the cloud.  
No client id`s all left blank.

yes I do , but they disconnect and stay off which is the concern.

---

<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:** [11 January 2022 12:37 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/4 "2022-01-11T12:37:38Z")

</div>

It may be related to the AWS broker.  
You could test this by connecting to a local broker & rebooting it to see if node-red reconnects.

> [@edwardr](#):
>
> node.js V12.18.2  
> node red V1.2.7

Have you considered upgrading to latest V2 and node-js 14?

The latest mqtt nodes can be issued a `connect` and `disconnect` action. It might dig you out of a hole.

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [11 January 2022 12:40 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/5 "2022-01-11T12:40:43Z")

</div>

Thank you,

Could you explain what you mean by a local broker? The AWS broker we have is online, so we submit everything via lan to a router which speak to the aws server on line?

I assume the connect reconnect command is on node red, does the mqtt node also tell me when it disconnects?

---

<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:** [11 January 2022 13:08 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/6 "2022-01-11T13:08:37Z")

</div>

> [@edwardr](#):
>
> Could you explain what you mean by a local broker

I mean local to your node-red (i.e. mosquitto installed on the same server or a device on your LAN - e.g NOT AWS)

> [@edwardr](#):
>
> I assume the connect reconnect command is on node red

Yes, you would issue a msg to an MQTT node, formatted to tell the node-red client connection to the broker to connect/disconnect (which you can of course automate)

> [@edwardr](#):
>
> does the mqtt node also tell me when it disconnects

Yes, you can cpature the status of a node using a `status` node. Therefore you can point a status node at an MQTT node & it will send a message everytime the status of that node changes (essentially providing you with a means to understand the state of the MQTT connection & therefore a means to automate a reconnection)

---

<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:** [11 January 2022 13:40 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/7 "2022-01-11T13:40:11Z")

</div>

I suggest updating node-red to the latest, there have been significant changes to the MQTT nodes so that in itself may fix or change the symptom.

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [11 January 2022 14:02 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/8 "2022-01-11T14:02:33Z")

</div>

May I ask if the keep alive function on the mqtt node would do anything? I was thinking perhaps the mqtt is timing out due to inactivity hence the keep alive could improve it?

---

<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:** [11 January 2022 14:35 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/9 "2022-01-11T14:35:57Z")

</div>

I had a Tasmota MQTT configured device which had a bad connection to the 230V supply, it was going on and off many times a day (in batches) due to the intermittent connection. The Node-RED MQTT connection always reconnected.

The MQTT device was installed before April 2020, not sure which version of Node-RED, but this was well before V2 was released, and I had seen no problems. As to the intermittent connection, not sure when that began as I only started tracking the connections last September, and that was for a completely different reason. It was only when I created this flow that I found the problem.

HTH

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [11 January 2022 15:39 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/10 "2022-01-11T15:39:40Z")

</div>

> [@Steve-Mcl](#):
>
> Yes, you would issue a msg to an MQTT node, formatted to tell the node-red client connection to the broker to connect/disconnect (which you can of course automate)

How exactly is this done? The mqtt node doesn`t allow any reconnection command, only the passing of signals to the specific topic ?

---

<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:** [11 January 2022 15:44 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/11 "2022-01-11T15:44:19Z")

</div>

> [@edwardr](#):
>
> How exactly is this done

It's documented in the built in help

But first, I'll refer you back to my first post...

> [@Steve-Mcl](#):
>
> Have you considered upgrading to latest V2 and node-js 14?
> 
> The latest mqtt nodes can be issued a `connect` and `disconnect` action. It might dig you out of a hole

Emphasis on this " **The latest mqtt nodes can be issued a `connect` and `disconnect` action**"

---

<div class="post-metadata">

**Author:** ![edwardr](https://avatars.discourse-cdn.com/v4/letter/e/e0b2c6/32.png) [@edwardr](https://discourse.nodered.org/u/edwardr)\
**Post date:** [11 January 2022 16:25 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/12 "2022-01-11T16:25:18Z")

</div>

> [@Steve-Mcl](#):
>
> Emphasis on this " **The latest mqtt nodes can be issued a `connect` and `disconnect` action**"

Okay , I gathered that, however checking in the palette there doesn`t seem to be a latest node that is capable of this - do you have any node package suggestions? Thank you.

---

<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:** [11 January 2022 16:26 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/13 "2022-01-11T16:26:21Z")

</div>

You have to upgrade node-red to v2.x latest. Then you get the new capabilities.

---

<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:** [11 January 2022 17:14 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/14 "2022-01-11T17:14:04Z")

</div>

And, as I said, it is worth doing that first and making sure it still fails.

---

<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:** [12 March 2022 17:14 UTC](https://discourse.nodered.org/t/mqtt-time-out-random-disconnect/56463/15 "2022-03-12T17:14:46Z")

</div>

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