Skip to content

OPC Router Tutorial WhatsApp

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

Why an OPC Router tutorial with WhatsApp?

Because “learning by doing” with examples is fun. Also, this functionality can provide us with a modern use case: the versatility to receive events notifications to your smartphone directly via the WhatsApp application and Twilio, which is an excellent option when we want to add a popular 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
  9. Build an SMS basic interaction within OPC Router
  10. Build a WhatsApp basic interaction within OPC Router (this post)
  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 🏗️
  • WhatsApp 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 whatsapp 1

What is WhatsApp?

opc router tutorial whatsapp 2

WhatsApp Messenger, or simply WhatsApp, is an internationally available messaging application that let users send messages, make video or voice calls, share images, documents, user locations, and other content. It’s a service owned by American company Meta Platforms (formerly Facebook).

What is Twilio?

opc router tutorial whatsapp 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

  • Initially, make sure to follow the procedure described here.

Send a WhatsApp test message with Twilio

  • Firstly, go to the Twilio Console:
opc router tutorial whatsapp 4
  • Then, go to “Messaging ➡️ Try it out ➡️ Send a WhatsApp message” to start the process of sending a WhatsApp notification:
opc router tutorial whatsapp 5
  • Learn how to set up your test quickly by creating a test sandbox and to provision a Twilio phone number.
opc router tutorial whatsapp 6
  • At this point, save the Twilio Sandbox phone number on your phone:
opc router tutorial whatsapp 7
  • Notice how this looks on WhatsApp:
opc router tutorial whatsapp 8
  • At first, send temporal “join quietly-coal” message to the Twilio phone number:
opc router tutorial whatsapp 9
  • Watch the successful response:
opc router tutorial whatsapp 10
  • Watch how the message is also received on the Twilio web interface:
opc router tutorial whatsapp 11
  • Then, go to the “Send a One-Way WhatsApp Message” next step and click “Order Notifications” template tab:
opc router tutorial whatsapp 12
  • Enter the recipient WhatsApp phone number and the body of your message. Then, press the “Make Request” button to proceed:
opc router tutorial whatsapp 13
  • Watch how the message is received on my Android phone:
opc router tutorial whatsapp 14
opc router tutorial whatsapp 15
  • 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( 
                              from_='whatsapp:+14155238886',  
                              body='This is a WhatsApp notification with Twilio :-)',      
                              to='whatsapp:+584249999999' 
                          ) 
 
print(message.sid)
opc router tutorial whatsapp 16
  • Also, watch the JSON response:
{
    "body": "This is a WhatsApp notification with Twilio :-)",
    "num_segments": "1",
    "direction": "outbound-api",
    "from": "whatsapp:+14155238886",
    "date_updated": "Thu, 10 Nov 2022 19:37:03 +0000",
    "price": null,
    "error_message": null,
    "uri": "/2010-04-01/Accounts/ACa7db...7e6d/Messages/SMd754...77be.json",
    "account_sid": "ACa7db...7e6d",
    "num_media": "0",
    "to": "whatsapp:+584249999999",
    "date_created": "Thu, 10 Nov 2022 19:37:03 +0000",
    "status": "queued",
    "sid": "SMd754...77be",
    "date_sent": null,
    "messaging_service_sid": null,
    "error_code": null,
    "price_unit": null,
    "api_version": "2010-04-01",
    "subresource_uris": {
        "media": "/2010-04-01/Accounts/ACa7db...7e6d/Messages/SMd754...77be/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.
opc router tutorial whatsapp 17
  • Monitor variable within “Controller Tags” tab:
opc router tutorial whatsapp 18

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 whatsapp 19
opc router tutorial whatsapp 20
  • 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:
opc router tutorial whatsapp 21
  • Specifically, make sure to notice OPC Data Access, Data Change 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:
opc router tutorial whatsapp 22
opc router tutorial whatsapp 23
  • Make sure to copy both your Twilio “Account SID” and “Authentication Token”. Please save it to a secure location:
opc router tutorial whatsapp 24
  • Store Twilio API URL by going to “Messaging”, and then, “Send a WhatsApp message”:
opc router tutorial whatsapp 25
opc router tutorial whatsapp 26
  • 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:
opc router tutorial whatsapp 27
  • Download the plugin and run the service:
opc router tutorial whatsapp 28
opc router tutorial whatsapp 29

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):
opc router tutorial whatsapp 30
  • 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 Eighth Template

  • In similar fashion to the ninth part of the tutorial, a template is the correct approach once again. Let’s create a new WhatsApp messaging template MSpdSp within WA folder (VSD motor speed setpoint):
  • 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 WhatsApp 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 WhatsApp message you want to send:
{ds_symbol} at PLN0{cd_location3} changed to {qt_value} {ds_unit} | Date/Time: {dt_timestamp}.
  • Confirm the configured Text Replace block:
  • Edit the Data Change trigger block to detect any value change for MSpdSp (VSD motor speed setpoint):
  • Confirm the configured Data Change trigger block:
  • Edit the REST block to set the Twilio WhatsApp 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 WhatsApp messages, along with the text prefix “whatsapp:“:
  • Confirm again the configured first Constant Values block:
  • Finally, make sure to link blocks as shown here:
  • Additionally, create the connections folder “WA” within “PLN01”:

Working with Instances from Templates

  • With your eighth 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 (add prefix “whatsapp:“), physical location, symbol and unit:

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

  • 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 MSpdSp values by production line here:
  • Then, watch how the VSD motor speed setpoint (MSpdSp) changes three times: 520 rpm, 750 rpm and 50 rpm. Each time, a data change trigger the event 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 WhatsApp

  • Notice a first event notification on the WhatsApp application of my Android phone:
  • Finally, watch how the OPC Router tutorial allows us to send WhatsApp messages to a smartphone every time a data change for MSpdSp is triggered:

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

Stay tuned and follow part 11 of this tutorial! 😎

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

Share this post