Page 21 - AutomationNotebook-Issue43-flip
P. 21

Cover Story continued
PLCs can interact with the internet in a similar manner, but with a few key differences.
APIs in Action
While many websites offer all sorts of API definitions, the PLC com- munity is probably most interested in those websites offering hard data useful for automated machines, equipment, and systems. To obtain this type of information, a PLC needs outbound internet access so it can connect to the desired websites.
Figure 2: This color-highlighted JSON sample shows the layered nature of information, which contains human-readable data ready for parsing by software.
Research performed on the internet by search- ing for “website APIs” and similar terms will identify various websites and the APIs they offer. Some APIs offer free access, or at least a limited number of free connections per day. Other websites, often with more valuable information, may require registration and charge a usage or subscription fee.
Programmers should have a few software tools available as they begin their first project to connect a PLC with an internet website, including the open- source Wireshark packet monitoring software and a JSON-aware text editor.
Unpacking JSON
HTTP requests to website APIs will return responses in JSON format, which is not easily human-readable in raw format (Figure 1). However, JSON has a well-defined system of layers and
nesting, and those information objects are readily viewed with a compatible text editor (Figure 2).
The information a user would want is often nested several layers deep within the JSON file, which must be progressively parsed so it can be retrieved. In the Figure 2 example, the temperature of 44 degrees Fahrenheit resides in Layer 3, underneath Layer 2 “Imperial” and
Layer 1 “Temperature”.
AutomationDirect BRX PLCs incorporate four key features to make communication with internet websites possible:
• An Ethernet port configured on the plant network, with proper privileges allowing the PLC to connect to the internet
• The ability to be configured as a trans- mission control protocol (TCP) client, so the PLC can open a logical channel to initiate HTTP instructions
• An HTTP command instruction, so request strings can be sent to the API of a target URL
• A JSON parsing instruction, so that the response data payload can be processed
For AutomationDirect, the specific program instructions are HTTPCMD and JSONPARSE. Following is an application example demonstrating the
necessary steps.
Go to Article
Editor's Note
New Product Focus
- Headless C-more Remote HMI without attached display
- Continuous Flexing Profinet Cable
- ProductivityOpen Arduino-compatible Controller
- Hammond Industrial Enclosures
Tech Thread
Productivity®Open - Maker In, Industrial Out
Business Notes
Cover Story
Does Your PLC Talk JSON?
What's New
User Solutions
Roller Coaster Overhaul
Student Spotlight
Industrial Automation with a Mission
Break Room
Brain Teasers
Figure 1: A typical JSON data payload requires some parsing to extract the desired data.
Cover Story www.automationnotebook.com | Issue 43
continued >>


































































































   19   20   21   22   23