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:
- 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
- Build an SMS basic interaction within OPC Router (this post)
- 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:
- 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:
What is SMS?
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?
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.
- 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.
- Following this, begin the verification process with an on-screen puzzle.
- Complete the verification process with an email.
- Once the email is confirmed, verify your phone number now:
- When the verification code is received in your phone, submit it to complete the process.
- At this point, watch the “Welcome to Twilio” page.
- Personalize your experience in any way you want and press the “Get Started with Twilio” button. For instance, you could make this selection:
- If prompted, activate your test sandbox for WhatsApp.
Send an SMS test message with Twilio
- Firstly, go to the Twilio Console:
- Learn how to set up your test quickly by creating a “Messaging Service” and to provision a Twilio phone number.
- Then, go to “Messaging ➡️ Services” and click the “Create Messaging Service” button:
- At this instant, create a new “SMSNotifications1” messaging service:
- Get a Twilio phone number:
- At this point, start the process of sending an SMS notification:
- Fill out the form and press the “Send test SMS” button:
- Make sure to notice the message was sent:
- Watch how the message is received on my Android phone:
- 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)
- 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"
}
}
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.
- Monitor variable within “Controller Tags” tab:
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”.
- 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.