Combine strings from multiple inputs

Hello experts,

I am an PLC engineer whith lots of experience in programming code for machines.
Node red however, is not my cup of tea.
Things which are easy for you, takes me a lot of time to think about.
I have a struggle with the following.

I have 2 inputs... 1 is an answer from my database msg.topic=token, another is an input string msg.topic=id.
I have to make a string with the following:
text <payload of topic "token"> text <payload of topic "id"> text.

Anyone who can help me out please.

Thanks

Show us what you have done so far.

Also, provide real example e.g.
"DB msg.payload contains "ABC123" and PLC msg.payload contains "999" - so I want to make a text payload of "The DB token is ABC123 and the PLC value is 999"

Lastly,
Export a demo flow (CTRL+E) so we can have a look.

NOTE: Please do not include database or PLC nodes in your export as we wont have your data nor do we have access to your PLCs (so it is pointless).
Instead, simulate the DB/PLC values using inject nodes.

Also, as you are new to node-red and struggling, you are probably missing some key concepts that help you understand. I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Hello Steve,

Thank you for your quick response.

The PLC information was background data of me.
The project is on a raspberry pi 4.

As you can see I have 2 topics with 2 payloads
I want to compine them in a single string
Not the topics, but the payloads of that topic.

It should look like
text - payload of topic "token" - text - payload of topic "auth" - text

I don't have any code to give you.
Tried different things, like join, template, function....
But nothing works out the way I want it to.

I will do the course, which you recommended

Thanks

See this article in the cookbook for an example of how to join messages into one object.

  • Link token and auth to a join node.
  • set join node to 2 parts & "key/value" mode
  • add a function after the join node with the following code
msg.payload = `payload of topic "token" = "${msg.payload.token}", payload of topic "auth" = "${msg.payload.auth}"` 
return msg;

Thank you very much Steve,

I was strugling for hours.

I would have come to your solution, even if I had studied for days.
Many thanks

Dear Steve,

Can you tell me how to get text string in between the 2 messages?

sorry, that doesnt make sense.

Provide an example or diagram to help explain.

Dear Steve

The code you provided.

msg.payload = payload of topic "token" = "${msg.payload.token}", payload of topic "auth" = "${msg.payload.auth}"
return msg;

This will show topic token and topic auth.
I want to put text string in front, in between and at the end of these messages

Sorry Steve,

MY bad...I had to studie your code better.

Its working perfectly.

Thank you

Dear Steve,

I have everything in a single string now.
Can you tell me how to get it into my http node
what I normally would put into the url field of the http node, is now in the payload of the function.

The function is connected to the http node
I have tried msg.payload, $mag.payload
only errors.

Your help would be apreciated

Not without some details. What http node? as a parameter? as a payload/data? Is the a http request node? Need details.

Build in help...
image

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