# How to retrieve the status of my mqtt

**URL:** <https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051>\
**Category:** General\
**Tags:** mqtt\
**Created:** [17 May 2024 08:19 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051 "2024-05-17T08:19:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://discourse.nodered.org/u/Paul)\
**Post date:** [17 May 2024 08:19 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/1 "2024-05-17T08:19:56Z")

</div>

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

 ![node2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/6/36605e4360daf6b12436320286aafbd3866c2772.png)  
 ![node1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/20f395192116c9e8c8a1e443935fb2d44ac6ecb9.png)

---

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://discourse.nodered.org/u/Paul)\
**Post date:** [17 May 2024 08:20 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/2 "2024-05-17T08:20:28Z")

</div>

![node5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/f/df906bbc89ecd8e3987f1d6c8d85378153d80966.png)

---

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://discourse.nodered.org/u/Paul)\
**Post date:** [17 May 2024 08:21 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/3 "2024-05-17T08:21:17Z")

</div>

![node4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/2/2282536d577f6dc063235d275a8afa6edfb7c3ae.png)

---

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://discourse.nodered.org/u/Paul)\
**Post date:** [17 May 2024 08:21 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/4 "2024-05-17T08:21:48Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/9/7901de1fcdc33088875858963c06413405bdaad1.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [17 May 2024 08:30 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/5 "2024-05-17T08:30:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [17 May 2024 08:42 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/6 "2024-05-17T08:42:29Z")

</div>

> [@Paul](#):
>
> I would like to be able to receive a notification which tells me the state of my mqtt server

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

Here is some reading:

- [What is MQTT Last Will and Testament (LWT)? – MQTT Essentials: Part 9](https://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament/)
- [Search results for 'mqtt lwt order:latest' - Node-RED Forum](https://discourse.nodered.org/search?q=mqtt%20lwt%20order%3Alatest)

---

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://discourse.nodered.org/u/Paul)\
**Post date:** [17 May 2024 08:47 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/7 "2024-05-17T08:47:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://discourse.nodered.org/u/Paul)\
**Post date:** [17 May 2024 08:48 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/8 "2024-05-17T08:48:14Z")

</div>

THANKS I'm going to look at this

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [17 May 2024 08:49 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/9 "2024-05-17T08:49:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 May 2024 08:57 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/10 "2024-05-17T08:57:32Z")

</div>

@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)

 ![Screenshot 2024-05-17 at 4.55.09 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/d/cd0bc0619bca681ac7a9562784e01b1a680a76dc.png)

```auto
[{"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.

---

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://discourse.nodered.org/u/Paul)\
**Post date:** [17 May 2024 09:07 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/11 "2024-05-17T09:07:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [17 May 2024 09:12 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/12 "2024-05-17T09:12:04Z")

</div>

@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!

---

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://discourse.nodered.org/u/Paul)\
**Post date:** [17 May 2024 09:12 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/13 "2024-05-17T09:12:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [17 May 2024 09:13 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/14 "2024-05-17T09:13:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [17 May 2024 09:16 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/15 "2024-05-17T09:16:59Z")

</div>

> [@Paul](#):
>
> However, the issue is that I don't have access to the MQTT server

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/6/56d73ce1e5375e269d330ae9e79e0ff7c57e560d.png)

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

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [17 May 2024 09:17 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/16 "2024-05-17T09:17:25Z")

</div>

# EDIT

See what @Steve-Mcl said.

😉

> [@Paul](#):
>
> However, the issue is that I don't have access to the MQTT

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.

---

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://discourse.nodered.org/u/Paul)\
**Post date:** [17 May 2024 09:29 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/17 "2024-05-17T09:29:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [17 May 2024 09:33 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/18 "2024-05-17T09:33:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://discourse.nodered.org/u/Paul)\
**Post date:** [17 May 2024 09:33 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/19 "2024-05-17T09:33:32Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f98abda5886911c643f86e080d743550d857fa7c.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [17 May 2024 09:35 UTC](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051/20 "2024-05-17T09:35:56Z")

</div>

> [@Paul](#):
>
> 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.

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?

[Next page](https://discourse.nodered.org/t/how-to-retrieve-the-status-of-my-mqtt/88051.md?page=2)
