Benefits of Connecting a PLC to the Internet
Programmable logic controllers (PLCs) are now gaining information technology (IT) abilities to interact directly with the internet, creating new automation and information possibilities.
Bill Dehner, a Technical Marketing Manager at AutomationDirect, authored an article for the July 2019 issue of Control Engineering titled Benefits of Connecting a PLC to the Internet. Here’s a summary, click on the link above for the full text.
PLCs have traditionally excelled at using wired inputs and outputs (I/O) to execute automation logic quickly and reliably. Now, users are recognizing the internet contains a wealth of information useful for PLC applications either directly in the logic or for operator displays. Many websites can programmatically deliver information such as weather forecasts, sunset/sunrise times or even commodity prices. With the right software tools built-in, modern PLCs can access this information.
Web Browser Basics
When users type a web address into a browser address bar, they are entering what is called a uniform resource locator (URL) which points to a specific domain and webpage. Accessing the internet requires a capability called hypertext transfer protocol (HTTP), which formats information as lightweight text files. Entering a URL generates an HTTP request to a web server, which responds with a lightweight HTTP response to populate the browser display.
Working with JSON Files
JSON responses are received as a compact ASCII string, which is not very human-readable. Reorganizing the content with a compatible text editor reveals the layered and nested structure of information objects in a JSON file.
Bill recommends users gather a few helpful tools before embarking on a project to link a PLC with a website:
One is the open-source Wireshark, which will expose the HTTP request and response packets. Another is a text editor to facilitate viewing JSON responses. Any text editor will do, but there are many free editors that make the job much easier by providing enhanced displays of JSON formatted content.
Every PLC is different, but for this article Bill looks at the special instructions provided with AutomationDirect BRX PLCs and Do-more Designer software. The first is a HTTPCMD block for requesting information from a target API server, while the second is a JSONPARSE block used to drill into object layers within a JSON payload.
This HTTPCMD block in an AutomationDirect BRX PLC enables the PLC to initiate a request to an internet website API to obtain data.
This JSONPARSE block in an AutomationDirect BRX PLC is needed so the PLC can extract the desired information from within the JSON payload.
With these basic understandings, Bill moves on to a practical example.
Checking the Temperature via the Internet
Bill works through some details of how to obtain the current local temperature from a website like AccuWeather using HTTPCMD and JSONPARSE commands. He first describes how to register and obtain a private user API key, and then discusses the programming to make it happen.
In actual runtime, the PLC will be configured to issue HTTP commands with the proper request strings. As each response is received, the PLC needs to place the data in string variables and then issue successive JSON parse instructions to drill down to the desired data.
The AccuWeather API offers options to request information based on major city, latitude/longitude or ZIP code. For this example, Bill uses the ZIP code approach, a two-step process. First the user must use a “get” method of “postal code search” to obtain a location “key”, and they can then use that key with a “get” method of “current conditions”. Finally, they can parse the JSON results to get the temperature.
Playing it Safe
Users must always take steps to ensure network security is preserved any time an industrial device connects to the internet. For this simple example, the end user might be better served by installing a local temperature transmitter. However, the internet offers plenty of useful information which can’t be instrumented locally, such as commodity prices. With a little thought and some programming effort, users can take advantage of PLC-based HTTP and JSON instructions to add a new level of functionality to applications.