Connecting a Siemens PLC to an OPC UA Client. Node-red to Excel.

OPC UA Siemens
Siemens PLC to an OPC UA client

This article will guide you through the process of connecting a Siemens PLC to an OPC UA client. We’ll explore two different methods: using the UA Expert client for monitoring and using Node-RED to save data to an Excel file.

\for more info find link below to our Youtube videos.

To get started, you’ll need the following:

  • Siemens TIA Portal: A software suite for engineering and programming Siemens automation systems.
  • Siemens PLC: A programmable logic controller (e.g., S7-1200 or S7-1500).
  • Node-RED: A flow-based programming tool for connecting hardware devices, APIs, and online services.
  • Node.js: A JavaScript runtime environment, required to run Node-RED.
  • OPC UA Expert: A powerful OPC UA client for testing and diagnostics.

Step 1: Configure the Siemens PLC

First, you need to enable OPC UA communication on your Siemens PLC.

  1. Open TIA Portal: Open your project in the TIA Portal.
  2. Enable OPC UA Server: Navigate to the “Properties” of your PLC and select the “OPC UA” tab. Enable the OPC UA server and ensure the “Server is enabled” option is checked.
  3. Create Datablock and enable read from OPC client or HMI.
  4. Compile and Download: Compile the project and download the new configuration to your PLC.

Step 2: Connect with UA Expert

The UA Expert client is a great tool to confirm that your PLC’s OPC UA server is working correctly.

  1. Launch UA Expert: Open the OPC UA Expert software.
  2. Add a new Server: Click the “Add Server” button.
  3. Enter Server Details: In the dialog box, enter the IP address of your Siemens PLC in the “Endpoint URL” field. The port for OPC UA is typically 4840.
  4. Connect: Click “OK” to connect. If the connection is successful, you’ll see a green check mark next to your server.
  5. Browse and Monitor: You can now browse the PLC’s namespace and see the variables you exposed in TIA Portal. You can drag and drop these variables into the “Data Access View” to monitor their live values.

Step 3: Connecting with Node-RED to Save Data to Excel

Node-RED provides a flexible way to automate data collection and storage. This example will show you how to read data from the PLC and save it to an Excel file.

  1. Install Node-RED: If you haven’t already, install Node.js and then install Node-RED using the command prompt: npm install -g --unsafe-perm node-red
  2. Install Necessary Nodes: In the Node-RED flow editor, go to “Manage palette” and install the following nodes:
    • node-red-contrib-opcua: This is the OPC UA client node.
    • node-red-contrib-exceljs: or others – check video. This node allows you to work with Excel files.
  3. Build the Flow: Create the following flow in Node-RED:
    • Inject Node: Use an Inject node to trigger the data read at a specified interval. Set it to repeat every few seconds.
    • OPC UA Client Node: Add an OPC UA Client node.
      • Endpoint: Configure the endpoint URL with your PLC’s IP address and port (e.g., opc.tcp://<PLC_IP_Address>:4840).
      • Nodes to Read: Add the Node IDs of the variables you want to read from the PLC. You can find these IDs in the UA Expert client or TIA Portal.
    • Function Node: Connect a Function node to the OPC UA Client node. Use this node to format the incoming data into a suitable format for the Excel node. A simple script can create an object with the data values and timestamps.
    • Excel Node: Add an Excel node.
      • File Path: Specify the path where you want to save the Excel file (e.g., C:\data\data.csv).
    • Operation: Set the operation to “Append” to add new rows of data.
  4. Deploy: Click the “Deploy” button to run the flow.

Node-RED will now automatically read data from your Siemens PLC at the specified interval and append it as a new row in your Excel file.

By admin

Related Post

Leave a Reply