Monitor a Rpi/node-red with another Rpi/node-red


I am running a node-red install in my ships sump where it serves an important function in taking notice of when the sewage tank is full and then turning on the pump to empty the tank - while letting me know that this is happening by a notification. Works excellently.

On the "bridge" of the boat I have another node-red installation that is managing a full control panel of LED's and buttons where I can control relays around the boat through various protocols. Works great as well.

Now I want the node-red in the control panel to know the run-status of the node-red (or the rpi really) in the sump. Because if for some reason the rpi in the sump looses power, I want to know by the node-red on the bridge lighting up an LED in my control panel.

I have the two linked together with MQTT, but I am unsure how to write the appropriate code. I suppose it's something about sending out a ping once in a while and if that ping isn't coming then light up a warning light. It is not critical to know right away wether the sewage node-red is down, just a ping every 10 minutes or so.

How would I make this functionality work? Thanks.

You actually don't need code for that if both devices are running MQTT. Simply configure so that the central Pi's broker subscribes to and so republishes the appropriate topic(s). So-called "bridge" mode for the bridge!

When you setup the MQTT connection in your client (Pi in the Bilges) you can use the "Messages" tab to specify a "Birth Message" and a "Will Message" AKA LWT.

Now when the Pi in the Bilges connects to your broker (Pi on the Bridge) a message will be published on the birth message topic - for example
{"topic": "bilges/birth", "payload" "Bilge Pi Connected to MQTT"}

And if Bilge Pi succumbs to a flood of sewage, after a bit ot a timeout (default 30 sec?) a message will be published of the LWT topic - for example
{"topic": "bilges/lwt", "payload" "Bilge Pi has sunk"}

Bridge Pi can subscribe to this topic and inform you that the ship has hit the fan.

1 Like

Ah, that looks really like what I need. I tried it out and it works. Thanks. Only thing I can't figure out is how or where to place a timeout. I suppose the Bridge Pi needs to check regularly for the LWT thing, but if I set up a mqtt receiver on the Bridge subscribing to the bilges/lwt then I can't put a "check every 30 seconds" there. It doesn't allow inputs.

Here's my nodes on the Bridge pi

I actually don't get it completely. You are saying that in the "will message" (setup and specified on the client mqtt setup (bilge pi)) but not on the broker then how does the client send out a "will" message if it is disconnected?

The birth message seem to work as expected (and that I get, it pings when it's awake).

It doesn't. The broker knows to send it on behalf of the client.

1 Like

Ah, I (think) get it. :slight_smile:

Then I suppose my question is where one may define the checking interval (if at all).

The client sends it's birth and lwt messages when it first connects but it's the broker that actually publishes them at the appropriate time.

There is an excellent series of explanations at

Well that's part one and LWT and the keep-alive feature are parts 9 and 10 but if you read/watch them all you'll be an expert.

This all works automagically but if you want more control you can get extra options by selecting MQTT v5.

Edit: And note that if you shutdown Bilge Pi it will disconnect gracefully from the broker; the last will and testament message is not sent (I think).
There is a third option on the Messages tab for messages at a graceful disconnect.

1 Like

If you are running under Docker you can add the health check option and monitor that from the other server as well as the MQTT option. Have a look at node-red-docker/.docker/healthcheck.js at master · node-red/node-red-docker · GitHub

Wow, that article on hivemq is amazing. Thanks for pointing me to that.

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