Insert into AWS DynamoDB
Overview
Once the MQTT connection with AWS works, next let's insert PLC data into AWS DynamoDB
What Is DynamoDB?
Amazon DynamoDB is a fully managed NoSQL database provided by AWS.
Using the AWS IoT Core rules engine, MQTT messages sent from the PLC can be saved automatically to DynamoDB.
Preparation
Preparation on the AWS side
Follow the AWS documentation "Tutorial: Storing device data in a DynamoDB table" to the end
AWS IoT Rule settings
In AWS IoT Core, the rules engine can forward received MQTT messages to DynamoDB.
In this example, the topic device/+/data is targeted and registered in DynamoDB.
Creating the PLC program
Connecting to AWS
Connecting to AWS is the same as in "MQTT connection with AWS"
Sending a message from the PLC
JSON data to send
The PLC sends temperature, humidity, air pressure, wind direction and wind speed information in JSON format.
| Item | Description |
|---|---|
| temperature | Temperature |
| humidity | Humidity |
| barometer | Air pressure |
| velocity | Wind speed |
| bearing | Wind direction |
Sending sample ladder
Change Pub_Topic and Pub_PubMsg from "MQTT connection with AWS" and send
Pub_Topic := 'device/22/data'
Pub_PubMsg :=
'{"temperature": 28,"humidity": 80,"barometer": 1013,"wind": {"velocity": 22,"bearing": 255}}'
ST part
Checking in DynamoDB
Open "Tables" - "Explore items" in DynamoDB, and under "Items returned" you can confirm that the data sent by the PLC has been inserted
FAQ
Can a PLC connect directly to DynamoDB?
Normally data goes through AWS IoT Core and is saved to DynamoDB using an IoT Rule.
What data format is sent?
JSON data is sent as the payload of MQTT messages.
What is DynamoDB?
A fully managed NoSQL database provided by AWS that enables fast and scalable data storage.
