# MQTT in randomly disconnect

**URL:** <https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574>\
**Category:** General\
**Tags:** mqtt\
**Created:** [22 December 2022 09:35 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574 "2022-12-22T09:35:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sets](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Sets](https://discourse.nodered.org/u/Sets)\
**Post date:** [22 December 2022 09:35 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/1 "2022-12-22T09:35:57Z")

</div>

Hi,

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

The node red server is set up on an AWS server,  
since 2 months I have a problem that MQTT node every now and then (once every 4 days, every 5 days, the last 2 weeks) disconnects and refuses to connect to restart node-red or deploy.  
In the meantime nothing is done on the node-red itself so this is not a problem caused by deploy. Node red as of today is in the latest version.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c44a6748e8c0d52954a6dbc39922247a7beadb00.png)

cliend id is empty

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/02f6ddbb2550368a84913de233a298eea24d1c4a.png)

On the graph you can see that it did not work from 22 the previous day until today the moment of reboot

Do you have any ideas what could be the reason for this?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 December 2022 09:45 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/2 "2022-12-22T09:45:11Z")

</div>

On what is the MQTT broker running?  
RasPi?

I don't want to sound like a broken record but I have had similar problems and it was a bad power supply.

What kind of power supply are you using?

You may want to check logs (sorry I can't tell you which ones or where they are) and see if it is only the MQTT that is failing or the entire machine - if it is a RasPi.

Sorry I can't be of more help.

---

<div class="post-metadata">

**Author:** ![Sets](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Sets](https://discourse.nodered.org/u/Sets)\
**Post date:** [22 December 2022 09:49 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/3 "2022-12-22T09:49:31Z")

</div>

Broker nor power supply is not the problem I already checked it at the beginning.

The logs look like this which makes them not very helpful :/.  
5 Dec 07:45:07 - [info] [mqtt-broker:Aws i] Disconnected from broker: mqtts://q25a-ats.iot.eu-central-1.amazonaws.com:8883

5 Dec 07:45:22 - [info] [mqtt-broker:Aws i] Connected from broker: mqtts://q25a-ats.iot.eu-central-1.amazonaws.com:8883

5 Dec 07:45:22 - [info] [mqtt-broker:Aws i] Disconnected from broker: mqtts://q25a-ats.iot.eu-central-1.amazonaws.com:8883

5 Dec 07:45:37 - [info] [mqtt-broker:Aws i] Connected from broker: mqtts://q25a-ats.iot.eu-central-1.amazonaws.com:8883

5 Dec 07:45:37 - [info] [mqtt-broker:Aws i] Disconnected from broker: mqtts://q25a-ats.iot.eu-central-1.amazonaws.com:8883

5 Dec 07:45:52 - [info] [mqtt-broker:Aws i] Connected from broker: mqtts://q25a-ats.iot.eu-central-1.amazonaws.com:8883

5 Dec 07:45:52 - [info] [mqtt-broker:Aws i] Disconnected from broker: mqtts://q25a-ats.iot.eu-central-1.amazonaws.com:8883

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 December 2022 09:52 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/4 "2022-12-22T09:52:14Z")

</div>

I think I am out of my depth.

I only mentioned the power supply because it cost me 8 months of chasing my tail trying to work out what was going on.

Can you confirm the uplink is always available when needed?  
Is it WiFi or Cable?  
Though even if it is cable: if the network goes down: it is down. Just WiFi is (can be) more prone to dropouts than cable.

---

<div class="post-metadata">

**Author:** ![Sets](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Sets](https://discourse.nodered.org/u/Sets)\
**Post date:** [22 December 2022 10:00 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/5 "2022-12-22T10:00:32Z")

</div>

thanks for your help but I doubt this is the solution

everything is on AWS as a test version, the data itself is also collected separately for comparison because so far I am testing it, so I rule out a problem with the power broker or wifi.

maybe my node red configuration is wrong but if that's the case I don't understand why it works for a few days/weeks and then stops at random intervals

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 December 2022 10:11 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/6 "2022-12-22T10:11:17Z")

</div>

> [@Sets](#):
>
> don't understand why it works for a few days/weeks and then stops at random intervals

That is slightly worring. Not in a **BAD** way, but to me that means (or could) that there is something else causing the problem.

Power spikes. (or drops)  
EMP (or similar).  
RF interference.

But as I said, I am out of my depth.  
Please don't rule things out. I learnt this the hard way.  
I stubbornly believed the power supply was good.  
In the end I replaced 2. On two RasPis and things have since been great.  
Maybe the `keep alive` (on the channel) time is expiring?

---

<div class="post-metadata">

**Author:** ![Sets](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Sets](https://discourse.nodered.org/u/Sets)\
**Post date:** [22 December 2022 10:15 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/7 "2022-12-22T10:15:47Z")

</div>

I did not rule out a problem with the broker but to have a clear conscience I just checked the base collected outside nod red,  
And there are no problems.

Keep alive is set at 60 which I still think is a bit much, do you think it should be more?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/50f28416c82cc0366209bd1d1523497720fbf5dd.png)  
I left the client id blank for autamatic gereation

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 December 2022 10:22 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/8 "2022-12-22T10:22:19Z")

</div>

Sorry.  
Above me.

Oh, which version of MQTT are you using?  
The latest?  
As much as I don't like hearing this: It could be you have an older version and so the bug exists.  
I don't know how to get this information either, sorry.  
But may be worth checking.

---

<div class="post-metadata">

**Author:** ![Sets](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Sets](https://discourse.nodered.org/u/Sets)\
**Post date:** [22 December 2022 10:23 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/9 "2022-12-22T10:23:18Z")

</div>

Give me a momentnet, I'll check it out.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 December 2022 10:25 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/10 "2022-12-22T10:25:17Z")

</div>

You may also want to post the version of NR you are using and on which kind of computer/OS it is running.

---

<div class="post-metadata">

**Author:** ![Sets](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Sets](https://discourse.nodered.org/u/Sets)\
**Post date:** [22 December 2022 10:25 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/11 "2022-12-22T10:25:26Z")

</div>

I'm using node-red version 3.0.2  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/3/73400e17ec7fd97332e072a8fdb658953559d21a.png)

The MQTT node is in the core node red if I understand correctly so the MQTT version is the node red version

its runing on amazon AWS

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 December 2022 10:27 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/12 "2022-12-22T10:27:24Z")

</div>

3.1.1 is what I have.  
That is seen here:

(Picture)

 ![Screenshot from 2022-12-22 21-26-08](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/ed43c5ddc92b6be8fc1ed8e455e94c80d7b64ae5.png)

---

<div class="post-metadata">

**Author:** ![Sets](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Sets](https://discourse.nodered.org/u/Sets)\
**Post date:** [22 December 2022 10:28 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/13 "2022-12-22T10:28:33Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c47bef75078b0f656faa529ac753622c6f5af995.png)  
then I have the same

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 December 2022 10:30 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/14 "2022-12-22T10:30:22Z")

</div>

Ok, that is good.

NR version is here:

 ![Screenshot from 2022-12-22 21-29-13](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/0/60422328cf602b6b8b4694900206ba81d8274753.png)

Machine? O/S?

(My eyes are getting heavy. I'm going now. Too tired.)  
I hope someone else can help you more than I have.

---

<div class="post-metadata">

**Author:** ![Sets](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Sets](https://discourse.nodered.org/u/Sets)\
**Post date:** [22 December 2022 10:32 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/15 "2022-12-22T10:32:12Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/5/a5ac96c19260b9ed853fab2bf160dd46e37f28e3.png)  
3.0.2  
on linux

---

<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:** [22 December 2022 10:43 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/16 "2022-12-22T10:43:54Z")

</div>

Do you use any dynamic subscriptions?

Can you try switching to Broker type v5 (I believe you will get richer disconnection info)

---

<div class="post-metadata">

**Author:** ![Sets](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Sets](https://discourse.nodered.org/u/Sets)\
**Post date:** [22 December 2022 10:52 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/17 "2022-12-22T10:52:56Z")

</div>

I don't quite understand what you mean by "dynamic subscriptions"?

I have to check if AWS supports version 5  
I was using 3 because it was the most "stable"

---

<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:** [22 December 2022 11:01 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/18 "2022-12-22T11:01:49Z")

</div>

> [@Sets](#):
>
> 5 Dec 07:45:52 - [info] [mqtt-broker:Aws i] Connected from broker: mqtts://q25a-ats.iot.eu-central-1.amazonaws.com:8883
> 
> 5 Dec 07:45:52 - [info] [mqtt-broker:Aws i] Disconnected from broker: mqtts://q25a-ats.iot.eu-central-1.amazonaws.com:8883

Also, does that continue connecting and disconnecting until you rebooted?

Did you try a node-red restart?

---

<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:** [22 December 2022 11:09 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/19 "2022-12-22T11:09:53Z")

</div>

> [@Sets](#):
>
> I have to check if AWS supports version 5

On another project I helped out with, that had issues with AWS + dynamic subscriptions, MQTT V5 was supported (not all V5 features were supported - but everything V3.11 does was) - this helped greatly.

The easy way is "try it" a V5 connection wont connect if the broker doesnt support it! Thats the easy test.

---

<div class="post-metadata">

**Author:** ![Sets](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Sets](https://discourse.nodered.org/u/Sets)\
**Post date:** [22 December 2022 11:18 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/20 "2022-12-22T11:18:15Z")

</div>

Yes, until node-red restart  
I was doing always a restarts because it didn't require logging in to AWS node reda.

[Next page](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574.md?page=2)
