Looking for node - "time between messages"

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.

Part of @BartButenaers amazing suite of nodes ... node-red-contrib-interval-length (node) - Node-RED

2 Likes

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.

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.

Andrew,
Have a look at my 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 design.
Bart

1 Like

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

3 Likes

Wow, that is an interesting way of doing it.

Thanks for the suggestion.

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

Excluding the node which is being tested.

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

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

1 Like

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

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.

On that link the subflow only isn't selectable.

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

Um, ok...

But I am now getting this error:

{"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.

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

[
    {
        "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"
            ]
        ]
    }
]

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.

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

It definitely works

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...

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.

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.

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.

:sob:

Sorry both @Steve-Mcl and @krambriw .