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

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [22 December 2022 11:19 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/21 "2022-12-22T11:19:02Z")

</div>

In my experience, such continual connect/disconnect is caused by a duplicate MQTT client ID.

---

<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:21 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/22 "2022-12-22T11:21:56Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/c/1ceb3a4f648327e397c154a20689929284b59dc1.png)  
on V 3.1.1

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/015765af24c6825d314ccb997412bae6338821a6.png)  
on V 5

So it is likely that the broker does not support it.

---

<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:24 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/23 "2022-12-22T11:24:38Z")

</div>

I left the client id blank for automatic generation  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/8615b1a0560dcad0fac765e393106371a7b1d325.png)  
should she be a constant to everyone ?

---

<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:38 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/24 "2022-12-22T11:38:15Z")

</div>

I have had the problem for over 2 months now, during this time I have also tried to search for the problem on my own by which I came across your earlier posts and also tried to follow them but unfortunately nothing helped.

only thing is that earlier I had "keep alive" set to 45 after changing it to 60 the occurrence changed from 4-5 days to a week- two weeks without any problem.

I really appreciate your time 🙂

---

<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 12:00 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/25 "2022-12-22T12:00:52Z")

</div>

> [@Sets](#):
>
> only thing is that earlier I had "keep alive" set to 45 after changing it to 60 the occurrence changed from 4-5 days to a week- two weeks without any problem.

I am confused. You said two hours ago that it fails every 4-5 days, now you say that since you made that change it has worked for two weeks without a problem. Please clarify.

---

<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 12:05 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/26 "2022-12-22T12:05:13Z")

</div>

at the very loss I wrote in brackets (once every 4 days, every 5 days, the last 2 weeks)

two weeks it worked after changing the "keep alive" to 60 from 45 but this could just be a coincidence

I am sorry if I have misled you

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [22 December 2022 16:00 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/27 "2022-12-22T16:00:59Z")

</div>

> [@Sets](#):
>
> should she be a constant to everyone ?

No, should be different for every connection - left blank should do that anyway.

---

<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 16:25 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/28 "2022-12-22T16:25:03Z")

</div>

According to AWS IoT Core docs, it does support many (not all) V5 features: [MQTT - AWS IoT Core](https://docs.aws.amazon.com/iot/latest/developerguide/mqtt.html)

But it should connect. You should try again (perhaps restart node-red changing just in case).

V5 has a lot of benefits, and in this case, v5 has greatly improved status info & so your logs should include reason codes (and if AWS did a good job, you should also get a friendly reason description alongside the reason code)

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [22 December 2022 23:58 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/29 "2022-12-22T23:58:56Z")

</div>

Did you try to monitor the topic `$aws/events/presence/#` ? There you will find disconnection codes that may give you some hint.

Reference: [Lifecycle events - AWS IoT Core](https://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html)

---

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

</div>

I found something like this

`(node:29) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification. (Use `node --trace-warnings ...` to show where the warning was created)`

---

<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:** [12 January 2023 07:25 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/31 "2023-01-12T07:25:46Z")

</div>

Hi  
After 20 days  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/a/5a505cca710a96ea210696283d778395ea2c8918.png)  
all MQTT discconected  
in logs typical  
"connected  
disconnected..."  
as above

---

<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:** [13 March 2023 07:26 UTC](https://discourse.nodered.org/t/mqtt-in-randomly-disconnect/72574/32 "2023-03-13T07:26:40Z")

</div>

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

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