Detecting disconnection of MQTT out node

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


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?

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

1 Like

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

Nop, It is a remote one

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

1 Like

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

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

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

In the MQTT node config settings

1 Like

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.

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 :wink:

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 ?

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.

How is the mqtt broker node configured?

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

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?

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

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?

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

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.