Connecting PLCs to AWS IoT Core
This tutorial show you how to connect PLCs and other devices as a Thing to AWS IoT Core
Table of Contents
Video tutorialApplying the AWS Things SSL certificatesAdding the Thing's endpoint as InstanceConfiguring topics as ItemsDefining message formats for the topicsMapping data from the PLCs to AWS IoT CoreThis article will guide you through how to publish and subscribe data between various PLCs, sensors and protocols and to AWS IoT Core. You will find a video that shows all the steps and procedure as well as written details describing the steps on how to install AWS IoT Core certificate, adding the endpoint and topics, how you are tailoring and customizing the published payload from the PLCs and respective protocols.
To connect data from PLCs to AWS IoT Core, the MQTT connector is required to be installed on SIA Connect as IoT Core is based on MQTT. If it is not already installed, you can follow this link for a guide on how to do so.
For a complete list of all supported devices and protocols check Supported Industrial & Buildings devices article.
This guide will take you through the following steps:
- Installing the Thing SSL certificate from IoT Core on SIA Connect
- Creating the Thing as Instance
- Adding topics for subscribing and publishing to the Thing
Video tutorial
This video shows how to connect PLCs to AWS IoT Core. For further details read the remanding guide.
Applying the AWS Things SSL certificates
In the previous step where a Thing was created in IoT Core, you were presented to the SSL certificates for the Thing.
These are the certificates used by SIA Connect to establish a secure & trusted connection to the Thing in AWS IoT Core.
You will need a private key, public key and Root CA certificate for the IoT Core as listed below (naming most likely differ):
The certificates need to be uploaded to SIA Connect in the MQTT connector in order for the connector to work properly.
- Go to Connectors
- Locate the MQTT Connector and press Upload new file
- A popup will open where you can upload a file.
- Do this procedure for Root CA certificate, Private key and Device certificate
After this is done the Connector files will look something like the following:
When the certificates are uploaded they can then be used when creating a new instance for the Thing in AWS IoT Core.
Adding the Thing's endpoint as Instance
In order to add a connection from SIA Connect to the Thing in AWS IoT Core you will need to add a Instance pointing to the Thing's endpoint. To add a instance refer you can follow this guide showing how to add a instance.
The table below shows how to fill out the fields on the instance
Parameter | Description |
---|---|
Address |
a2b2rqf1kr1flp-ats.iot.eu-west-1.amazonaws.com The address in this case refers to the endpoint, which can be found by following the previous step |
Port |
8883 The port for your MQTT connection |
Username |
Not used in this example Broker username |
Password |
Not used in this example Broker password |
Device ID |
Auto-generated by SIA Connect The Device Id (or ClientId) to use when connecting to a Broker and be identified as such. Leave empty to auto-generate one or insert your own if desired. |
Ssl Version |
TLS 1.2 The SSL version used by the broker |
Certificate |
device.pem.crt Device certificate obtained from IoT Core uploaded in previous step |
Key |
private.pem.key Private key uploaded in previous step |
Server Certificate |
Amazon-root-CA-1.pem Root Ca Certificate uploaded in previous step |
Verify Server Ca |
Yes This is an extra layer of security required to connect to the AWS IoT Core |
When the IoT Core endpoint is added as a Instance the next step is to define and add all the MQTT topics you want to publish and subscribe to the IoT Core. This is done by adding a item defining this topic and is described in the next section.
Configuring topics as Items
When the instance has been set up with the proper endpoint, we next need to set up items that defines the topics to use when publishing and subscribing to the Thing in AWS IoT Core. To learn how to add an item you can follow this guide.
We will set up three items in this example. You can add and name the topics just as you desire:
Topic | Read/Write | Description |
---|---|---|
PublishTopic | Write | Topic used to publish data |
SubscribeTopic | Read | Topic used to subscribe data |
Pub/SubTopic | Read and Write | Topic that both subscribe and publishes data. Not recommended to use as this also subscribes to its own messages |
/device/%INSTANCE_MASTER.NAME%/datapoint/%ITEM_MASTER.NAME% | Write | Topic that will auto generate by the name of the PLC and its datapoints by using the dynamic variables %INSTANCE_MASTER.NAME% and %ITEM_MASTER.NAME%. Refer to Instance variables and Item variables for full reference. E.g.: /device/PLC_BOTTLE/datapoint/Counter |
The following image shows a item configuration for the PublishTopic item. The name of the item can be anything.
Defining message formats for the topics
In order to define and customize the payloads that are being published the Input template for the topics item can be set.
Below are some examples of how these payload and message formats can be set:
Message format example (Input template) | Result |
---|---|
{ "device": "%INSTANCE_MASTER.NAME%", "item": "%ITEM_MASTER.NAME%", "value": "%VALUE%", "time": "%VALUE.TIME%" } |
{ "device": "PLC Bottle Line", "item": "Bottle Counter", "value": "458", "time": "2022-02-03T07:47:26" } |
{ "value": "%VALUE%", "time": "%VALUE.TIME.FORMAT("h:m:s yy/d/M")%", "prod_id": "%UID_OF_PRODUCTION_ITEM%" } |
{ "value": "458", "time": "7:3:5 22/2/3", "prod_id": "ORDER XYZ12345" } |
For a full reference of the available variables and parameters please refer to System variables, Instance variables and Item variables.
That's it, now we are ready to create the mappings between the PLC data and the topics we just added.
Mapping data from the PLCs to AWS IoT Core
SIA Connect is able to read data from almost any PLC. This is done by creating an instance and setting the PLC up withing that instance. If you need help in doing so, our help-page contains various guides for creating instances for the specific PLC you want to use
For a PLC to transfer data to the AWS IoT core, you must use Mappings. Mappings is a SIA Connect feature where you can transfer data from one Instance to another. In this case, we have two instances, a PLC and the AWS IoT Core.
As Master item select the instance and item which masters when to transmit data. In this example we select Siemens S7 PLC and its item named Analog. As Slave item select the AWS instance and the desired Item which in this case is the topic. In this example it is instance named AWS and item named Publish.
In this window we can see how the mapping interface looks like
Data from the Siemens S7 PLC from the Analog item is now being published to the AWS IoT Core's topic named Publish. Continue this step with all the data items which you desire to publish to AWS IoT Core.
Following the next guide - Validating data exchange between AWS IoT Core and PLC - you can see the data being transferred between the AWS IoT Core and SIA Connect and verify that everything is working