# Track messages across nodes

**URL:** <https://discourse.nodered.org/t/track-messages-across-nodes/82850>\
**Category:** General\
**Created:** [14 November 2023 10:58 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850 "2023-11-14T10:58:26Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![andre\_x](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andre\_x](https://discourse.nodered.org/u/andre_x)\
**Post date:** [14 November 2023 10:58 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/1 "2023-11-14T10:58:26Z")

</div>

I'm having some problems on a complex flow: I don't know which node turns on some lights! 🙈  
Is there a way to track the messages across nodes so that I can understand which function triggers the lights?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 November 2023 11:13 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/2 "2023-11-14T11:13:24Z")

</div>

I don't know the answer to the question, but if you add debug nodes to the output of each node that can turn the lights on then you should be able to find it.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [14 November 2023 11:30 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/3 "2023-11-14T11:30:38Z")

</div>

I scatter a few of these to see what and where a message is being routed (requires node-red-contrib-simpletime)

```auto
[{"id":"42652991.2d0e78","type":"subflow","name":"+ hh:mm:ss","info":"","category":"","in":[{"x":40,"y":60,"wires":[{"id":"68633fa6.25f2e"}]}],"out":[{"x":380,"y":60,"wires":[{"id":"68633fa6.25f2e","port":0}]}],"env":[],"meta":{},"color":"#C7E9C0","icon":"node-red-contrib-sun-position/clock-white.png","status":{"x":380,"y":120,"wires":[{"id":"421b10be.1db69","port":0},{"id":"68633fa6.25f2e","port":0}]}},{"id":"68633fa6.25f2e","type":"simpletime","z":"42652991.2d0e78","name":"","mydate":false,"myymd":true,"myyear":false,"mymonth":false,"mymonthn":false,"mydom":false,"mydoy":false,"myday":false,"myhourpm":false,"myhour":false,"mytime":false,"mytimes":true,"myminute":false,"myminutes":false,"mysecond":false,"mymillis":false,"myepoch":false,"myrawdate":false,"mypm":false,"x":115,"y":60,"wires":[["a8b5a4ba.c0c178"]],"l":false},{"id":"421b10be.1db69","type":"change","z":"42652991.2d0e78","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"mytimes","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":180,"wires":[[]]},{"id":"a8b5a4ba.c0c178","type":"delay","z":"42652991.2d0e78","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":120,"y":180,"wires":[["421b10be.1db69"]]},{"id":"96c1978419f64b6f","type":"subflow:42652991.2d0e78","z":"d760e2801b9ca31b","name":"","env":[],"x":305,"y":610,"wires":[["b57d7d0afc2c0bd1","af93327c733ce7b1"]],"l":false}]

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [14 November 2023 14:53 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/4 "2023-11-14T14:53:44Z")

</div>

If I'm using MQTT, I often add sub-topics that indicate the origin flow and last update.

For a pure message flow, maybe consider adding a "standard" bit of metadata to the msg. Maybe:

```auto
msg = {
   .....
   _meta: {
       track: [
          // .. each section of flow your msg traverses, push another entry to this array
      ]
   }

```

---

<div class="post-metadata">

**Author:** ![andre\_x](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andre\_x](https://discourse.nodered.org/u/andre_x)\
**Post date:** [14 November 2023 15:26 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/5 "2023-11-14T15:26:40Z")

</div>

Mmm...I've imported your flow, but I didn't get it. Could you elaborate a bit?  
Thanks!

---

<div class="post-metadata">

**Author:** ![andre\_x](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andre\_x](https://discourse.nodered.org/u/andre_x)\
**Post date:** [14 November 2023 15:27 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/6 "2023-11-14T15:27:25Z")

</div>

I know, but I have thousands of nodes around about 15 pages and it's quite impossible to add a debug node everywhere.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 November 2023 15:31 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/7 "2023-11-14T15:31:52Z")

</div>

Surely there are not thousands of nodes that output to the lights?

---

<div class="post-metadata">

**Author:** ![andre\_x](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andre\_x](https://discourse.nodered.org/u/andre_x)\
**Post date:** [14 November 2023 15:33 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/8 "2023-11-14T15:33:02Z")

</div>

This seems a very nice idea!  
For now it would mean that I'll have to redo all the function node and it wouldn't work on the _change_ nodes.  
Also sometimes I discard the old msg and create a new one to lose unnecessary msg.\*.  
I'll keep your idea in mind for the next developments.  
Thanks!

---

<div class="post-metadata">

**Author:** ![andre\_x](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andre\_x](https://discourse.nodered.org/u/andre_x)\
**Post date:** [14 November 2023 15:33 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/9 "2023-11-14T15:33:55Z")

</div>

That outputs to the lights no, but those that does have tens of connections each, so I don't know where the command starts.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 November 2023 15:37 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/10 "2023-11-14T15:37:13Z")

</div>

> [@andre\_x](#):
>
> I don't know where the command starts.

Work back through the flow.

---

<div class="post-metadata">

**Author:** ![andre\_x](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andre\_x](https://discourse.nodered.org/u/andre_x)\
**Post date:** [14 November 2023 15:46 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/11 "2023-11-14T15:46:14Z")

</div>

As I told you, each node that output a command to the light, has tens of node connected to it.  
It it was so easy, I would have already done it!  
Your replies aren't really helping.

---

<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:** [14 November 2023 16:28 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/13 "2023-11-14T16:28:26Z")

</div>

How many mqtt-out nodes do you have?  
Are they multi-purpose with the topic set by msg.topic or is the topic generally hard coded in the mqtt node?

---

<div class="post-metadata">

**Author:** ![andre\_x](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andre\_x](https://discourse.nodered.org/u/andre_x)\
**Post date:** [14 November 2023 16:33 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/14 "2023-11-14T16:33:11Z")

</div>

I have just a few (4 or 5) MQTT out nodes that are generic, the topics are generated in other nodes.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 November 2023 16:45 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/15 "2023-11-14T16:45:27Z")

</div>

> [@andre\_x](#):
>
> each node that output a command to the light, has tens of node connected to it.

Wow, you have tens of different ways that a light can be switched on/off. I am surprised by that.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [14 November 2023 17:10 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/16 "2023-11-14T17:10:37Z")

</div>

> [@andre\_x](#):
>
> For now it would mean that I'll have to redo all the function node and it wouldn't work on the _change_ nodes.  
> Also sometimes I discard the old msg and create a new one to lose unnecessary msg.\*.  
> I'll keep your idea in mind for the next developments.

There is also a design principle in there about "loose coupling". Trying to make sure that you are not tightly coupling different sections of your logic and data. I use MQTT a fair bit for that because it gives you an event driven loose coupling that is generally still highly performant.

But yes, unfortunately, that does likely mean some rework. Most of my home automation stuff has been completely rewritten at least 4 or 5 times. 🙂

---

<div class="post-metadata">

**Author:** ![andre\_x](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@andre\_x](https://discourse.nodered.org/u/andre_x)\
**Post date:** [14 November 2023 17:37 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/17 "2023-11-14T17:37:48Z")

</div>

> [@TotallyInformation](#):
>
> There is also a design principle in there about "loose coupling". Trying to make sure that you are not tightly coupling different sections of your logic and data. I use MQTT a fair bit for that because it gives you an event driven loose coupling that is generally still highly performant.

Do you mean that you link different section of your Node Red project with MQTT instead of link IN/OUT?

> [@TotallyInformation](#):
>
> But yes, unfortunately, that does likely mean some rework. Most of my home automation stuff has been completely rewritten at least 4 or 5 times. 🙂

😄  
I'm not there...yet! I think that I'm _only_ at the third version!!!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [14 November 2023 17:57 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/18 "2023-11-14T17:57:34Z")

</div>

> [@andre\_x](#):
>
> Do you mean that you link different section of your Node Red project with MQTT instead of link IN/OUT?

Yes. here is an example. I take the inputs from my 433MHz devices all in one place, standardise the data and push to MQTT.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/89fb02759849cdf60a5a607309f6e1002033e3b3.png)

And here, I listen to some of them and output - again to MQTT

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/16d0af350cf05fd67d29958ce945cca77a276957.png)

Those outputs are listened to in another flow that outputs to Telegram. Of course, I could have many other outputs if I needed them.

So each section of "code" is kept relatively simple and if, for example, I needed to rip out Telegram and replace with something else, that would be easy. Just as easy would be ripping out the 433MHz stuff and replacing with something else without having to replace the other logic.

---

<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:** [15 November 2023 12:03 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/19 "2023-11-15T12:03:16Z")

</div>

I was wondering if a flow to generate a list of dashboard tabs and the nodes which link to mqtt would help, something like this  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/97aa41412ffc400115698bbcca4e070197df1af1.png)

```auto
{"tabs":{"tab1":{"name":"tab1","id":"c7777","nodes":{"aaa":{"nodename":"aaa","mqttnode":{"name:":"mqtt1","OnTab":"tab1"}},"bbb":{"nodename":"bbb","mqttnode":{"name:":"mqtt1","OnTab":"tab1"}}}},"tab2":{"name":"tab2","id":"c7777","nodes":{"aaa":{"nodename":"aaa","mqttnode":{"name:":"mqtt1","OnTab":"tab1"}},"bbb":{"nodename":"bbb","mqttnode":{"name:":"mqtt1","OnTab":"tab1"}}}}}}

```

but I'm having difficulty generating that format from the flows file.

---

<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:** [14 January 2024 12:03 UTC](https://discourse.nodered.org/t/track-messages-across-nodes/82850/20 "2024-01-14T12:03:21Z")

</div>

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