PLC to RPC XML v3.02

I am new to node red and having trouble finding where to look for an example.

I have an S7-1200 Siemens PLC hooked up to a barcode scanner.

I need to take some values off the PLC (which I have done already and am able to see values) and send them to a RPC api formatted in XML.

I have the structured XML ready but I am not sure how to format it so I can input variables from the PLC. I have a "template" but not sure if I am doing it correctly.

My trials so far:
S7-In -> Template (not sure how to function it here) -> XMLRPC
S7-In -> Function -> XMLRPC

The tutorials I have seen basically say structure for JSON and use XML parser, is that the best way?

Appreciate any help my Google Fu is failing me.

It is "a" way.

If the XML structure is static then a template can be easier.

What do you mean by "not sure how to function it here"?

The built in help of the template node provides a basic how to (and provides the mustache syntax) e.g...

Suppose you get data from PLC, then "condition it" in a change node or function node so that going into the template node is the following msg...

{
  topic: "widgets",
  payload: {
    name: "Recipe 1",
    speed: 400,
    pressure: 5.5,
    holdTime: 2500,
    coolTime: 4000
} 

but you need the final XML format of ...

<?xml version="1.0" encoding="UTF-8" ?>
<root>
  <name>widgets</name>
  <recipe>
    <speed>400</speed>
    <pressure>5.5</pressure>
    <hold-time>2500</hold-time>
    <cool-time>4000</cool-time>
  </recipe>
</root>

you could achieve it with the template ...

<?xml version="1.0" encoding="UTF-8" ?>
<root>
  <name>{{topic}}</name>
  <recipe>
    <speed>{{payload.speed}}</speed>
    <pressure>{{payload.pressure}}</pressure>
    <hold-time>{{payload.holdTime}}</hold-time>
    <cool-time>{{payload.coolTime}}</cool-time>
  </recipe>
</root>

Steve,
Thank you. Exactly an example I was looking for that should give me everything I need to get this done. Funny I saw a similar question earlier 2-3 years ago you answered didn't expect to see you here but thankful nonetheless, appreciate the help!

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