Connecting an industrial equipment to a cloud platform offers endless possibilities of data processing and integrations. This tutorial aims to connect an Allen-Bradley PLC to cloud. We’ll do it on a legacy PLC which has OPC-DA protocol. We need to pull and push data from OPC-DA to MQTT to be able to benefit cloud resources on an industrial equipment. Let’s see.

This blog post is produced from my senior design project; called “Application-Independent Industry 4.0 Based Connected Smart Platform” To read more about it; have a look at Industry 4.0 Platform page.

Here is the steps to connect an existing industrial system to the cloud using OPC-DA to MQTT software gateway.

  1. Create the project. Basically, the project contains several PLC tags. One BOOL output which connected to a timer OUTPUT, and one more BOOL output which connected to a BOOL Input. These PLC tags will be monitored on cloud and their values will be changeable on cloud. Thus, two way communication between cloud and PLC will be achieved.

  2. Configure OPC Topic. After this configuration, PLC tags can be monitored/set over OPC-DA protocol.

  3. Configure OPC-MQTT Gateway. A python program is developed to transfer OPC data to MQTT in either way. Configuration of this gateway software makes connecting PLC to cloud is possible.

  4. Create the MQTT connected dashboard. If all of these steps done, PLC data can be set and monitored over internet, using the dashboard which developed to connect to the platform.

Before starting, have a look at the resources we’ll need. This tutorial is produced from APPPENDIX A. of the paper, so please find resources in appanedix-a folder of the repo; https://github.com/eercanayar/industry-4.0-platform

Create the project

Download the sample project from resources and download it to an Allen-Bradley PLC.

A project which seen at the figure below has to be run. Then OUTPUT2 tag can set via INPUT tag, also can monitor how OUTPUT1 is changing with the timer.

PLC project

Configure OPC Topic

This step makes monitoring and setting PLC tags over OPC-DA protocol are possible.

After opening the RSLinx Classic Professional and select DDE/OPC -> Topic Configuration a screen as seen on the figure below has to seen.

OPC topic configuration

RSLogix project from left has to chosen and assign the PLC’s IP address from the list on right side as shown on the figure below.

Assigning OPC topic to IP address

OPC configuration is done with this step. It can connect to this OPC topic from any client in local network. Python gateway will be discussed in the next section.

Configure OPC-MQTT Gateway

OPC-MQTT gateway is a Python program to transfer OPC data to MQTT in either way. First, python2.7 should be installed on the computer which is connected to the PLC and also public internet. In the project, a computer has 2 ethernet ports is used, one is connected to PLC, and one to local network.

There are two requirements to run this gateway;

  1. OpenOPC: This library makes OPC data is accessible in python programs. Download from here: https://sourceforge.net/projects/openopc/files/
  2. paho-mqtt: This library makes connecting to MQTT servers in python programs is possible. Installation here: https://pypi.python.org/pypi/paho-mqtt

Download the python gateway from resources. After environment is ready, run it from a command window by typing the name of the program, it’ll start to transfer between OPC and MQTT protocols as seen at figure below.

OPC-MQTT gateway runtime

Create the MQTT connected dashboard

Download the mqtt.html dashboard and run it from any browser; recommended Chrome. Now it can be done when accomplish to monitor OUTPUT1 and change OUTPUT2 by setting INPUT as seen on the figure below.

Platform demo dashboard

Finally, it has achieved successfully that connecting industrial devices to cloud over MQTT.

This blog post is produced from my senior design project; called “Application-Independent Industry 4.0 Based Connected Smart Platform” To read more about it; have a look at Industry 4.0 Platform page.