For the complete documentation index, see llms.txt. This page is also available as Markdown.

Connecting a Phoenix Contact PLCnext Controller

How to read data from a Phoenix Contact PLCnext controller through its built-in OPC UA server with the Connectware OPC UA connector and map it into an ISA-95 style MQTT topic hierarchy.

This guide shows you how to read data from a Phoenix Contact PLCnext controller, such as the AXC F 2152, with the Connectware OPC UA connector and map it into an ISA-95 style MQTT topic hierarchy. Every PLCnext controller ships with a built-in OPC UA server, so no additional hardware or gateway is required to make PLC variables available to Connectware. In more detail, the following topics are covered:

  • Understanding how the PLCnext OPC UA server exposes variables

  • Making variables OPC UA accessible in PLCnext Engineer

  • Understanding the PLCnext authentication and security defaults

  • Mapping the data into an ISA-95 style MQTT topic hierarchy

  • Verifying data in the Data Explorer

This guide focuses on the PLCnext specifics. For the general workflow of browsing an OPC UA address space and picking NodeIds, see Using Connectware as an OPC UA Client.

A complete example file is available at the end of this guide.

Prerequisites

To follow this guide, you will need the following:

  • A running instance of Cybus Connectware.

  • A Phoenix Contact PLCnext controller, for example an AXC F 2152, that is reachable over Ethernet from Connectware.

  • Phoenix Contact PLCnext Engineer and access to the PLC program of the controller. For the controller-side documentation, see the PLCnext Info Center.

  • The username and password of a user configured on the controller.

  • Access to the Admin UI with sufficient user permissions.

  • Basic knowledge of MQTT and the Connectware services concept (for example, service commissioning files, connections, and endpoints).

How the PLCnext OPC UA Server Exposes Variables

The PLCnext firmware includes an embedded OPC UA server, called the eUA server. It listens on the standard OPC UA port 4840, so the endpoint URL of the controller is opc.tcp://${PLCNEXT_HOST}:4840, where ${PLCNEXT_HOST} is the hostname or IP address of the controller.

The eUA server publishes the variables of the IEC 61131-3 program from the Global Data Space (GDS) of the controller in the namespace http://phoenixcontact.com/OpcUA/PLCnext/GlobalDataSpace/. Each variable is addressed by a string NodeId of the following form:

  • ${NAMESPACE_INDEX} is the index of the GDS namespace on your controller. The index is not fixed, so read it from the namespace array of the server or from an OPC UA browser as described in Using Connectware as an OPC UA Client.

  • ${PROGRAM_INSTANCE} is the name of the program instance in your PLCnext Engineer project.

  • ${VARIABLE_NAME} is the name of the variable. Nested paths such as function block instances and structure fields are appended with dots, for example Arp.Plc.Eclr/MainInstance.Drive1.ActualSpeed.

For security reasons, the variables of a PLCnext Engineer project are not visible to OPC UA clients by default. You mark the variables in PLCnext Engineer first, as described in Making Variables Accessible in PLCnext Engineer.

Making Variables Accessible in PLCnext Engineer

Configure the eUA server and mark the variables in your PLCnext Engineer project:

  1. Open the variable table of your program and select the OPC check box for each variable that Connectware should read.

  2. In the PLANT area, open the OPC UA node.

  3. In the Basic settings, set Visibility of variables to Marked. With this setting, all variables marked with the OPC check box become accessible through the eUA server. Alternatively, the All setting exposes every GDS variable without marking, which is convenient for testing but exposes more data than necessary.

  4. Write the project to the controller and restart the PLC program.

For details on these settings, see Basic OPC UA Settings in the PLCnext Engineer online help.

Authentication and Security Defaults

The PLCnext firmware enforces a secure configuration of the eUA server by default:

  • User authentication is required. OPC UA clients authenticate with the username and password of a user configured on the controller, for example through the Web-based Management (WBM) of the controller. Anonymous sessions are rejected by default.

  • Username and password authentication requires an encrypted endpoint. The eUA server does not accept username identity tokens on unencrypted endpoints, and the security policy None is disabled by default. The connection example in this guide therefore uses the message security mode SignAndEncrypt with the security policy Aes128_Sha256_RsaOaep, which the eUA server enables by default. The deprecated Basic128Rsa15, Basic256, and Basic256Sha256 policies are disabled by default in current firmware versions.

  • Client certificates are trusted as long as the trust store is empty. For an encrypted connection, the client presents a certificate. As long as the trust store of the eUA server is empty, the server trusts all clients. To restrict access to specific clients, add the Connectware client certificate to the trust store of the controller.

