Skip to content

OPC Router Tutorial SMS

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

Why an OPC Router tutorial with SMS?

Because “learning by doing” with examples is fun. Also, this functionality can provide us with a modern use case: the versatility to receive alarms notifications to your phone directly via traditional SMS text messaging and Twilio, which is an excellent option when we want to add a classic messaging system from your production data environment to each of your client’s valid 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
  9. Build an SMS basic interaction within OPC Router (this post)
  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:

  • Twilio platform 🏗️
  • Messaging 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 sms 1

What is SMS?

opc router tutorial sms 2

SMS, which stands for Short Message Service, is commonly referred to as “text messaging”. It was introduced in the 1990s and is still used on most smartphones, the Internet, and mobile device systems today. The protocol allows us to send short messages of up to 160 characters.

What is Twilio?

opc router tutorial sms 3

Twilio is a cloud communication platform which provides programmable tools for making and receiving phone calls, sending and receiving text messages, and performing other communication functions using its web service APIs. You can build applications for customer support chat, alarms and events notifications, and tasks reminders, among others.

Working with Twilio

Creating a Twilio account

  • Firstly, let’s go here to start creating your free Twilio account and press the “Sign up and start building” button.
opc router tutorial sms 4
  • Then, enter the required information, accept the Twilio Terms of Service and press the “Start your free trial” button. Notice what you can build with this platform: SMS marketing, Omnichannel contact center, call tracking, web chat, push notifications, alerts and notifications, and phone verification.
opc router tutorial sms 5
  • Following this, begin the verification process with an on-screen puzzle.
opc router tutorial sms 6
opc router tutorial sms 7
  • Complete the verification process with an email.
opc router tutorial sms 8
opc router tutorial sms 9
  • Once the email is confirmed, verify your phone number now:
opc router tutorial sms 10
  • When the verification code is received in your phone, submit it to complete the process.
opc router tutorial sms 11
  • At this point, watch the “Welcome to Twilio” page.
opc router tutorial sms 12
  • Personalize your experience in any way you want and press the “Get Started with Twilio” button. For instance, you could make this selection:
opc router tutorial sms 13
  • If prompted, activate your test sandbox for WhatsApp.
opc router tutorial sms 14

Send an SMS test message with Twilio

  • Firstly, go to the Twilio Console:
opc router tutorial sms 15
  • Learn how to set up your test quickly by creating a “Messaging Service” and to provision a Twilio phone number.
opc router tutorial sms 16
  • Then, go to “Messaging ➡️ Services” and click the “Create Messaging Service” button:
opc router tutorial sms 17
opc router tutorial sms 18
opc router tutorial sms 19
  • At this instant, create a new “SMSNotifications1” messaging service:
opc router tutorial sms 20
  • Get a Twilio phone number:
opc router tutorial sms 21
  • At this point, start the process of sending an SMS notification:
opc router tutorial sms 22
opc router tutorial sms 23
  • Fill out the form and press the “Send test SMS” button:
opc router tutorial sms 24
  • Make sure to notice the message was sent:
opc router tutorial sms 25
  • Watch how the message is received on my Android phone:
opc router tutorial sms 26
opc router tutorial sms 27
  • Learn how to use some Python code from the Twilio server that creates and sends the message:
from twilio.rest import Client 
 
account_sid = 'ACa7db...7e6d' 
auth_token = '[AuthToken]' 
client = Client(account_sid, auth_token) 
 
message = client.messages.create(  
                              messaging_service_sid='MG24ae...b31c', 
                              body='This is an SMS notification with Twilio :-)',      
                              to='+584249999999' 
                          ) 
 
print(message.sid)
opc router tutorial sms 28
  • Also, watch the JSON response:
{
    "body": "This is an SMS notification with Twilio :-)",
    "num_segments": "0",
    "direction": "outbound-api",
    "from": null,
    "date_updated": "Fri, 07 Oct 2022 14:11:56 +0000",
    "price": null,
    "error_message": null,
    "uri": "/2010-04-01/Accounts/ACa7db...7e6d/Messages/SM0d1e08748a1442aaa46b7d9bc2cabc56.json",
    "account_sid": "ACa7db...7e6d",
    "num_media": "0",
    "to": "+584249999999",
    "date_created": "Fri, 07 Oct 2022 14:11:56 +0000",
    "status": "accepted",
    "sid": "SM0d1e...bc56",
    "date_sent": null,
    "messaging_service_sid": "MG24ae...b31c",
    "error_code": null,
    "price_unit": null,
    "api_version": "2010-04-01",
    "subresource_uris": {
        "media": "/2010-04-01/Accounts/ACa7db...7e6d/Messages/SM0d1e...bc56/Media.json"
    }
}
opc router tutorial sms 29

Check your main data channel

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

Working with OPC Router, OPC Classic and REST

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 sms 32
opc router tutorial sms 33
  • Make sure to notice OPC Classic and REST.

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, Threshold trigger, Variables, Constant Values, Text Replace and REST.

Configuring your Plugins

  • Following identification, OPC Router needs to configure every licensed plugin. Let’s start creating a new plug-in instance with REST (double click on the object) and the REST connections tab:
  • Make sure to copy both your Twilio “Account SID” and “Authentication Token”. Please save it to a secure location:
  • Store Twilio API URL by going to “Messaging”, and then, “Send an SMS”:
  • The API URL at the time of writing this post is:
https://api.twilio.com/2010-04-01/Accounts
  • At this time, define a new REST connection for our system:
  • Download the plugin and run the service:

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 Seventh Template

  • In similar fashion to the eighth part of the tutorial, a template is the correct approach once again. Let’s create a new SMS messaging template AirP within SMS folder (line air pressure):
  • Watch an empty design panel so you can start building your template:
  • Then, drag and drop these seven blocks as shown here:
  • 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 recipient mobile phone number that will receive text 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 text message you want to send:
Very low pressure of {ds_symbol} at PLN0{cd_location3}. Current value is {qt_value} {ds_unit} | Date/Time: {dt_timestamp}.
  • Confirm the configured Text Replace block:
  • Edit the Threshold trigger block to detect if a limit is exceeded, with a process value less or equal to 10 psi for AirP (very low line air pressure):
  • Confirm the configured Threshold trigger block:
  • Edit the REST block to set the Twilio SMS connection:
  • Make sure to choose this format for the request:
application/x-www-form-urlencoded
  • Also, add parameters “To”, “From” and “Body”:
  • Confirm the configured REST block:
  • Edit the first Constant Values block to include the Twilio phone number that route SMS messages:
  • Confirm again the configured first Constant Values block:
  • Finally, make sure to link blocks as shown here:
  • Additionally, create the connections folder “SMS” within “PLN01”:

Working with Instances from Templates

  • With your seventh 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, recipient phone number (check double quotes), physical location, symbol and unit:

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

  • 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 PAC

  • Make sure to notice normal AirP values by production line here:
  • Then, watch how the line air pressure (AirP) drops from 120 psi to 9 psi to trigger the alarm notification:

Visualize Online Data in OPC Router

  • Also, you can watch live values here:
  • At this point, you should notice an execution time visually:

Verify Message Transfer to SMS

  • Notice a first alarm notification on the Messaging application of my Android phone:
  • Finally, watch how the OPC Router tutorial allows us to send SMS messages to an Android phone every time an alarm for AirP is triggered:

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

Stay tuned and follow part 10 of this tutorial! 😎

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

Share this post