Visualization W5100S-EVB-Pico MQTT Message Using AWS + Grafana

by Gemma_Lee in Circuits > Raspberry Pi

571 Views, 2 Favorites, 0 Comments

Visualization W5100S-EVB-Pico MQTT Message Using AWS + Grafana

그림2.png

Visualization W5100S-EVB-Pico MQTT Message using AWS IoT Core, Amazon Timestream DB and Grafana.

Supplies

cover.png
  • WIZnet W5100S-EVB-Pico
  • Ethernet Cable
  • USB cable
  • AWS IoT
  • Amazon Timestream
  • Grafana

W5100S-EVB-Pico + AWS IoT Core

tess.PNG

1) Connect components

Connect W5100S-EVB-Pico and ethernet cable. And the board connect to PC using 5 pin USB cable.

2) Setup AWS IoT Core

Please see and follow the link below.

https://docs.aws.amazon.com/iot/latest/developerguide/create-iot-resources.html

3) Setup Connect AWS IoT through MQTT Example

- Git clone

git clone --recurse-submodules https://github.com/Wiznet/RP2040-HAT-AWS-C.git

- Setup SPI port and pin

Settings in the 'w5x00_spi.h' file located in the 'RP2040-HAT-AWS-C/port/ioLibrary_Driver/' directory.

/* SPI */
#define SPI_PORT spi0

#define PIN_SCK 18
#define PIN_MOSI 19
#define PIN_MISO 16
#define PIN_CS 17
#define PIN_RST 20

- Setup network config

Set in the 'aws_iot_mqtt.c' file in the 'RP2040-HAT-AWS-C/examples/aws_iot_mqtt/' directory.

If the board is connected to the router, it is assigned automatically, so there is no need to edit the file.

/* Network */
static wiz_NetInfo g_net_info =
    {
        .mac = {0x00, 0x08, 0xDC, 0x12, 0x34, 0x56}, // MAC address
        .ip = {192, 168, 11, 2},                     // IP address
        .sn = {255, 255, 255, 0},                    // Subnet Mask
        .gw = {192, 168, 11, 1},                     // Gateway
        .dns = {8, 8, 8, 8},                         // DNS server
        .dhcp = NETINFO_DHCP                         // DHCP enable/disable
};

- Setup AWS IoT configuration

MQTT_DOMAIN is AWS IoT Core > setting > device data endpoint.

Replace my_rp2040_thing with the name of the device you created.

Username and password are not set.

/* 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"

- Setup device certificate and key

Set in the mqtt_certificate.h file in the 'RP2040-HAT-AWS-C/examples/aws_iot_mqtt/' directory.

Insert the authentication key issued when creating a device in AWS. Put the Amazon Root CA1 certificate in root_ca. Put your certificate.pem in client_cert. Put RSA in the private key.

You must enter it according to the input format below. Enclose each line in quotation marks and \r\n.

uint8_t mqtt_root_ca[] =
"-----BEGIN CERTIFICATE-----\r\n"
"...\r\n"
"-----END CERTIFICATE-----\r\n";

uint8_t mqtt_client_cert[] =
"-----BEGIN CERTIFICATE-----\r\n"
"...\r\n"
"-----END CERTIFICATE-----\r\n";

uint8_t mqtt_private_key[] =
"-----BEGIN RSA PRIVATE KEY-----\r\n"
"...\r\n"
"-----END RSA PRIVATE KEY-----\r\n";

- Setting MQTT Message

In RP2040-HAT-AWS-C, in the file examples/aws_iot_mqtt/aws_iot_mqtt.c, change the line 207 code to temperature, humidity and build.

4) Build

When you have finished editing the file, click the build button in vs code or press f7. When the build is completed, the 'aws_iot_mqtt.uf2' file is created in the 'RP2040-HAT-AWS-C/build/examples/aws_iot_mqtt/' directory.

5) Upload and Run

Press the BOOTSEL button of W5100S-EVB-Pico and connect the USB port to mount the RPI-RP2 drive automatically. Copy and paste the 'aws_iot_mqtt.uf2' file in the drive.

- AWS MQTT Test client

Select the Test Client menu in the AWS IoT console. Subscribe to a topic and publish a topic.

AWS IoT Rule + Timestream

1.PNG
2.PNG
3.PNG
4.PNG
5.PNG
6.PNG
7.PNG
8.PNG
9.PNG
10.PNG

1) Setup Amazon Timestream

- Create DB

Enter the Timestream console and create a DB. Select Standard database, set only the DB name and click the Create database button.

- Create Table

Create a table in the DB created above. Set the name, data retention period and click the Create table button.

2) Setup IoT Rule

- Create Rule

AWS IoT Core > Rule > Create

Set rule name.

Set query. Enter the topic set above.

Timestream job configuration.

Set the DB and Table created above, and set the dimension to clientId. ${clientId()} is the value received from the device. There are only Temperature and Humidity in the MQTT message, but if you do this, the clientId is automatically inserted into the table.

Click Create Role and create a new one.

You can set it up by going to the IAM page, but if you set only a name and create a role here, the role is automatically set with permission to write data to Timestream, so it is convenient to create it here.

Also, if a pre-made role is used, even if the role can write to the timestream table, the role has limited privileges only for a specific table, so the operation is not performed properly.

It is recommended to make a new one and use it.

Error actions and tags create rules without separate actions.

- Check Timestream table

Check whether the rule is executed properly through the Query editor in Timestream.

Timestream + Grafana

31.PNG
32.PNG
33.PNG
34.PNG
35.PNG
36.PNG
37.PNG
328.PNG

1) Connect Timestream to Grafana

Setup Data sources.

Enter Grafana - Configuration - Data sources > Amazon Timestream

Timestream settings

Select Access & secret key from Authentication Provider and enter. Default Region is set to the region where Timestream exists. Default Query Macros set Timestream DB and Table. After completing the settings, click the Save & test button below, and if the connection is successful, a message of Connection success appears.

2) Setting Dashboard

Create - Dashboard

New dashboard created. Choose Add a new panel.

Set queries.

Timestream data can be monitored in real time.

Currently, data is passed as a fixed value, but it can be implemented by connecting a sensor to receive the sensor value.

By pressing the Apply button above, you can visualize the MQTT message sent by W5100S-EVB-Pico in real time.