# How to Connect OPC UA Machine Data to Your ERP

> Source: https://netray.co/erp-help/mes-opc-ua-to-erp-integration-how-to
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: ERP Help

## Short answer

Do not connect OPC UA servers straight to the ERP. Read machine tags through an edge gateway or MES, convert signals into business events (cycle complete, stop, state change, count), attach the work order context, and post summarised confirmations to the ERP through its supported API. The ERP wants quantities, times and reasons per order, not millions of raw tag values.

## Kind

advanced

## System

mfg-systems

## Erp

Shop floor to ERP

## Module

OPC UA Integration

## Query

how to connect OPC UA machine data to ERP

## Alternate Queries

- OPC UA to ERP integration architecture
- PLC machine data to ERP production counts
- OPC UA subscription vs polling ERP
- send OPC UA data to MES and ERP securely

## Applies To

OPC UA (IEC 62541) servers on PLCs, CNCs and gateways, integrated with Infor, SAP, NetSuite, Dynamics, Epicor or other ERPs via an MES, edge platform or custom middleware

## Steps

### How to connect OPC UA to ERP

**Items:**

- Inventory machines and their OPC UA support: native server on the controller, a vendor gateway, or a protocol converter for legacy PLC protocols.
- Define the tags you need: machine state, cycle counter or part count, program or recipe, alarm and stop code, and the work order or job identifier if the machine knows it.
- Deploy an edge gateway or MES connector inside the plant network that acts as the OPC UA client and uses subscriptions with a sampling interval and deadband, not tight polling.
- Convert signals to events: state transitions become start/stop events, counter deltas become production counts, with timestamps taken at the source.
- Add business context by joining each event with the active work order, operation and operator from the MES or a dispatch table.
- Buffer events locally (store and forward) so a network or ERP outage does not lose data.
- Post summarised confirmations to the ERP through its supported API, following your production reporting design, with a message ID for idempotency.
- Secure the path: OPC UA security policy with certificates, network segmentation, and an outbound-only connection from the plant zone to the integration layer.

## Sections

### Why not wire OPC UA to the ERP directly

**Body:**

OPC UA exposes machine data at high frequency and fine granularity: states, counters and alarms changing many times per second. An ERP expects transactions with business meaning, such as a posted quantity against an operation. Streaming raw tags into ERP tables overwhelms it, mixes concerns, and usually breaks on upgrade. The layer in between exists to filter, contextualise and decide what is worth a transaction.

That layer may be an MES, a historian, an IIoT platform or a small custom service. The choice is less important than having it own timestamps, buffering and state logic, so the ERP only sees clean, deduplicated events.

### Subscriptions, sampling and counters

**Body:**

OPC UA clients create subscriptions with monitored items, each with a sampling interval, queue size and optional deadband. The server pushes changes, which is more efficient than polling and preserves the sequence of changes when the queue is sized properly. Choose intervals based on how fast the process changes, not the fastest the PLC can deliver.

Counters need care. A PLC counter may roll over, reset at power cycle or reset per program. Always compute production counts from deltas with rollover and reset detection, and cross-check against a cycle-complete signal where available. Persist the last seen value so a gateway restart does not create a spurious large delta.

### Context and mapping to ERP transactions

**Body:**

A machine does not know the ERP work order unless someone tells it. Typical patterns: an operator scans or selects the job at the terminal, the MES dispatches the order to the machine, or the program name maps to an item and operation. Without that context, counts cannot be posted to an order and remain only machine statistics.

Once context is attached, map events to ERP concepts: counts to good and scrap quantity, run and stop intervals to labor and machine time, stop codes to downtime reasons, and program changes to setup. Then follow the same posting rules as any other MES feed.

**Code:**

// Pseudocode: counter delta with rollover and reset handling
delta = current - last
if (delta < 0) {
  if (last > maxValue * 0.9) delta = (maxValue - last) + current;  // rollover
  else delta = current;                                            // reset
}
publishCount(workOrder, operation, delta, timestampUtc, messageId);

### Security and air-gapped plants

**Body:**

Use OPC UA security: a security policy with signing and encryption, certificate trust lists managed deliberately, and user authentication on the server. Place the gateway in an industrial DMZ or a segmented zone, and prefer outbound connections initiated from the plant to the integration layer so you do not open inbound ports into the control network.

In defense and aerospace environments that are fully air-gapped, the integration layer, MES and ERP may all run on-prem, with data moved across any boundary by approved mechanisms. The same architecture applies, with local buffering and no cloud dependency.

## Pitfalls

- Posting raw tag changes to the ERP instead of summarised business events.
- Polling too aggressively, loading PLCs and the network for no analytical gain.
- Ignoring counter rollover and reset, producing impossible production quantities.
- No store and forward buffer, so outages create data gaps.
- Attaching no work order context, leaving counts unpostable.
- Leaving OPC UA security set to None for convenience.

## Ai Angle

Machine data is only useful if someone can ask about it in business terms. A private assistant grounded in your ERP and MES data, such as ERPray or DataRay on-prem, can answer questions like which orders ran with unexplained stops last week, with the query shown and ERP roles respected. It does not connect to PLCs and cannot control machines; it works on the summarised data your integration layer already stored.

## Faq

### Does the ERP need an OPC UA client?

**Answer:** Generally no. Most ERPs are not designed to consume OPC UA directly. An edge gateway, MES or IIoT platform acts as the OPC UA client and sends business events to the ERP through its web service or API. This keeps the ERP stable and the machine logic outside it.

### OPC UA or MQTT for shop floor data?

**Answer:** They solve different problems. OPC UA provides a rich information model and secure client-server access to machines; MQTT is a lightweight publish-subscribe transport often used to move data north. Many architectures use OPC UA at the machine and MQTT or a message queue between the plant and the integration layer.

### How do I get machine counts to match ERP quantities?

**Answer:** Use cycle-complete signals and counter deltas with rollover handling, attach the active work order, and reconcile machine counts against the operator-reported good and scrap quantities. Differences usually trace to parts-per-cycle, rework, or counts during setup and first-article runs.

### Can legacy machines without OPC UA be integrated?

**Answer:** Often yes, through a gateway that speaks the controller's native protocol and exposes OPC UA, or by adding sensors and I/O for counts and state. The effort rises for old controllers, so confirm which signals you truly need before investing.

## Search terms

OPC UA ERP integration, OPC UA to ERP, PLC data to ERP, machine data to MES, OPC UA subscription sampling interval, OPC UA counter rollover, edge gateway manufacturing, shop floor data to ERP, OPC UA security policy, industrial IoT ERP integration

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
