# Broker regularly disconnects and connects?

**URL:** https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262
**Category:** General
**Created:** [8 November 2022 14:12 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262 "2022-11-08T14:12:48Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)
#### Post date: [8 November 2022 14:12 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/1 "2022-11-08T14:12:48Z")

</div>

Hi,

I am running Node-RED on a RPI, I have noticed that sensors I have around my house sometimes do not work.

On looking at the Terminal screen after i restarted Node-RED ... I see this

```auto
Welcome to Node-RED
===================

8 Nov 08:17:36 - [info] Node-RED version: v2.1.6
8 Nov 08:17:36 - [info] Node.js version: v12.22.12
8 Nov 08:17:36 - [info] Linux 5.15.56-v7+ arm LE
8 Nov 08:17:39 - [info] Loading palette nodes
8 Nov 08:17:45 - [info] Dashboard version 3.1.7 started at /ui
8 Nov 08:17:47 - [warn] Missing node modules:
8 Nov 08:17:47 - [warn] - node-red-contrib-aedes (0.6.0): aedes broker
8 Nov 08:17:47 - [warn] - node-red-contrib-mqtt-broker (0.2.9): mosca in
8 Nov 08:17:47 - [info] Removing modules from config
8 Nov 08:17:47 - [info] Settings file : /home/pi/.node-red/settings.js
8 Nov 08:17:47 - [info] Context store : 'default' [module=memory]
8 Nov 08:17:48 - [info] User directory : /home/pi/.node-red
8 Nov 08:17:48 - [warn] Projects disabled : editorTheme.projects.enabled=false
8 Nov 08:17:48 - [info] Flows file : /home/pi/.node-red/flows.json
8 Nov 08:17:48 - [info] Server now running at http://127.0.0.1:1880/
8 Nov 08:17:48 - [warn] 

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

8 Nov 08:17:49 - [info] Starting flows
8 Nov 08:17:50 - [info] Started flows
8 Nov 08:17:51 - [info] [sqlitedb:71cf7c5fab68a227] opened /media/pi/Storage/RPI/Database/RPI - Home/Home - V2.00.db ok
8 Nov 08:17:51 - [info] [sqlitedb:61693413682a0187] opened /media/pi/Storage/RPI/Database/TEST/Test - V2.00.db ok
8 Nov 08:17:51 - [info] [mqtt-broker:52789754.032f7] Connected to broker: mqtt://192.168.1.65:1883
8 Nov 08:18:29 - [info] [mqtt-broker:52789754.032f7] Disconnected from broker: mqtt://192.168.1.65:1883
8 Nov 08:18:32 - [info] [alexa-remote-account:45cd036d.732c4c] intialising with the PROXY method and saved data...
8 Nov 08:18:44 - [info] [mqtt-broker:52789754.032f7] Connected to broker: mqtt://192.168.1.65:1883
8 Nov 08:58:29 - [info] [mqtt-broker:52789754.032f7] Disconnected from broker: mqtt://192.168.1.65:1883
8 Nov 08:58:44 - [info] [mqtt-broker:52789754.032f7] Connected to broker: mqtt://192.168.1.65:1883
8 Nov 09:58:29 - [info] [mqtt-broker:52789754.032f7] Disconnected from broker: mqtt://192.168.1.65:1883
8 Nov 09:58:45 - [info] [mqtt-broker:52789754.032f7] Connected to broker: mqtt://192.168.1.65:1883

```

There seems to be a pattern ?  
I then looked at the mosquitto log and found this

```auto
pi@raspberrypi:~ $ sudo tail -n20 -f /var/log/mosquitto/mosquitto.log
1667914641: New client connected from 192.168.1.91:22920 as MQTT Module 91 (p2, c1, k15).
1667914670: Client MQTT Module 91 has exceeded timeout, disconnecting.
1667914693: New connection from 192.168.1.90:4918 on port 1883.
1667914693: New client connected from 192.168.1.90:4918 as MQTT Module 90 (p2, c1, k15).
1667914718: Client MQTT Module 90 has exceeded timeout, disconnecting.
1667914790: New connection from 192.168.1.91:5796 on port 1883.
1667914790: New client connected from 192.168.1.91:5796 as MQTT Module 91 (p2, c1, k15).
1667914814: Client MQTT Module 91 has exceeded timeout, disconnecting.
1667914868: New connection from 192.168.1.92:19537 on port 1883.
1667914868: New client connected from 192.168.1.92:19537 as MQTT Module 92 (p2, c1, k15).
1667914892: Client MQTT Module 92 has exceeded timeout, disconnecting.
1667914937: New connection from 192.168.1.91:27126 on port 1883.
1667914937: New client connected from 192.168.1.91:27126 as MQTT Module 91 (p2, c1, k15).
1667914964: Client MQTT Module 91 has exceeded timeout, disconnecting.
1667915085: New connection from 192.168.1.91:26629 on port 1883.
1667915085: New client connected from 192.168.1.91:26629 as MQTT Module 91 (p2, c1, k15).
1667915108: Client MQTT Module 91 has exceeded timeout, disconnecting.
1667915159: New connection from 192.168.1.92:16366 on port 1883.
1667915159: New client connected from 192.168.1.92:16366 as MQTT Module 92 (p2, c1, k15).
1667915186: Client MQTT Module 92 has exceeded timeout, disconnecting.
1667915232: New connection from 192.168.1.91:7078 on port 1883.
1667915232: New client connected from 192.168.1.91:7078 as MQTT Module 91 (p2, c1, k15).
1667915258: Client MQTT Module 91 has exceeded timeout, disconnecting.
1667915270: New connection from 192.168.1.90:1412 on port 1883.
1667915270: New client connected from 192.168.1.90:1412 as MQTT Module 90 (p2, c1, k15).
1667915294: Client MQTT Module 90 has exceeded timeout, disconnecting.
1667915380: New connection from 192.168.1.91:17561 on port 1883.
1667915380: New client connected from 192.168.1.91:17561 as MQTT Module 91 (p2, c1, k15).
1667915408: Client MQTT Module 91 has exceeded timeout, disconnecting.

```

I do have battery operated modules ( **Module 90 ... 91 ... 92** ) that send data every 10 minutes and between that time they sleep. These are in the list above. **Client MQTT Module 90 has exceeded timeout, disconnecting.** etc

Is this the problem ?  
Do i need to change the **Keep alive time** for the Broker, if so what time too ?

 ![37](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/2/a2c3639b20a52f46222035447550f80e878388cc.jpeg)

Thanks

Gaz

---

<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: [8 November 2022 15:45 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/2 "2022-11-08T15:45:26Z")

</div>

It looks like you may be using the same client id for multiple connections. Don't do that.

---

<div class="post-metadata">

### Author: ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)
#### Post date: [8 November 2022 15:56 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/3 "2022-11-08T15:56:18Z")

</div>

> [@questuk](#):
>
> `1667915294`

Hi Colin where would I find the client ID ?

Thanks

---

<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: [8 November 2022 16:02 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/4 "2022-11-08T16:02:24Z")

</div>

Or indeed what client library are you using. As part of the client connection you set a keepalive timeout. The client then has to send that keepalive or it will get dropped. Maybe your library isn't doing that ?

---

<div class="post-metadata">

### Author: ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)
#### Post date: [8 November 2022 16:16 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/5 "2022-11-08T16:16:23Z")

</div>

I must admit I am confused and I am not good at Node-RED etc.

My Node\_RED project has been running successfully for 6 years on a **32bit linux pc** and an early version of Node\_RED. a guess would be version 0.7 ?

But I wanted to use Grafana so I had to use a 64bit machine, so i moved the project to a **RPI 3** and use **mosquitto** broker and it is set to enable anonymous users.  
All seemed to be working well although I didn't check the Node\_RED terminal output as it has never been a problem.

But I have a PIR that turns on lights in the evening via Node\_RED and ESP-8266.  
I noticed recently, sometimes it would **not turn ON** or be delayed by about 20 seconds.  
_( Perhaps more noticeable because of the darker evenings, so it may have been doing this before !)_

> The not turning On or delay I think is caused by Node-RED reconnecting.

As I said this has worked perfectly for 6 years on the other PC.

So I am totally unsure where the problem is ?

Any tests i can do ?

thanks

Gaz ... sorry for the long ramble

---

<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: [8 November 2022 19:55 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/6 "2022-11-08T19:55:29Z")

</div>

I doubt if the problem with the PIR is related to the timeout.

Have you changed the battery in the offending device?  
Also add a debug node showing the data received from the MQTT node. Set it to Output to the console. Then when it fails note the time and then you can look back in the log to confirm whether nothing was received or if the problem is something else.

---

<div class="post-metadata">

### Author: ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)
#### Post date: [9 November 2022 08:41 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/7 "2022-11-09T08:41:52Z")

</div>

Hi,

To try to find out the offending items ... overnight I **turned off ALL battery operated sensors** that communicate with Node\_RED.

This morning looking at the mosquitto log I have multiple ...

> 1667979270: New client connected from 192.168.1.65:33248 as nodered\_61d118136924eafd (p2, c1, k15).  
> 1667979836: Client nodered\_61d118136924eafd has exceeded timeout, disconnecting.

Using command `sudo tail -n20 -f /var/log/mosquitto/mosquitto.log`

1. Where can I find out where **Client nodered\_61d118136924eafd** is located on my system ?
2. Also what does **(p2, c1, k15)**. mean ?

Thanks for your help so far

Gaz

---

<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: [9 November 2022 09:08 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/8 "2022-11-09T09:08:17Z")

</div>

> [@questuk](#):
>
> Where can I find out where **Client nodered\_61d118136924eafd** is located on my system

This is an auto-generated clientId from a broker connection in node-red. I think if you look further back in logs you will see a node ID associated with that client ID.

> [@questuk](#):
>
> Also what does **(p2, c1, k15)**. mean

That is not something I've seen. Curious. Is it the name set in the config? Use Ctrl-f and search for that in node-red.

One suggestion would be try upgrading node-red to latest 2.x or better still v3.0.2

---

<div class="post-metadata">

### Author: ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)
#### Post date: [9 November 2022 09:28 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/9 "2022-11-09T09:28:17Z")

</div>

Hi,

> [@Steve-Mcl](#):
>
> That is not something I've seen. Curious. Is it the name set in the config? Use Ctrl-f and search for that in node-red.

Did search for **(p2, c1, k15)** and also K15 nothing found.

At the moment i would rather not change too many things like upgrading as it may confuse matters ?  
Also this is a good time to find out what all these things mean instead of being a "black box" for me.

Hopefully with all your help we can track down the fault.

If we are stuck I will **disable** all of my tabs ( i have about 25 with lots of flows ) and see which one if any is causing the problem

I do appreciate ALL of your time to help me.

Gaz

---

<div class="post-metadata">

### Author: ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)
#### Post date: [9 November 2022 10:02 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/10 "2022-11-09T10:02:15Z")

</div>

A quick update ... I have changed the **keep alive from 15 to 60** and after 20 mins, I have not seen any errors ?

![45](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/0/00b35c5be1f7e67580d1f77528c33f131f0788fb.png)

I will give it another 30 mins then if still OK, I will turn ON my battery operate devices one at a 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: [9 November 2022 10:33 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/11 "2022-11-09T10:33:05Z")

</div>

60 is the default that I see here. Did you change it away from that?

---

<div class="post-metadata">

### Author: ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)
#### Post date: [9 November 2022 10:53 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/12 "2022-11-09T10:53:17Z")

</div>

No it was 15 . I wouldn't have changed it from install ... it as i didn't know what it did ?

---

<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: [9 November 2022 11:24 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/13 "2022-11-09T11:24:00Z")

</div>

> [@questuk](#):
>
> No it was 15 . I wouldn't have changed it from install

That is odd. If you create a new MQTT node, select Make a new broker, and look in there what is the timeout? You can then just cancel and Undo to remove the mqtt node. No need to deploy.

---

<div class="post-metadata">

### Author: ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)
#### Post date: [9 November 2022 11:30 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/14 "2022-11-09T11:30:04Z")

</div>

Hi Colin,

Yes is did that and yes it was ... **60**

I think because these flows are from 6 years ago and I was using a very old version of Node-RED 0.7 ?  
And i just copied across all my flows from then.

It may have been the default a long time ago.

---

<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: [9 November 2022 11:34 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/15 "2022-11-09T11:34:45Z")

</div>

> [@questuk](#):
>
> It may have been the default a long time ago.

Yes, that probably explains it.

---

<div class="post-metadata">

### Author: ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)
#### Post date: [9 November 2022 12:56 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/16 "2022-11-09T12:56:17Z")

</div>

Hi,

I attached the battery operated devices again, and it's been at least an hour now and no problems.

Thanks to you ALL for your help

Gaz

---

<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: [8 January 2023 12:56 UTC](https://discourse.nodered.org/t/broker-regularly-disconnects-and-connects/70262/17 "2023-01-08T12:56:39Z")

</div>

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