'How to handle mqtt disconnection on Node-RED?

I'm implementing a draft of a connection between 2 Raspberry and an Arduino, connected via mqtt. I'm working on Node-RED flows and I used mqtt nodes.

As you can see, in mqtt node configuration there is the possibility to send different messages for specific moments (when the subscriber is online, when it goes offline and when it disconnects unexpectedly. I'd like to catch this last event and handle it. How can I do it?

enter image description here



Solution 1:[1]

You need to look at the status node, this can be used to monitor other nodes.

enter image description here

You can point it at the MQTT node and it will report every time the status text (next to the little coloured dot under the node) changes. You can use this to detect the disconnected state.

Beware that it will probably trigger during start up as the node starts disconnected.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hardillb