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:
- Getting Started with OPC Router
- Connect an OPC DA server to Microsoft SQL Server
- Connect an MQTT data source to InfluxDB Cloud
- Perform multiple calculations within OPC Router
- Run an OPC Router application with Linux and Docker
- Build a process data simulator with Python, CSV and OPC Router
- Explore basic RESTful web services within OPC Router
- Build a Telegram basic interaction within OPC Router (this post)
- Build an SMS basic interaction within OPC Router
- Build a WhatsApp basic interaction within OPC Router
- Build a Teams basic interaction within OPC Router
- Explore advanced RESTful web services within OPC Router
- 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:
What is Telegram?
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.
- Press the “START” button to begin the process.
- Touch the “/newbot” command to create a new bot.
- The name of the bot will be “PPN-PBF-19_Bot” and the username for the bot will be “PpnPbf19Bot“:
- Moreover, confirm the creation of the new bot. Make sure to keep your token secure and store it safely.
Preparing commands for your Telegram bot
- At this instant, type “/setcommands” and choose the new bot “@PpnPbf19Bot“:
- Then, type the initial available commands “help” and “start” with the following syntax:
command1 - Description of first command
command2 - Another description
- Lastly, confirm success.
Starting your new Telegram bot
- At this point, search for “PPN-PBF-19_Bot” and press the “START” button:
Getting a list of available commands
- Type “/“:
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.
- Monitor variable within “Controller Tags” tab:
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”.
- 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:
- 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):
- At this time, define a new Telegram bot for our system:
- Make sure you see the contextual dialog:
- Inspect the “BotFather” tab:
- Create a validation code within the “Authentication” tab:
- Watch the link for authentication:
- Download the plugin and run the service:
- Go back to Telegram and make sure to run the command “/start” or press the “START” button:
- Go back to the “Authentication” tab:
- 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.