Skip to content

OPC Router Tutorial

opc router 4

Welcome! Want to learn how to build real-world applications that collect, exchange and set information between OPC servers, IoT devices, MES, ERP systems and databases using OPC Router with a tutorial? Here, you’ll do just that, configuring and running a project for “Papín”, a fictional potato bread factory.

papín potato bread

What is OPC Router?

According to inray’s product documentation:

OPC Router is a software router for data routing between OPC Servers (and therefore any PLCs) and databases (and therefore almost any MES, ERP or other business administration software). Other plug-ins connect SAP systems and mail servers, print labels, update Excel files (or create them), communicate with web services or process individual scripts for customized connections.

OPC Router 4.25 User Guide

Why an OPC Router tutorial?

Because “learning by doing” with examples is fun. See below a list of posts that complete this tutorial:

  1. Getting Started with OPC Router (this post)
  2. Connect an OPC DA server to Microsoft SQL Server
  3. Connect an MQTT data source to InfluxDB Cloud
  4. Perform multiple calculations within OPC Router
  5. Run an OPC Router application with Linux and Docker
  6. Build a process data simulator with Python, CSV and OPC Router
  7. Explore basic RESTful web services within OPC Router
  8. Build a Telegram basic interaction within OPC Router
  9. Build an SMS basic interaction within OPC Router
  10. Build a WhatsApp basic interaction within OPC Router
  11. Build a Teams basic interaction within OPC Router
  12. Explore advanced RESTful web services within OPC Router
  13. Run an OPC Router application with Portainer

Introduction

Initially, the features we’re trying to achieve with the OPC Router v4.26 tutorial are:

  • OPC Classic connection from a ControlLogix PAC using a Factory Talk Linx Gateway OPC DA server.
  • Apache Kafka data stream processing.
  • Microsoft SQL Server database storage.

The factory that produces “Papín” potato bread has three (3) facilities as process areas (“P-PBF19-PA01”, “P-PBF19-PA02” and “P-PBF19-PA03”) and six (6) production lines each (PLN0xxx). Also, one (1) process area data gateway is in charge of collecting variables from production lines and global process area.

In short, check this legend for better reference:

  • First, run OPC Router Config to configure your PPN_PBF_19 project.
  • Wait for the OPC Router 4 GUI to load.
opc router 4
  • Then, you should see something like this in the Start tab:

Getting Started with OPC Router

Knowing your Plugins

  • To begin with, the configuration of OPC Router starts with your licensed plugins. There are several categories such as “Cloud / IoT”, “Topfloor”, “Shopfloor”, “Storage”, “Advanced”, “Messaging” and “Printer”.
opc router plugins 1
opc router plugins 2
  • For instance, make sure to notice Apache Kafka, OPC Classic and MS SQL.

Configuring your Plugins

  • Following identification, OPC Router needs to configure every licensed plugin. Let’s start creating a new plug in instance with OPC Classic (double click on object):
opc router plugins 3
opc router plugins 4
  • At this point, define a local OPC Classic connection using a Factory Talk Linx Gateway OPC DA server, with an update rate of 6 seconds.
opc router plugins 5
  • After that, let’s start creating a new plug in instance with MS SQL:
opc router plugins 6
opc router plugins 7
  • Then, define a local Microsoft SQL Server database storage and press the “Check connection” button to test connectivity.
opc router plugins 8
opc router plugins 9
  • Finally, let’s start creating a new plug in instance with Apache Kafka:
opc router plugins 10
opc router plugins 11
  • Define a remote Apache Kafka broker and press the “Check connection” button to test connectivity.
opc router plugins 12
opc router plugins 13

Working with Folders, Templates, and Connections

  • Use folders to arrange your project better. For example, name T_PPN_PBF_19 to your main templates folder. Additionally, name PPN_PBF_19 to your main connections folder (enable a context menu with a right-click).
opc router plugins 14
opc router plugins 15
opc router plugins 16
opc router plugins 17
  • In addition, create template subfolders “AK” and “IDB” for your Apache Kafka and INSERT database operations, and connections subfolders “PLN01”, “AK” and “IDB”.
opc router plugins 18
opc router plugins 19

Creating your First Template

  • Given that our use case prompts to multiple connections with the same structure, a template is the right approach to this problem. Initially, let’s create a new Apache Kafka template MCurr (VSD motor current):
opc router template 1
opc router template 2
  • Observe an empty design panel so you can start building your template:
opc router template 3
  • First of all, insert a “Time trigger” block (drag and drop):
opc router template 4
opc router template 5
  • Set a periodic transfer of 6 seconds (double click on block):
opc router template 6
  • Secondly, you need to use some variables:
opc router template 7
opc router template 8
  • Thirdly, you will use some constant values:
opc router template 9
opc router template 10
  • Also, you need to configure an OPC data access:
  • Then, you must add a “JSON Write” block:
  • Later, you must enter a new NULL constant value:
  • Insert the Apache Kafka block:
  • At this point, you must include the system time as a variable:
  • To see global and local variables, go to “Plug-ins” and then, select “Variables”:
  • Next, create the following “location” global variables:
  • Also, create the code that identifies the MCurr variable:
  • Additionally, you must add some template variables. Firstly, for OPC Data Access:
  • Add a path to the OPC item:
  • Configure some global variables:
  • Secondly, you must add a template variable as constant value for final location:
  • Following this, configure the “JSON Write” block:
  • Make sure to link blocks as shown here:
  • Configure your Apache Kafka transfer object:
  • Link it to the JSON Write transfer object and the NULL constant value:
  • Your first completed template is shown here:

Working with Instances from Templates

  • With your first template, an instance is required now. Start creating it using the contextual menu:
  • Check the new instance:
  • In the design panel, double click to update values in template variables according to actual OPC item and location:
  • Make sure to create folder PLN01 within P_PBF19_PA01 for MCurr:

Compile, Save and Publish your OPC Router Project Configuration

  • At this time, you need to compile, save and publish the connection you just created by clicking the “Go productive” button:
  • Meanwhile, the project is saved and published.
  • Press the “Yes” button to start the OPC Router service and run your application.

Check Compiled Connection State

  • Finally, you should check the state of your compiled connection by pressing the “State” button:
  • You should notice an execution time visually (it’s 0.54 milliseconds in this example):

Visualize Online Values

  • Also, you can watch live values here:

Verify Data Transfer to Apache Kafka

  • Additionally, you can verify data transfer within the Apache Kafka container by running:

Control OPC Router service

  • You are able to start, stop or restart the OPC Router service, when needed.

Stay tuned and follow part 2 of this tutorial! 😎

For other articles like this one in English, click here. To see them in Spanish, click here.

Share this post

2 thoughts on “OPC Router Tutorial”

    1. José Alberto Maita

      Muchas gracias a tí por tus palabras. Espero que te haya gustado, aunque se ha demostrado que su lectura puede causar somnolencia 😆

Comments are closed.