Skip to content

Visualization W5100S-EVB-Pico MQTT Using AWS + Grafana

Visualization W5100S-EVB-Pico MQTT Using AWS + Grafana

pranchal

Published March 28, 2022

Project description

Things used in this project

Hardware components

W5100S-EVB-Pico
WIZnet W5100S-EVB-Pico
× 1
Ethernet Cable, Cat6a
Ethernet Cable, Cat6a
× 1
USB-A to B Cable
USB-A to B Cable
× 1

Software apps and online services

AWS IoT
Amazon Web Services AWS IoT
Amazon Timestream
Grafana

Story

1. W5100S-EVB-Pico + AWS IoT Core

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?rn.

uint8_t mqtt_root_ca[] =
"-----BEGIN CERTIFICATE-----rn"
"...rn"
"-----END CERTIFICATE-----rn";

uint8_t mqtt_client_cert[] =
"-----BEGIN CERTIFICATE-----rn"
"...rn"
"-----END CERTIFICATE-----rn";

uint8_t mqtt_private_key[] =
"-----BEGIN RSA PRIVATE KEY-----rn"
"...rn"
"-----END RSA PRIVATE KEY-----rn";

-?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.

1. W5100S-EVB-Pico + AWS IoT Core

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.

1. W5100S-EVB-Pico + AWS IoT Core

2. AWS IoT Rule + Timestream

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.

2. AWS IoT Rule + Timestream

-?Create Table

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

2. AWS IoT Rule + Timestream

2) Setup IoT Rule

-?Create Rule

AWS IoT Core > Rule > Create

2. AWS IoT Rule + Timestream

Set rulename.

2. AWS IoT Rule + Timestream

Set query.?Enter the?topic?set above.

2. AWS IoT Rule + Timestream

Timestream job configuration.

2. AWS IoT Rule + Timestream

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.

2. AWS IoT Rule + Timestream

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.

2. AWS IoT Rule + Timestream
2. AWS IoT Rule + Timestream

Error actions and tags create rules without separate actions.

2. AWS IoT Rule + Timestream

-?Check Timestream table

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

2. AWS IoT Rule + Timestream

3. Timestream + Grafana

1) Connect Timestream to Grafana

Setup Data sources.

Enter Grafana - Configuration - Data sources > Amazon Timestream

3. Timestream + Grafana

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.

3. Timestream + Grafana

2) Setting Dashboard

Create - Dashboard

3. Timestream + Grafana

New dashboard created. Choose?Add a new panel.

3. Timestream + Grafana

Set queries.

3. Timestream + Grafana
3. Timestream + Grafana

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.

3. Timestream + Grafana

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

3. Timestream + Grafana

Comments

Similar projects you might like

Comments