How to retrieve the status of my mqtt

Hello, I would like to know if it was possible to retrieve the state of my mqtt server in a debug because subsequently I would like to be able to receive a notification which tells me the state of my mqtt server

I searched and did this, but I don't get anything in my debug

have a good day lagache paul


Hi Paul.

As a new user, you are limited to how many posts you can make per day.
You've used 4 of them just now.
All of what you posted could be in/on one post.

I am not understanding what you are wanting to do. Sorry.

broker is the term for the machine which is the MQTT machine to which all other machines send their messages and distributes the messages.

This is what the LWT (Last Will and Testament) if designed for.

Here is some reading:

Thank you for the information. Let me explain in more detail what I would like to do.

In recent weeks, I've encountered connection issues with the MQTT server to which I send a JSON. I would like to set up an alarm log that alerts me by email or another method when the server is disconnected. On the Node-RED flow display, you can see the status of the MQTT server (connected or disconnected). I would like to know if it is possible to retrieve this information so that I can receive an alert when the server is disconnected.

Thank you.

Lagache Paul-Henri

THANKS I'm going to look at this

Reading it and how I see it:

I would say you have a basic network problem you need to find.

Sending emails (or what ever) when the MQTT does down isn't really going to achieve much.

@Paul welcome to the forum.

Here are a couple of ideas:
You could use MQTT Explorer (a stand alone app) to see if it is active
You could have a MQTT-in node with a topic of $SYS/broker/uptime. That should receive a message at a regular interval. (in my test I get a message every 11 seconds). By adding a 1trigger` node you use that to identify when it wasn't active.

Here is an image of my test flow and the code so you can import it (note you will have to configure the mqtt-in node to your broker)

[{"id":"1e934ab2256fd7b2","type":"debug","z":"21c74addd196f0d8","name":"debug 3425","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":580,"wires":[]},{"id":"c52c7c483ecaa05e","type":"mqtt in","z":"21c74addd196f0d8","name":"","topic":"$SYS/broker/uptime","qos":"2","datatype":"auto-detect","broker":"ad801e2e54d5319b","nl":false,"rap":true,"rh":0,"inputs":0,"x":310,"y":580,"wires":[["9eebd21f3e4951bb","4f0ed69cad9aebc8"]]},{"id":"9eebd21f3e4951bb","type":"trigger","z":"21c74addd196f0d8","name":"","op1":"","op2":"MQTT Broker down","op1type":"nul","op2type":"str","duration":"15","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":530,"y":580,"wires":[["1e934ab2256fd7b2"]]},{"id":"4f0ed69cad9aebc8","type":"debug","z":"21c74addd196f0d8","name":"debug 3426","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":640,"wires":[]},{"id":"ad801e2e54d5319b","type":"mqtt-broker","name":"","broker":"152.67.141.188","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

One more thing, my local MQTT Broker running on a Pi Zero W Rev 1.1 has been running non stop for 47 days.

2 Likes

This would allow me to know when the MQTT server is no longer reachable because I don't manage the MQTT server myself, so I don't know when there's an issue. Whereas if I know there's a problem, I can directly investigate instead of waiting for the person managing the MQTT server to no longer receive my JSON.

@Trying_to_learn makes a good point. In my experience the most likely cause of MQTT disconnection is network problems.
In that case I'm not likely to be able to send an email.

Interesting little flow @zenofmud, thanks!

Thank you for your response, it aligns with what I would like. However, the issue is that I don't have access to the MQTT server because my sole purpose in this project is to retrieve data using DP read nodes (Loytec) and then filter and send only the desired data in JSON format. If I understand correctly, the LWT is a feature specific to the server, and since I don't have access to it, I cannot implement it.

I suspect there is a deeper problem lurking around.

MQTT is a protocol that is robust.

It has a long life time line and has been used it a lot of things BECAUSE it is so easy to use.

Can you explain the network structure?

All cable?

WiFi?

Remote machines?

You dont need access to the server, only the MQTT nodes on Node-RED

Then simply subscribe via an MQTT in node to broker/lwt/status

1 Like

EDIT

See what @Steve-Mcl said.

:wink:

I'm confused.

This isn't consistent with how MQTT works.

And it a BROKER - for correct naming. Not a server.

When you configure the MQTT there is a tab that allows you to define the LWT message.

You put it in there and it works.

Sure, let me explain how the installation is set up.

So, the main goal of the project is to collect data and display it on an application. To achieve this, on our end, we have temperature probes, sensors, and meters. These devices feed data to Node-RED using the Loytec library. Node-RED then allows us to read the values. Then, on the side of the person managing the MQTT server, we send all the necessary data in JSON format. They then link this data to their MQTT database to store and use it on their web application.

An important point regarding the network is that all our meters are on a local network. To access this network remotely, we use a VPN.

This us (pronoun) is a bit off putting.

Please see @Steve-Mcl post #15.
It shows you how to get the LWT message.

You need to find out where this alleged failure is.
Going into NR or when it is being sent out.

Also using this loytec library.
Can't help you there and can't guarantee it works.

It could be the device isn't sending messages now and then.

Apply what @Steve-Mcl said and check where it is failing - if at all.

I'd like to set up something like a ping that tests the communication between MQTT and Node-RED every 5 seconds, for instance. If the ping doesn't return, I'd receive an email.

As shown in this screenshot where we see "connected," I'd like to retrieve this data to know when it switches to "disconnected." When it switches to "disconnected," I want to receive an alert.

image

That won't really work.
PING and MQTT are different protocols and because one fails may not mean the other fails.

PINGING a machine to determine the MQTT status is just asking for trouble.

It has been said:
USE THE LWT AS SHOWN

ALSO

If the machine is not connected to the network:
HOW can it send an email?