• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PROFINET to OPC UA data conversion with Node-RED
#1
I personally checked a data conversion from PROFINET to OPC UA and vice versa using Node-RED on netPI RTE 3 successfully.

First I was loading a Node-RED container onto my netPI from here https://hub.docker.com/r/hilschernetpi/netpi-nodered. At least the version tag 1.5.6 is needed.

This Node-RED versions contains on one hand a fieldbus node that turns netPI's netX network controller into a PROFINET device. On the other hand it contains an OPC UA server node that can be addressed across port 53880 via any client.

I developed a simple Node-RED flow that creates two OPC UA objects "Inputs" and Outputs" of data type "string" and size of 2 bytes for each the data from/to PROFINET shall get exchange across on OPC UA side.

Code:
[{"id":"4489596a.516928","type":"OpcUa-Server","z":"bf08491e.4ddf1","port":"53880","name":"OPC-UA Server","endpoint":"UA/SimpleNodeRedServer","x":1120,"y":260,"wires":[["10d54ef6.e0f8a9"]]},{"id":"8123b078.34d418","type":"inject","z":"bf08491e.4ddf1","name":"Data string","topic":"","payload":"Hello World","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":220,"y":420,"wires":[["c2559406.92e0b"]]},{"id":"8aba729c.24dae","type":"status","z":"bf08491e.4ddf1","name":"Get OPC UA server status","scope":["4489596a.516928"],"x":270,"y":120,"wires":[["cfbd0cca.68f4c8"]]},{"id":"cfbd0cca.68f4c8","type":"switch","z":"bf08491e.4ddf1","name":"If running -> continue","property":"status.fill","propertyType":"msg","rules":[{"t":"eq","v":"green","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":660,"y":120,"wires":[["a292296a.862468","dabbc6c8.72862"]]},{"id":"f6c11eb7.173e38","type":"change","z":"bf08491e.4ddf1","name":"Command \"addVariable\"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{ \"opcuaCommand\": \"addVariable\" }","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":260,"wires":[["4489596a.516928"]]},{"id":"a292296a.862468","type":"change","z":"bf08491e.4ddf1","name":"Add \"Inputs\" variable","rules":[{"t":"set","p":"topic","pt":"msg","to":"ns=1;s=Inputs;datatype=String","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":240,"wires":[["f6c11eb7.173e38"]]},{"id":"933612fe.e2fb58","type":"comment","z":"bf08491e.4ddf1","name":"Check OPC UA server status","info":"","x":200,"y":60,"wires":[]},{"id":"9ba5bd0d.da3648","type":"comment","z":"bf08491e.4ddf1","name":"Add input and output buffer to OPC UA server","info":"","x":250,"y":180,"wires":[]},{"id":"88b215a0.e3cda8","type":"comment","z":"bf08491e.4ddf1","name":"Inject Inputs manually","info":"","x":180,"y":360,"wires":[]},{"id":"3676aa42.e7c55e","type":"comment","z":"bf08491e.4ddf1","name":"PROFIBUS inputs to OPC UA server","info":"","x":220,"y":480,"wires":[]},{"id":"dabbc6c8.72862","type":"change","z":"bf08491e.4ddf1","name":"Add \"Outputs\" variable","rules":[{"t":"set","p":"topic","pt":"msg","to":"ns=1;s=Outputs;datatype=String","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":300,"wires":[["f6c11eb7.173e38"]]},{"id":"c2559406.92e0b","type":"change","z":"bf08491e.4ddf1","name":"Add variable name \"Inputs\"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Inputs","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":420,"wires":[["b9696001.48685"]]},{"id":"6a96c8f3.ddc1c8","type":"change","z":"bf08491e.4ddf1","name":"Add variable name \"Inputs\"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Inputs","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":540,"wires":[["d52aa695.c840a8"]]},{"id":"b9696001.48685","type":"change","z":"bf08491e.4ddf1","name":"To JSON","rules":[{"t":"set","p":"payload","pt":"msg","to":"{ \"messageType\" : \"Variable\", \"variableName\": msg.topic, \"variableValue\": msg.payload }","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":420,"wires":[["4489596a.516928"]]},{"id":"d52aa695.c840a8","type":"change","z":"bf08491e.4ddf1","name":"To JSON","rules":[{"t":"set","p":"payload","pt":"msg","to":"{ \"messageType\" : \"Variable\", \"variableName\": msg.topic, \"variableValue\": msg.payload }","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":540,"wires":[["4489596a.516928"]]},{"id":"1b409600.aa19f2","type":"comment","z":"bf08491e.4ddf1","name":"OPC UA server to PROFIBUS outputs","info":"","x":230,"y":620,"wires":[]},{"id":"10d54ef6.e0f8a9","type":"switch","z":"bf08491e.4ddf1","name":"\"Outputs\"?","property":"payload.variableName","propertyType":"msg","rules":[{"t":"eq","v":"Outputs","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":210,"y":700,"wires":[["f3cc4f4a.30ef08"]]},{"id":"f3cc4f4a.30ef08","type":"function","z":"bf08491e.4ddf1","name":"string to array","func":"msg.payload.value = [];\n\nfor (let i=0; i < msg.payload.variableValue.length; i++) {\n    msg.payload.value[i] = msg.payload.variableValue.charCodeAt(i);\n}\n\ndelete msg.payload.variableValue;\ndelete msg.payload.variableName;\ndelete msg.payload.messageType;\n\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":700,"wires":[["6943568d.333558"]]},{"id":"e6483c51.702b58","type":"fieldbus in","z":"bf08491e.4ddf1","name":"PROFINET IO","FieldbusNodeVersion":"1.2.7","WrapperVersion":"1.2.8","WrapperCompileDate":"Feb 18 2020/14:33:18","MinExpectedNodeJSVersion":"12.13.1","ActNodeJSVersion":"12.18.1","ActNodeREDVersion":"1.0.6","selectedSignalPath":"input~receive_001~Sig_1","fieldbusObj":"b5082b22.f82568","x":210,"y":540,"wires":[["c2fd56f0.52b8f"]]},{"id":"6943568d.333558","type":"fieldbus out","z":"bf08491e.4ddf1","name":"PROFINET IO","FieldbusNodeVersion":"1.2.7","WrapperVersion":"1.2.8","WrapperCompileDate":"Feb 18 2020/14:33:18","MinExpectedNodeJSVersion":"12.13.1","ActNodeJSVersion":"12.18.1","ActNodeREDVersion":"1.0.6","selectedSignalPath":"output~send_001~Sig_1","fieldbusObj":"b5082b22.f82568","x":620,"y":700,"wires":[]},{"id":"c2fd56f0.52b8f","type":"function","z":"bf08491e.4ddf1","name":"array to string","func":"msg.payload = Buffer.from(msg.payload.value);\nmsg.payload = msg.payload.toString();\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":540,"wires":[["6a96c8f3.ddc1c8"]]},{"id":"b5082b22.f82568","type":"fieldbus interface","z":"","availableStackName":"PROFINET IO Device (version 3.12, build 0 revision 2): cifX0","interfaceComponents":"{\"fwName\":\"PROFINET IO Device\",\"boardName\":\"cifX0\",\"fwVersionMajor\":3,\"fwVersionMinor\":12,\"fwVersionBuild\":0,\"fwVersionRev\":2,\"prtName\":\"PROFINET IO\",\"className\":\"Device\",\"prtClassNumber\":21,\"commClassNumber\":10,\"channelNumber\":2,\"deviceNumber\":7660120,\"serialNumber\":21947}","clearOutputsOnDeploy":false,"traceFilePath":"/root/.node-red/node-fieldbus.log","traceLevelWrapper":"wrapper","traceLevelNode":"node"}]


Import this flow for own tests with copy and paste across your clipboard and insert it via the Node-RED embedded "import" function. Before it runs fine you need to double click one of the PROFINET nodes and select "open" to open the Fieldbus configuration web page and configure "2 send bytes" and "2 receive bytes" in exactly that order and click Project "save". Then you can deploy the flow.

Please to not forget to give the new netPI PROFINET device a name over Ethernet using tools supporting the DCP protocol that is explained here what it is: https://profinetuniversity.com/naming-ad...finet-dcp/. The default name is "niotenpi351gbenre" and stated in the GSDML file that can be download in the fieldbus configrator as well.

As counterpart on OPC UA side I was using a free OPC UA client from company Unified Automation that everybody can download from here after registration: https://www.unified-automation.com/downl...ients.html

Since the OPC UA server node does not send the user a message when it is finished initializing, I am using a "status" node as a trick to get triggered when the status of the OPC UA node changes to "green" in order to have an indication when the objects "Inputs" and "Outputs" can be created. If you are not wating creating such objects will fail!

Because the OPC UA server node just supports the data type "string" as only object that is of type array I am using that one to exchange data from/to PROFINET.

Have fun.
You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] Storing data on a (remote) database MGharat 20 26,544 June-13th-2022, 03:05 PM
Last Post: Armin@netPI
  IoT Edge Gateway: Node-RED - ARRAY -> OPC UA AxelHa2111 5 6,217 May-21st-2021, 05:13 PM
Last Post: Armin@netPI
  Configuring S7-1200 PLC to communicate with node-red ... Cman587 3 6,869 January-27th-2021, 11:01 AM
Last Post: Armin@netPI
  InfluxDB, Node-RED and Grafana Armin@netPI 0 4,431 January-6th-2021, 02:36 PM
Last Post: Armin@netPI
  Read/write data from S7 with netPI over Profinet student 10 12,322 September-9th-2020, 04:59 PM
Last Post: Armin@netPI
  Converter from TCP/IP to ProfiNet WalterSchaefer 8 8,547 August-5th-2020, 08:31 PM
Last Post: WalterSchaefer
  Send Data to Specific Port via UDP Hoeber 2 4,202 July-29th-2020, 09:10 AM
Last Post: Hoeber
  Getting data from AllenBradley PLC MarcoMedina 3 5,237 February-26th-2020, 11:53 AM
Last Post: Armin@netPI
  Accessing Siemens S7 PLCs over Node-RED Armin@netPI 3 10,808 February-24th-2020, 06:44 PM
Last Post: jacp
Information NPIX-RCAN with node-red-contrib-canbus node patrick 0 2,628 August-22nd-2019, 02:36 PM
Last Post: patrick

Forum Jump:


Users browsing this thread: 1 Guest(s)