Weird things happening with `node.status`

(Yes, I've been in a similar place before.)

I think this is different.

Prelude:

I have a function node that is receiving two messages and creating a new message when the two other messages are received.

To help me with seeing what is going on I use the node.status({}) command.
The idea is that when message 1 is received the node indicates that.
Then when message 2 is received, the node also indicates this.

YES! There is a problem with this.
As both messages arrive at the same time (basically speaking) I only see one message.

So to get around this I delayed one of the messages a few seconds.

Given the messages are coming through every 20 seconds, it is not a big deal.

So I set a 3 second delay.

So I'd expect to see (badly worded)
message 1 received. 3 seconds later message 2 received. 17 seconds.
message 1 received. 3 seconds later message 2 received. 17 seconds.

No.
The only way I can get it to do this (with the changes in time understood as being in the equation)
message 1 received. 5 seconds later. message 2 received. 15 seconds.
(repeat)

The messages are complicated but not impossible.
Here are two examples of the messages.

{"payload":{"Who":"TimePi","device":"Modem","Modem":"Online"},"_msgid":"166050d1d44749f4"}
{"payload":{"Who":"TimePi","device":"UpLink","UpLink":"Online"},"_msgid":"570805fe17dd94e5"}

They are sent in together but with a 5 second difference between then.

This is the node:

[{"id":"4bccf388.5f0814","type":"function","z":"c636aa5a.cc34","name":"Make ONE message","func":"let A;\nlet B;\nlet C;\nlet D = context.get(\"D\") || 0;\nlet E = context.get(\"E\") || 0;\nif (msg.topic == \"NEWDAY\")\n{\n    return msg;\n}\n\nif (msg.payload.device == \"Modem\")\n{\n    //\n    //  Modem detected.\n    //\n//    node.warn(\"Modem message arrived\");\n//    node.warn(msg.condition);\n    context.set(\"Modem\",1)\n    context.set(\"Modem_status\",msg.payload.Modem);\n    context.set(\"WHO\",msg.payload.Who);\n    node.status({ fill: \"green\", text: \"Modem\" });\n}\nif (msg.payload.device == \"UpLink\")\n{\n    //\n    //  UpLink detected.\n    //\n//    node.warn(\"UpLink message arrived\");\n//    node.warn(msg.condition);\n    context.set(\"UpLink\",1)\n    context.set(\"UpLink_status\",msg.payload.UpLink);\n    context.set(\"WHO\",msg.payload.Who);\n    node.status({ fill: \"red\", text: \"Uplink\" });\n}\n\n//node.status({});\n\n//if ((context.get(\"Modem\") == 1) && (context.get(\"Uplink\") == 1))\nif (context.get(\"Modem\") == 1)\n{\n    //\n    if (context.get(\"UpLink\") == 1)\n    {\n        //\n        //  both messages received.\n        //\n        //node.status({fill:\"yellow\",shape:\"dot\",text:\"message\"});\n        context.set(\"Modem\",0);\n        context.set(\"UpLink\",0);\n        A = context.get(\"Modem_status\");\n        B = context.get(\"UpLink_status\");\n        C = context.get(\"WHO\");\n        msg.topic = C;\n        //msg.payload = {\"Who\":msg.who,\"Modem\": context.get(\"Modem_status\"), \"Uplink\": context.get(\"UpLink_status\")};\n\n        //node.status({});\n        \n        msg.payload = {\n            \"Who\":C,\n            \"Modem\": A, \n            \"UpLink\": B\n        };\n        return msg;\n    }\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1990,"y":4740,"wires":[["dc8d6eed.9ba1d8","cfb7b905.7a326"]]}]

Why doesn't the node.status work nicely with ONLY a 5 second difference between the two messages being received?

Other stuff:
NR 3.0.2
RasPi 3B+
Buster

node -v
v14.19.0

Thanks in advance.

Add node.warn() statements at the point you set the status and see what is going on.

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