Hi and welcome to the forum.
This is a bit tricky, depending on your knowledge of all the stuff you can do with the nodes.
You are kind of right with the join node, but it won't guarantee the order of the two messages.
This needs a bit more magic that you know just now.
But for the sake of helping you get on your way, here is the basic idea of what you need to do:
The trick is with a function
node because it has a bit more of the magic under its hood than the other nodes and can store messages for later use.
The problem you are having is that in node-red, everything is real time and no messages are stored. Unless you use something like the join
node.
Good on you for trying/thinking of it.
So, first off each message will need to have a unique attribute so they can be identified.
This is only needed as far as the function
node.
For this example, I'll make Message 1 and Message 2 easy to identify.
// store the incoming message value.
if (msg.topic == "MESSAGE1")
{
context.set("message1",msg.payload);
}
if (msg.topic =="MESSAGE2")
{
context.set("message2",msg.payload);
}
msg = {}; // wipe the message.
var a = context.get("message1");
var b = context.get("message2");
if (a.length > 0)
{
if (b.length > 0)
{
msg.payload = context.get("message1") + context.get("message2")
context.set("message1","");
context.set("message2","");
return msg;
}
}
This was typed here, now and I haven't tested it.
But I hope that helps you understand what is needing to be done.
Good luck.
Ok, that code doesn't work. (I'm not that good)
But this does and it is an example as well.
[{"id":"319a422441bd214c","type":"function","z":"0918ee609bf69fc7","name":"","func":"// store the incoming message value.\nif (msg.topic == \"MESSAGE1\")\n{\n context.set(\"message1\",msg.payload);\n}\nif (msg.topic ==\"MESSAGE2\")\n{\n context.set(\"message2\",msg.payload);\n}\nmsg = {}; // wipe the message.\n\nvar a = context.get(\"message1\") || \"\";\nvar b = context.get(\"message2\") || \"\";\n\n\n\nif ((a.length) > 0)\n{\n if ((b.length) > 0)\n {\n msg.payload = context.get(\"message1\") + context.get(\"message2\")\n context.set(\"message1\",\"\");\n context.set(\"message2\",\"\");\n return msg;\n }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":1610,"wires":[["e18a85119048611f"]]},{"id":"b27b8df82741fb13","type":"inject","z":"0918ee609bf69fc7","name":"first","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"MESSAGE1","payload":"first","payloadType":"str","x":470,"y":1570,"wires":[["319a422441bd214c"]]},{"id":"c8c591968a100e7d","type":"inject","z":"0918ee609bf69fc7","name":"second","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"MESSAGE2","payload":"second","payloadType":"str","x":470,"y":1630,"wires":[["319a422441bd214c"]]},{"id":"e18a85119048611f","type":"debug","z":"0918ee609bf69fc7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":1610,"wires":[]}]