# Dynamic WatchDog MQTT

**URL:** <https://discourse.nodered.org/t/dynamic-watchdog-mqtt/79190>\
**Category:** General\
**Tags:** mqtt\
**Created:** [14 June 2023 08:47 UTC](https://discourse.nodered.org/t/dynamic-watchdog-mqtt/79190 "2023-06-14T08:47:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)\
**Post date:** [14 June 2023 08:47 UTC](https://discourse.nodered.org/t/dynamic-watchdog-mqtt/79190/1 "2023-06-14T08:47:22Z")

</div>

Hello Community,

I use MQTT protocol for my system.I have a lot of rpi and I use a dynamic post but the properties WagDog is not dynamic.

 ![WatchDog](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3c91caa30acc667cc85253e09864e9968aa0fe08.jpeg)

Ex:  
rpi 1 the topic is RPI1/Input  
RPI1/Watchdog  
rpi 2 the topic is RPI2/Input  
RPI2/Watchdog  
...  
...  
...  
rpi X the topic is RPIX/Input  
RPIX/Watchdog

Is it possible to make this properties dynamic?

Thank you

---

<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:** [14 June 2023 08:50 UTC](https://discourse.nodered.org/t/dynamic-watchdog-mqtt/79190/2 "2023-06-14T08:50:27Z")

</div>

Most aspects of the MQTT nodes are dynamic (including setting LWT) however you don't _really_ need that complexity.

Just use env vars instead.

E.g. `${MQTTLWT}`

[https://nodered.org/docs/user-guide/environment-variables](https://nodered.org/docs/user-guide/environment-variables)

---

<div class="post-metadata">

**Author:** ![LinkView\_Maze](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@LinkView\_Maze](https://discourse.nodered.org/u/LinkView_Maze)\
**Post date:** [14 June 2023 09:10 UTC](https://discourse.nodered.org/t/dynamic-watchdog-mqtt/79190/3 "2023-06-14T09:10:38Z")

</div>

Ok I understand the principle but not the method of writing.

Could I have an example of flow?

---

<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:** [14 June 2023 09:27 UTC](https://discourse.nodered.org/t/dynamic-watchdog-mqtt/79190/4 "2023-06-14T09:27:37Z")

</div>

> [@LinkView\_Maze](#):
>
> Could I have an example of flow?

Um. Not really practical TBH.

Here is a minimal procedure:

- set an environment variable named `MQTTLWT` to the value `RPI1/Watchdog` in PI 1
- set an environment variable named `MQTTLWT` to the value `RPI2/Watchdog` in PI 2
- set an environment variable named `MQTTLWT` to the value `RPIn/Watchdog` in PI n
- change the MQTT config "Messages" topics from `RPI1/Watchdog` to `${MQTTLWT}`
- (re)start node-red on all the PIs

As for how to set an env variable - this is an operating system specific thing (but there are LOTS of docs, tutorials and vides around the net - just search "[set permanent environment variable debian](https://www.google.com/search?q=set+permanent+environment+variable+debian)")

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 August 2023 09:27 UTC](https://discourse.nodered.org/t/dynamic-watchdog-mqtt/79190/5 "2023-08-13T09:27:40Z")

</div>

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