Skip to content

OPC Router Tutorial Telegram

Following the seventh part of the OPC Router tutorial, I’m presenting how to interact with industrial automation systems via the Telegram messaging application. Remember, we’re configuring and running a project for “Papín”, a fictional potato bread factory.

Why an OPC Router tutorial with Telegram?

Because “learning by doing” with examples is fun. Also, this functionality can provide us with a modern use case: the versatility to receive process notifications to your smartphone directly via the Telegram bot, which is an excellent option when we want to add a messaging system from your production data environment to each of your client’s authorized users. See below a list of posts that complete this tutorial:

  1. Getting Started with OPC Router
  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 (this post)
  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

Considerations

From this point on, we must download and install OPC Router v4.27.5016.75 or later to make this feature work appropriately. Also, OPC Router Config was renamed to OPC Router Management.

Prerequisites

Firstly, you’ll need:

  • Telegram application 📧
  • FactoryTalk Linx Gateway as OPC DA server 🛤️
  • ControlLogix 1756-L61 as Programmable Automation Controller (PAC) 🤖
  • An Internet connection 🌐
  • Schematic diagram 📝
  • OPC Router Management application 💻

Schematic Diagram

To illustrate this idea better, look at this:

opc router tutorial telegram 36

What is Telegram?

opc router tutorial telegram 1

Telegram is a free, cloud-based instant messaging application available across a range of mobile and desktop platforms, including Android, iOS, Windows, macOS and Linux. Also, offers enhanced security and privacy thanks to various levels of encryption.

Working with a Telegram Bot

Creating our Telegram bot

  • Initially, run the Telegram application on your smartphone and search for the “@BotFather“: Then, make sure to select this bot.
opc router tutorial telegram 2
opc router tutorial telegram 3
  • Press the “START” button to begin the process.
opc router tutorial telegram 4
opc router tutorial telegram 5
  • Touch the “/newbot” command to create a new bot.
opc router tutorial telegram 6
opc router tutorial telegram 7
  • The name of the bot will be “PPN-PBF-19_Bot” and the username for the bot will be “PpnPbf19Bot“:
opc router tutorial telegram 8
opc router tutorial telegram 9
  • Moreover, confirm the creation of the new bot. Make sure to keep your token secure and store it safely.
opc router tutorial telegram 10

Preparing commands for your Telegram bot

  • At this instant, type “/setcommands” and choose the new bot “@PpnPbf19Bot“:
opc router tutorial telegram 11
opc router tutorial telegram 12
  • Then, type the initial available commands “help” and “start” with the following syntax:
command1 - Description of first command
command2 - Another description
opc router tutorial telegram 13
opc router tutorial telegram 14
  • Lastly, confirm success.
opc router tutorial telegram 15

Starting your new Telegram bot

  • At this point, search for “PPN-PBF-19_Bot” and press the “START” button:
opc router tutorial telegram 16
opc router tutorial telegram 17

Getting a list of available commands

  • Type “/“:
opc router tutorial telegram 18

Set your main data channel

  • Make sure to set OPC topic “P_PBF19_PA01” for 1756-L61 controller through Factory Talk Linx Gateway OPC DA interface.
opc router tutorial telegram 19
  • Monitor variable within “Controller Tags” tab:
opc router tutorial telegram 20

Working with OPC Router, OPC Classic and Telegram

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 tutorial telegram 21
opc router tutorial telegram 22
  • Make sure to notice OPC Classic and Telegram.

Knowing your Transfer Objects

  • At this point, we’re going to need seven (7) transfer objects to solve our use case:
opc router tutorial telegram 23
  • Specifically, make sure to notice OPC Data Access, Time trigger, Variables, Constant Values, Text Replace and Telegram.

Configuring your Plugins

  • Following identification, OPC Router needs to configure every licensed plugin. Let’s start creating a new plug-in instance with Telegram (double click on the object):
opc router tutorial telegram 24
opc router tutorial telegram 25
  • At this time, define a new Telegram bot for our system:
opc router tutorial telegram 26
  • Make sure you see the contextual dialog:
opc router tutorial telegram 27
  • Inspect the “BotFather” tab:
opc router tutorial telegram 28
  • Create a validation code within the “Authentication” tab:
opc router tutorial telegram 29
  • Watch the link for authentication:
opc router tutorial telegram 30
  • Download the plugin and run the service:
opc router tutorial telegram 31
opc router tutorial telegram 32
  • Go back to Telegram and make sure to run the command “/start” or press the “START” button:
opc router tutorial telegram 33
  • Go back to the “Authentication” tab:
opc router tutorial telegram 34
opc router tutorial telegram 35
  • Allow a registered user to the Telegram bot by clicking “Allow permission”:
  • Confirm authorization:
  • You can also authorize an user by entering a code manually (if you didn’t use the “Authentication” tab):

Checking your Plugins

  • Following identification, OPC Router needs to configure every licensed plugin. Let’s check the plug-in instance with OPC Classic (double click on the object):
  • At this point, check a local OPC Classic connection using a Factory Talk Linx Gateway OPC DA server, with an update rate of 6 seconds.

Creating your Sixth Template

  • In similar fashion to the sixth part of the tutorial, a template is the correct approach once again. Let’s create a new Telegram messaging template MSpd within TLGM folder (VSD motor speed):
  • Watch an empty design panel so you can start building your template:
  • Then, drag and drop these seven blocks as shown here:
  • Edit the Time trigger block and set a periodic transfer of 30 minutes:
  • Confirm the configured Time trigger block:
  • Edit the OPC Data Access block and add a template variable:
  • Confirm the configured OPC Data Access block:
  • Edit the first Constant Values block to have a template variable for the Telegram username that will receive messages:
  • Confirm the configured first Constant Values block:
  • Edit the second Constant Values block to have template variables for the symbol and unit of the variable, and the physical location:
  • Confirm the configured second Constant Values block:
  • Edit the Variables block and choose the global variable “SystemTime”:
  • Confirm the configured Variables block:
  • Edit the Text Replace block to start preparing the format of the message to send:
  • Start creating placeholders:
  • Also, verify placeholders:
  • Give the desired format to the message you want to send:
The value of {ds_symbol} at PLN0{cd_location3} is {qt_value} {ds_unit} | Date/Time: {dt_timestamp}.
  • Confirm the configured Text Replace block:
  • Edit the Telegram block to set the Telegram connection:
  • Confirm the configured Telegram block:
  • Finally, make sure to link blocks as shown here:
  • Additionally, create the connections folder “TLGM” within “PLN01”:

Working with Instances from Templates

  • With your sixth template, a new instance is required now. Start creating it by using the contextual menu:
  • At this time, check the new instance:
  • In the design panel, double click to verify values in template variables according to actual OPC item, Telegram username, physical location, symbol and unit:

Compile, Save and Publish your OPC Router Project Configuration with Telegram

  • 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.
  • After that, press the “Yes” button to start the OPC Router service and run your application.
  • Lastly, watch both the initial and operational connection states:

Visualize Online Data in OPC Router

  • Also, you can watch live values here:
  • At this point, you should notice an execution time visually (it’s 1179.32 milliseconds in this example):

Verify Message Transfer to Telegram

  • Watch an initial value to transfer (718.25 rpm):
  • Notice a first process notification from the Telegram bot:
  • Finally, watch messages received on my Android phone every 30 minutes:

Did you enjoy this OPC Router tutorial with Telegram? I’d love to hear from you.

Stay tuned and follow part 9 of this tutorial! 😎

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

Share this post