How to Save W5100S-EVB-Pico MQTT Message in AWS DynamoDB

by Gemma_Lee in Circuits > Raspberry Pi

191 Views, 2 Favorites, 0 Comments

How to Save W5100S-EVB-Pico MQTT Message in AWS DynamoDB

아키텍처.jpg

This post is a tutorial to receive MQTT Message from W5100S-EVB-Pico and store it in DynamoDB. First, MQTT Message is received from IoT Core and processed according to the rule. This rule triggers Lambda, which allows the MQTT message to be stored in DynamoDB. Data is stored in a DynamoDB Table through this Lambda.

Supplies

cover.png
  1. WIZnet W5100S-EVB-Pico
  2. Amazon Web Services AWS IoT
  3. Amazon Web Services AWS Lambda
  4. Amazon Web Services AWS DynamoDB

Create Thing

1.png
2.png
3.png
4.png

- Click "Create things"

- Select "Create single thing"

- Set thing Name

- Select "Auto-generate... "

- Create and connect a policy for using IoT Core.

{
   "Version": "2012-10-17",
   "Statement": [
     {
       "Effect": "Allow",
       "Action": "iot:Connect",
       "Resource": "*"
     },
     {
       "Effect": "Allow",
       "Action": "iot:Publish",
       "Resource": "*"
     },
     {
       "Effect": "Allow",
       "Action": "iot:Receive",
       "Resource": "*"
     },
     {
       "Effect": "Allow",
       "Action": "iot:Subscribe",
       "Resource": "*"
     }
   ]
}

Publish MQTT Message

- I used a repository that connects the RP2040 and AWS.

https://github.com/Wiznet/RP2040-HAT-AWS-C/tree/main/examples/aws_iot_mqtt

- I changed the thing name to the thing name created above.

/* AWS IoT */
#define MQTT_DOMAIN "account-specific-prefix-ats.iot.ap-northeast-2.amazonaws.com"
#define MQTT_PUB_TOPIC "$aws/things/my_rp2040_thing/shadow/update"
#define MQTT_SUB_TOPIC "$aws/things/my_rp2040_thing/shadow/update/accepted"
#define MQTT_USERNAME NULL
#define MQTT_PASSWORD NULL
#define MQTT_CLIENT_ID "my_rp2040_thing"

- Message payload:

{"temperature":23, "humidity":25}

Create DynamoDB Table

5.png

- Only Table name, Partition key, and Sort key (option) were set, and default values ​​were used for other settings.

- creatTime is timestamp value.

Create Lambda

6.png

- Set function name and Select Runtime.

- Deploy index.js after changing the contents below.


Create IoT Rule

7.png
8.png
9.png
10.png

- Set rule name.

- SQL statement

SELECT * as payload, clientId() as clientId, timestamp() as timestamp FROM '$aws/things/picoThing/shadow/update'

- Select Lambda function which made above.

- Create rule and rule enabled.

- Save data in DynamoDB Table.