Skip to main content
Version: 3.0

Build a Pipeline: "Will the Tool Last?"

Build a six-node pipeline that reads OPC UA and REST data from the simulator, merges it in JavaScript and publishes a tool life check to the UNS.

Prerequisites
DFS running · .mhub.json imported
Protocols
OPC UA · REST
Trigger
Schedule, every 10 seconds
Output topic
mHv1.0/<workspace>/factory/LINE-BC-01/tool-check/OP20-CNC
Prerequisites

Before starting this guide, you must complete the steps in the Digital Factory Simulator page: install and run DFS, then import the .mhub.json file into MaestroHub so that all connections are available.

This guide walks you through building your first pipeline in MaestroHub. The goal is not the output itself; it is the process of connecting to different industrial protocols, reading live data, and combining them into a single result.

By the end of this guide, you will know how to:

  • Read OPC UA nodes from a CNC machine
  • Call a REST API on a manufacturing execution system
  • Merge data from both into a JavaScript node
  • Publish the result to the Unified Namespace

The pipeline answers a simple question: does the OP20 finish machining tool have enough life to complete the current work order?

What You Will Build​

Tool Life Check pipeline overviewTool Life Check pipeline overview

The completed Tool Life Check pipeline

The pipeline consists of 6 nodes across 2 protocols:

  1. Schedule Trigger: runs the pipeline every 10 seconds
  2. OPC-UA Read Group: reads tool life from OP20 (CNC)
  3. REST Request: reads the current work order from the MES API
  4. Merge: combines both branches into one object
  5. JavaScript: compares tool life against work order, makes a decision
  6. UNS Publish: publishes the result to a UNS topic

About the Production Line​

The Digital Factory Simulator models a 4-station brake caliper production line:

StationProtocolHas Tools?
OP10: CNC Rough MachiningModbus TCPYes (Face Mill, Rough Bore Bar)
OP20: CNC Finish MachiningOPC UAYes (Finish Bore Bar, M10 Tap)
OP30: Parts WasherModbus TCPNo
OP40: Leak TestOPC UANo

In this guide, you will read tool data from OP20 over OPC UA and work order data from the MES over REST. The tool life check targets OP20's Finish Bore Bar specifically: this is the tool with the shortest life limit (300 parts) on the line.

Step 1: Create the Pipeline​

Create a new pipeline and name it "Tool Life Check".

Step 2: Add the Schedule Trigger​

This is your first node. It starts the pipeline automatically at a fixed interval.

SettingValue
TypeSchedule Trigger
Interval10 seconds

What you are learning: Pipelines need a trigger to run. A schedule trigger is the simplest option; it runs the pipeline at regular intervals, like a clock.

Step 3: Add the OPC-UA Read Group​

This node reads data from OP20, the finish machining station. OP20 communicates over OPC UA, a modern industrial protocol used by CNC machines and advanced equipment. OPC UA organizes data as named nodes (like a file system).

SettingValue
Node nameOP20 Tools
ConnectionCaliperline-OP20-CNC

Add three functions to read:

Function NameDescription
ToolActNameName of the tool in the spindle
ToolActQuantityActualValueHow many more parts this tool can make
ToolActQuantitySetpointValueHow many parts the tool is rated for in total

Name the node OP20 Tools: the JavaScript in Step 6 reads the values by that name.

OPC-UA Read Group node configurationOPC-UA Read Group node configuration

OPC-UA Read Group reading tool life data from OP20

What you are learning: How to read values from a CNC machine over OPC UA. You select named functions that map to OPC UA node IDs; the connection handles the protocol details.

Step 4: Add the REST Request Node​

This node reads the current work order from the MES REST API. REST is an HTTP-based protocol used by business applications: MES, ERP, quality systems. Unlike OPC UA which talks directly to machines, REST talks to software systems.

SettingValue
Node nameCurrent Work Order
ConnectionCaliperline-MES-API
Functionproduction_orders_current
REST Request node configurationREST Request node configuration

REST Request reading the current work order from the MES API

What you are learning: How to call a REST API from a pipeline. This is the same kind of API call that web applications make, but here you are using it to get manufacturing data.

Step 5: Add the Merge Node​

Connect the outputs of the OPC-UA and REST nodes into a single Merge node. This combines both branches into one object so the JavaScript node can access everything.

After merging, each branch's result sits under the name of the node it came from:

  • OP20 Tools: the three OPC UA values from OP20
  • Current Work Order: the MES API response
Merge node configurationMerge node configuration

Merge node combining OPC UA and REST branches

