# Detecting disconnection of MQTT out node

**URL:** <https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914>\
**Category:** General\
**Tags:** mqtt\
**Created:** [21 December 2023 12:27 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914 "2023-12-21T12:27:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![j2002](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@j2002](https://discourse.nodered.org/u/j2002)\
**Post date:** [21 December 2023 12:27 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/1 "2023-12-21T12:27:10Z")

</div>

I am using the logic in the image to send data over MQTT and, in the past, it has worked correctly: the status node is supposed to detect the connection status of the mqtt out node and, if disconnected, store the data locally waiting for the connection to be restored

 ![mqtt](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/313b9ccd3774a7b2e761b581bda48b0d0534ec64.jpeg)  
As I say, I saw it working in the past, but today in a routinary check, I disabled Wi-Fi and MQTT out nodes never showed status "disconnected" What should I check? Any clue?

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [21 December 2023 12:29 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/2 "2023-12-21T12:29:16Z")

</div>

May be too obvious, but is the MQTT server on the same machine ?

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [21 December 2023 12:29 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/3 "2023-12-21T12:29:55Z")

</div>

I spotted that - `Aedes`, therefore does not depend on a lan connection?

---

<div class="post-metadata">

**Author:** ![j2002](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@j2002](https://discourse.nodered.org/u/j2002)\
**Post date:** [21 December 2023 12:31 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/4 "2023-12-21T12:31:28Z")

</div>

Nop, It is a remote one

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [21 December 2023 12:34 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/5 "2023-12-21T12:34:18Z")

</div>

what is your keep alive set to?  
might be too large?

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [21 December 2023 12:35 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/6 "2023-12-21T12:35:27Z")

</div>

Also if you have LWT setup in NR, does the broker report a disconnection ?

---

<div class="post-metadata">

**Author:** ![j2002](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@j2002](https://discourse.nodered.org/u/j2002)\
**Post date:** [21 December 2023 12:35 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/7 "2023-12-21T12:35:49Z")

</div>

It is set to 60 seconds. I've maintained wifi off for 30 minutes

---

<div class="post-metadata">

**Author:** ![j2002](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@j2002](https://discourse.nodered.org/u/j2002)\
**Post date:** [21 December 2023 12:38 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/8 "2023-12-21T12:38:58Z")

</div>

I'm not sure if I'm using LWT. I will say I'm not. Where shall I check that?

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [21 December 2023 12:39 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/9 "2023-12-21T12:39:42Z")

</div>

In the MQTT node config settings

---

<div class="post-metadata">

**Author:** ![j2002](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@j2002](https://discourse.nodered.org/u/j2002)\
**Post date:** [21 December 2023 12:48 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/10 "2023-12-21T12:48:09Z")

</div>

I can't find anything specifically called Last Will and Testament. Maybe you are talking about what I can find in MQTT-broker node config?: Message sent on an unexpected disconnection? It's left blank and I'm sure I've never touched it.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [21 December 2023 12:51 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/11 "2023-12-21T12:51:37Z")

</div>

Yes that's correct. I have never used it either, but it should cause the broker to publish a message if your NR drops its connection.

Just as another check to see if it really is disconnected 😉

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [21 December 2023 13:04 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/12 "2023-12-21T13:04:21Z")

</div>

I just looked at Aedes broker node as I don't use it -

_You can use the MQTT protocol in Node-RED without an external MQTT broker like Mosquitto_

Are you sure that you using an external broker ?

---

<div class="post-metadata">

**Author:** ![j2002](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@j2002](https://discourse.nodered.org/u/j2002)\
**Post date:** [21 December 2023 13:22 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/13 "2023-12-21T13:22:07Z")

</div>

I will give a try.  
And I'm pretty sure as I access to collected data in a server thousands of km away, so quite remote, yes.

---

<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:** [21 December 2023 13:54 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/14 "2023-12-21T13:54:57Z")

</div>

How is the mqtt broker node configured?

---

<div class="post-metadata">

**Author:** ![j2002](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@j2002](https://discourse.nodered.org/u/j2002)\
**Post date:** [21 December 2023 14:33 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/15 "2023-12-21T14:33:49Z")

</div>

Server: xxxxx Port 1883  
Connect automatically  
Protocol MQTT V3.1.1  
Client ID: blank  
Keep alive: 60  
Use Clean Session  
Birth, close and will messages Topic, Payload and Retain: Blank  
Birth, close and will messages QoS: 0

---

<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:** [21 December 2023 15:17 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/16 "2023-12-21T15:17:54Z")

</div>

> [@j2002](#):
>
> Server: xxxxx

Is that a remote machine?

What is the Aedes broker node that you show in your flow? What is it for?

Edit: Also where is node-red running and where is the browser running?

---

<div class="post-metadata">

**Author:** ![j2002](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@j2002](https://discourse.nodered.org/u/j2002)\
**Post date:** [21 December 2023 15:24 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/17 "2023-12-21T15:24:30Z")

</div>

Yes, it is the IP of a remote server.  
Aedes is not related with the problem (in my opinion). It was used to test some alternatives in the past  
Node-red is running on a Raspberry

---

<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:** [21 December 2023 15:42 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/18 "2023-12-21T15:42:29Z")

</div>

I aedes is not in use then I suggest removing it for the moment, just in case.

So the pi is local to you, and the mqtt server is remote?  
What are you running the browser on?

When you said you switched off the wifi, what device was that on?

---

<div class="post-metadata">

**Author:** ![j2002](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@j2002](https://discourse.nodered.org/u/j2002)\
**Post date:** [21 December 2023 16:02 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/19 "2023-12-21T16:02:55Z")

</div>

That's right. The raspberry is local. I can connect to it by VNC or by a browser on my PC (via WIFI).  
In addition, to do these tests, I physically connect to it, to deactivate wifi and see if StoreNForward status indicator increase (meaning, it is sending data to local file). As Isaid, it was its behaviour in the past, but now, MQTT out nodes are never "disconnected" from the broker

---

<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:** [21 December 2023 17:09 UTC](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914/20 "2023-12-21T17:09:32Z")

</div>

Do you mean that you don't know whether the nodes actually show disconnected or not, what you know is that things that are supposed to happen in that situation are not happening?  
If so then disconnect the wifi, leave it for a while, reconnect, and then look back at the node-red log to see what it says. You should be able to see mqtt disconnection messages.

Also you can configure debug nodes to monitor your flow and set them to output to the Console, then those will be visible in the node-red log too so you can debug the flow retrospectively.

[Next page](https://discourse.nodered.org/t/detecting-disconnection-of-mqtt-out-node/83914.md?page=2)
