# Looking for node - "time between messages"

**URL:** <https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573>\
**Category:** General\
**Created:** [21 April 2022 02:38 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573 "2022-04-21T02:38:38Z")\
**Posts on this page:** 20\
**Page:** 1

<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:** [21 April 2022 02:38 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/1 "2022-04-21T02:38:38Z")

</div>

I shall try to search the library, but as I am not sure of the term to use, I'll ask here too.

I am _deubgging_ some stuff and need to find a nominal time for a message to go through the ~~system.~~ bunch of nodes.

I am sure there are such beasts, but just can't think of what they would be called.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)\
**Post date:** [21 April 2022 03:35 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/2 "2022-04-21T03:35:40Z")

</div>

Part of @BartButenaers amazing suite of nodes ... [node-red-contrib-interval-length (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-interval-length)

---

<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:** [21 April 2022 03:36 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/3 "2022-04-21T03:36:39Z")

</div>

Thanks. Shall get it now.

Ummm..... Reading the docs, I am not sure that is what I want/need.

That tells you the time between two messages arriving at a point - as I can read.

I need to know how long it takes a message to get from point `a` to point `b` in the flow.  
Sorry but reading the docs, I can't see that is what the node is doing.

---

<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:** [21 April 2022 03:48 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/4 "2022-04-21T03:48:50Z")

</div>

Sorry @Bobo ..... I am right. That gives me the time (at one point in the flow) between two messages arriving.

I need to get the time it takes for a message to propagate down the nodes/flow.  
(May not need it now as things have progressed.)

But thanks all the same.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [21 April 2022 05:04 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/5 "2022-04-21T05:04:55Z")

</div>

Andrew,  
Have a look at my [node-red-contrib-msg-profiler](https://github.com/bartbutenaers/node-red-contrib-msg-profiler). Note that it is _ **NOT** _ available on npm, since Nick preferred to have something like that in the core. See [this](https://github.com/node-red/designs/discussions/69) design.  
Bart

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [21 April 2022 06:07 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/6 "2022-04-21T06:07:32Z")

</div>

Even simpler, just use a trigger and debug node, attach to it's input from wherever needed and you get a timestamp when the msg arrives

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/e/7ef91fbf664da10f195c83f774149692abb464f0.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:** [21 April 2022 06:14 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/7 "2022-04-21T06:14:57Z")

</div>

Wow, that is an interesting way of doing it.

Thanks for the suggestion.

---

<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:** [23 April 2022 07:47 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/8 "2022-04-23T07:47:51Z")

</div>

I looked at your suggestion and this is the flow I have made.

Excluding the node which is being tested.

```auto
[{"id":"baeb7091b4dd2fce","type":"function","z":"c56bddee.ca0a18","name":"","func":"var a;\nvar b;\nvar c;\n\nif (msg.topic == \"A\")\n{\n // A\n a = msg.payload;\n node.warn(\"A = \" + a);\n return;\n} else\nif (msg.topic == \"B\")\n{\n // B\n b = msg.payload;\n node.warn(\"B = \" + b);\n}\n\nc = parseInt(b) - parseInt(a);\n\nmsg.payload = parseInt(c);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":4640,"wires":[["9d38ceb31750d74c"]]},{"id":"9d38ceb31750d74c","type":"debug","z":"c56bddee.ca0a18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":4640,"wires":[]},{"id":"291bdb0ac590b9ec","type":"change","z":"c56bddee.ca0a18","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"},{"t":"set","p":"topic","pt":"msg","to":"B","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":4680,"wires":[["baeb7091b4dd2fce"]]},{"id":"b44d44583e89fa74","type":"inject","z":"c56bddee.ca0a18","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"A","payloadType":"date","x":250,"y":4700,"wires":[["610e3e684b9f0ebb","baeb7091b4dd2fce"]]}]

```

So for the sake of it, stick in a `delay` node.

But when I test it, I get `NaN` output.

I don't get why it is not happy.

Sorry....

---

<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:** [23 April 2022 08:02 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/9 "2022-04-23T08:02:17Z")

</div>

Andrew, here is a subflow that you can use inline in any flow to mark the start and stop points - it was designed for this exact purpose.

Be sure to read the info and look at the demo

[https://flows.nodered.org/flow/63f29373e826a9fd4943d679d43e725f](https://flows.nodered.org/flow/63f29373e826a9fd4943d679d43e725f)

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [23 April 2022 08:04 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/10 "2022-04-23T08:04:12Z")

</div>

There is nothing from my suggestion I can find in your flow that you shared. Did you miss something...or exported something else?

---

<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:** [23 April 2022 08:05 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/11 "2022-04-23T08:05:50Z")

</div>

Sorry, I expanded on what I thought you said. Get two time stamps and determine the difference.

Steve's posted a subflow and I'm looking at it.

Thanks.

---

<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:** [23 April 2022 08:06 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/12 "2022-04-23T08:06:45Z")

</div>

~~On that link the `subflow only` isn't selectable.~~

Don't worry, I'll drag select it. (Been a bad day for the brain)

---

<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:** [23 April 2022 08:18 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/13 "2022-04-23T08:18:06Z")

</div>

Um, ok...

But I am now getting this error:

```auto
{"message":"TypeError: msg.payload.sort is not a function","source":{"id":"90fd90b2.99848","type":"function","name":"Native JS Sort","count":1}}

```

Again: sorry, but I don't understand.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [23 April 2022 08:20 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/14 "2022-04-23T08:20:41Z")

</div>

Well, I think the wait time in the trigger node maybe was too long (1 ms)

Here is a modified version that demonstrates how I thought it should work. It measures the time the execution inside the function node takes

```auto
[
    {
        "id": "72f81f8e71a4a22f",
        "type": "trigger",
        "z": "36f1953be98c4956",
        "name": "",
        "op1": "",
        "op2": "",
        "op1type": "date",
        "op2type": "nul",
        "duration": "0.000000001",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 910,
        "y": 1670,
        "wires": [
            [
                "a4e5417642ba9263"
            ]
        ]
    },
    {
        "id": "a4e5417642ba9263",
        "type": "debug",
        "z": "36f1953be98c4956",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1160,
        "y": 1670,
        "wires": []
    },
    {
        "id": "baeb7091b4dd2fce",
        "type": "function",
        "z": "36f1953be98c4956",
        "name": "",
        "func": "//do something\nlet t = msg.payload;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 900,
        "y": 1790,
        "wires": [
            [
                "9d38ceb31750d74c",
                "72f81f8e71a4a22f"
            ]
        ]
    },
    {
        "id": "9d38ceb31750d74c",
        "type": "debug",
        "z": "36f1953be98c4956",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1160,
        "y": 1790,
        "wires": []
    },
    {
        "id": "b44d44583e89fa74",
        "type": "inject",
        "z": "36f1953be98c4956",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "A",
        "payload": "just whatever",
        "payloadType": "str",
        "x": 580,
        "y": 1670,
        "wires": [
            [
                "72f81f8e71a4a22f",
                "baeb7091b4dd2fce"
            ]
        ]
    }
]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/7/a7d369a3b051b5ca844d7981c34efb8ee06a6bd8.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:** [23 April 2022 08:24 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/15 "2022-04-23T08:24:01Z")

</div>

Ah, ok.

Thanks.

Yeah, I don't know if that will help me.  
I can't understand why I can't get the maths working to find the difference of the two timestamps.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [23 April 2022 08:24 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/16 "2022-04-23T08:24:46Z")

</div>

Thats a new issue. You can see what you get in the debug

---

<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:** [23 April 2022 08:29 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/17 "2022-04-23T08:29:31Z")

</div>

It definitely works

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/1/21a7b3cca99e25531a331c03846745f9bd811987.png)

You have probably changed the inject & left the function from the demo - that expects payload to be an array - but it should just be deleted. You should ONLY use the "flow-timer" node INSIDE your flow.

  

You are supposed to simply add a START and STOP flow-timer in your own flow...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/7/3782edfd4a55118f17c0929542c2f686ed3d926e.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:** [23 April 2022 08:33 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/18 "2022-04-23T08:33:00Z")

</div>

Ok, my foot is in my mouth.

That flow you posted worked.

I looked at it, and thought I understood what it is and how to use it.... JSON, etc... Not needed.

Ok, so I use the top `inject` node. Press it twice and get a message (middle `debug` node) and I see the time between the two presses.

Argh!

Ok. I didn't use the first `function` node.

I'll go back and try again.

When the day starts bad, I hoped it would get better. It hasn't. It is getting worse.

Be back soon.

---

<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:** [23 April 2022 08:38 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/19 "2022-04-23T08:38:54Z")

</div>

In the mean time I (once again) was shown how stupid I am.

The bit of code I posted a while back starting _today's_ posts was wrong in so many ways.

I just realised I wasn't saving the first value.

This is the function node code now and it works.

```auto
var a;
var b;
var c;

if (msg.topic == "A")
{
    // A
    a = msg.payload;
    node.warn("A = " + a);
    context.set("A",a);
    return;
} else
if (msg.topic == "B")
{
    // B
    b = msg.payload;
    node.warn("B = " + b);
}

a = context.get("A");
c = b - a;

msg.payload = c;

return msg;

```

That is the blown up version as I was checking myself through the code.

Really makes a big difference saving the context `A` for the first value.

😭

---

<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:** [23 April 2022 08:39 UTC](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573/20 "2022-04-23T08:39:53Z")

</div>

Sorry both @Steve-Mcl and @krambriw .

[Next page](https://discourse.nodered.org/t/looking-for-node-time-between-messages/61573.md?page=2)