What you are learning: When a pipeline has parallel branches (multiple reads happening at the same time), you need a Merge node to bring them back together before processing.

Step 6: Add the JavaScript Node​

This is where you combine data from both sources. The code is short; the important thing is understanding how the data flows in.

// The Merge node's result holds each branch's result under that node's name
const merged = $node["Merge"].result;

// OP20 CNC (OPC UA): the tool on the finish machining station
const tool = merged["OP20 Tools"];

// MES (REST): the current work order, parsed from the response body
const wo = merged["Current Work Order"].bodyJSON;

// Parts the tool can still make, and parts the order still needs
const toolLife = tool.ToolActQuantityActualValue.value;
const remaining = wo.target_qty - wo.produced_qty;

// The decision
const willLast = toolLife > remaining;

return {
station: "OP20-CNC",
tool: tool.ToolActName.value,
tool_life: toolLife + " / " + tool.ToolActQuantitySetpointValue.value,
order: wo.order_id,
order_remaining: remaining,
will_last: willLast,
action: willLast
? "No tool change needed"
: "CHANGE TOOL before part #" + (toolLife + 1)
};
JavaScript node configurationJavaScript node configuration

JavaScript node combining OPC UA and REST data

What you are learning:

  • Every node's output is { result, _metadata }: $node["Merge"].result is what the Merge node produced
  • Each branch is a key in that result, named after its node: OP20 Tools, Current Work Order
  • Every OPC UA value comes with its quality and timestamps ({ value, quality, success, timestamp, ... }): use .value to get the reading
  • A REST response carries its parsed JSON body in .bodyJSON

Step 7: Add the UNS Publish Node​

The final node publishes the result to the Unified Namespace so other systems, dashboards, or pipelines can consume it.

SettingValue
UNS Topicfactory/LINE-BC-01/tool-check/OP20-CNC
Value{{ $input[0].result }}

The topic field shows the version and your workspace in front of the path, so the full topic is mHv1.0/<workspace>/factory/LINE-BC-01/tool-check/OP20-CNC. The value is the JavaScript node's result: the whole object it returned.

UNS Publish node configurationUNS Publish node configuration

UNS Publish sending the result to a UNS topic

What you are learning: UNS Publish sends your pipeline's output to a topic that any subscriber can listen to. This is how pipelines share data with dashboards, alert systems, or other pipelines.

Step 8: Run the Pipeline​

Click Run (or wait for the schedule trigger). You should see output like this:

{
"station": "OP20-CNC",
"tool": "FINISH_BORE",
"tool_life": "74 / 300",
"order": "WO-2024-138",
"order_remaining": 5,
"will_last": true,
"action": "No tool change needed"
}

This tells you: the finish bore bar (FINISH_BORE) on station OP20-CNC can make 74 more parts. The current work order needs 5 more. The tool will last.

If the tool were running low:

{
"station": "OP20-CNC",
"tool": "FINISH_BORE",
"tool_life": "3 / 300",
"order": "WO-2024-138",
"order_remaining": 5,
"will_last": false,
"action": "CHANGE TOOL before part #4"
}

The tool can only make 3 more parts, but the work order needs 5. Change the tool before starting the 4th part.

You can also verify the published message by checking the UNS Topics page in MaestroHub:

UNS Topics showing published tool check resultUNS Topics showing published tool check result

Published tool check result visible in UNS Topics

What You Learned​

This pipeline was not about tool life; it was about learning the building blocks of MaestroHub pipelines:

StepWhat You Practiced
Schedule TriggerStarting a pipeline on a timer
OPC-UA Read GroupReading data from a CNC using node-based addressing
REST RequestCalling an HTTP API to get business data
MergeCombining parallel branches into a single data flow
JavaScriptAccessing and transforming data from multiple sources
UNS PublishPublishing results to the Unified Namespace

You now know the read, merge, transform, publish pattern. Every pipeline in MaestroHub follows this same structure, whether it calculates OEE, monitors energy, or predicts maintenance.

Next Steps​

Now that you know the building blocks, try these:

Add a Condition node after the JavaScript to only publish when will_last is false. This turns the pipeline from a periodic report into an alert that only fires when something needs attention.

Add a Modbus Read Group. OP10 communicates over Modbus TCP, a register-based protocol used by PLCs. Add a Modbus node to read OP10's tool data (Face Mill and Rough Bore Bar at registers 40030-40032) and extend the JavaScript to check tools across both stations.

Build an OEE pipeline. Use the same read, merge, transform, publish pattern, but read run time, down time, and part counts from each station to calculate Overall Equipment Effectiveness.