For details, see OPC UA Security Settings in the PLCnext Engineer online help.

Choosing the Variables

This guide reads a small set of variables that is typical for machine monitoring on a packaging line. The NodeIds are project-specific: replace the namespace index and the Arp.Plc.Eclr/${PROGRAM_INSTANCE}.${VARIABLE_NAME} paths with the values from your own PLCnext Engineer project.

Variable
Data type
NodeId (project-specific)
Sampling interval

ConveyorRunning

BOOL

ns=5;s=Arp.Plc.Eclr/MainInstance.ConveyorRunning

1000 ms

MotorSpeed

REAL

ns=5;s=Arp.Plc.Eclr/MainInstance.MotorSpeed

250 ms

MotorCurrent

REAL

ns=5;s=Arp.Plc.Eclr/MainInstance.MotorCurrent

250 ms

PieceCounter

UDINT

ns=5;s=Arp.Plc.Eclr/MainInstance.PieceCounter

1000 ms

OPC UA subscriptions are change-driven: the server samples each variable at the samplingInterval and only sends a notification when the value changes. Connectware combines all endpoints with the same publishInterval into one OPC UA subscription, so the example uses one common publish interval. For details, see Connectware Subscriptions and the OPC UA endpoint properties.

Writing the Service Commissioning File

The service commissioning file contains all connection and mapping details. Do not worry about copying the snippets together into one file, the complete example file is available at the end of this guide.

Description and Metadata

These sections contain general information about the service commissioning file. Only the metadata name is required.

Parameters and Definitions

We define the network address and the credentials of the controller as parameters, so you can set them when you install the service. The default OPC UA port is 4840.

The MQTT topics in this guide follow an ISA-95 style equipment hierarchy (<enterprise>/<site>/<area>/<line>/<work-cell>). We define the prefix once in the definitions section and reuse it in every mapping with !sub.

Cybus::Connection

The connection resource establishes the OPC UA session with the eUA server. The security options match the PLCnext defaults described in Authentication and Security Defaults: username and password authentication over an encrypted endpoint with the Aes128_Sha256_RsaOaep security policy. For all connection properties, including custom client certificates and the connectionStrategy retry behavior, see OPC UA Connection Properties.

Cybus::Endpoint

Each endpoint subscribes to one variable by its NodeId, according to the table in Choosing the Variables. Remember that the NodeIds are project-specific.

Cybus::Mapping

The mapping publishes each endpoint on a topic of the ISA-95 hierarchy.

With this mapping, the motor speed is published on the topic enterprise/hamburg/packaging/line-2/plc-01/motor/speed, and every other variable follows the same pattern.

Installing the Service Commissioning File

  1. Install the service commissioning file. See Installing Services.

  2. Enable the service. See Enabling Services.

Result: The service is enabled. Connectware opens an OPC UA session with the eUA server of the controller and subscribes to the configured variables.

Verifying the Data

Open the Data Explorer and subscribe to enterprise/hamburg/packaging/line-2/plc-01/#. Each topic carries a JSON object with the keys timestamp and value, where the timestamp is the OPC UA source timestamp set by the controller. For example, the motor speed:

Because OPC UA subscriptions are change-driven, a variable that never changes only publishes once after the subscription is established. Toggle a marked variable in the PLCnext Engineer debug mode to see an immediate update.

If the connection does not reach the Connected state, work through the following checks:

  • Verify that the controller is reachable from Connectware on port 4840.

  • Verify that the security options match the controller configuration. With the PLCnext defaults, a connection without messageSecurityMode and securityPolicy options is rejected because username and password authentication is only accepted on encrypted endpoints.

  • Verify the username and password. The credentials belong to a user on the controller, not to a PLCnext Engineer or Connectware user.

  • If the trust store of the eUA server is not empty, verify that it contains the Connectware client certificate.

If the connection is established but a topic stays empty, verify that the variable has the OPC check box selected, that Visibility of variables is set to Marked, and that the namespace index and the program instance name in the NodeId match your project.

Service Commissioning File Example

Disclaimer: PLCnext, PLCnext Engineer, and AXC F 2152 are trademarks or product designations of Phoenix Contact.

Last updated

Was this helpful?