Wiznet makers

Aimee0

Published February 12, 2026 ©

65 UCC

23 WCC

14 VAR

0 Contests

0 Followers

0 Following

ioNIC AWS MQTTS Client C Example

The W55RP20-S2E operates as an MQTTS client, connects securely to AWS IoT Core, and publishes and subscribes to configured topics.

COMPONENTS Hardware components

WIZnet - W55RP20-EVB-Pico

x 1


PROJECT DESCRIPTION

How to AWS MQTTS Client Example

This example explains how the Raspberry Pi Pico transmits AT commands to the W55RP20-S2E board via the UART or SPI interface to configure it in MQTTS client mode.

After the MQTTS client configuration is completed, the W55RP20-S2E establishes a TLS-secured connection to AWS IoT Core.

When a message is published to a subscribed topic in AWS IoT Core, the W55RP20-S2E receives the message and forwards it to the Raspberry Pi Pico via UART or SPI.

The Raspberry Pi Pico processes the received message, generates a publish message, and sends it to the W55RP20-S2E through UART or SPI. The W55RP20-S2E then publishes the message to the specified topic in AWS IoT Core.

Step 1: Prepare software

The following serial terminal programs are required for test, download and install from below links.

Step 2: Prepare hardware

1. Connect GPIO13 according to the selected UART/SPI mode of the W55RP20 EVB Pico, as illustrated below.

GPIO13 Pin Desc
LOW(GND)UART mode (default)
HIGH(3.3V)SPI mode

2. Connect the Raspberry Pi Pico and the W55RP20 EVB Pico using jumper wires as shown below, depending on the selected UART/SPI mode.

If UART mode :

Raspberry Pi PicoW55RP20 EVB Pico
GPIO4 (UART_TX)GPIO5 (UART_RX)
GPIO5 (UART_RX)GPIO4 (UART_TX)
GNDGND

If SPI mode :

Raspberry Pi PicoW55RP20 EVB Pico
GPIO2 (SPI_CLK)GPIO2 (SPI_CLK)
GPIO3 (SPI_TX)GPIO4 (SPI_RX)
GPIO4 (SPI_RX)GPIO3 (SPI_TX)
GPIO5 (SPI_CS)GPIO5 (SPI_CS)
GPIO26 (SPI_INT)GPIO26 (SPI_INT)
GNDGND

 

3. Connect the Raspberry Pi Pico to your PC (desktop or laptop) using a 5-pin Micro USB cable.

4. Connect the W55RP20 EVB Pico to your PC (desktop or laptop) using a USB Type-C cable.

Step 3: Setup MQTTS Client Example

AWS IoT Core

In order to connect to AWS IoT through MQTT, the development environment must be configured to use AWS IoT.

This example was tested by configuring AWS IoT Core. Please refer to the 'Create AWS IoT resources' section of document below and configure accordingly.

For more information on AWS IoT, refer to the document below.

Raspberry Pi Pico

Please refer to the link below for setting up the Raspberry Pi Pico development environment.

Getting started with Raspberry Pi Pico

We recommend the following versions for successful build and development:

  • pico-sdk: 2.2.0
  • ARM GCC Toolchain: 14.2.Rel1

To test the MQTTS Client example, minor settings shall be done in code.

Set up the AWS IoT certificates in the 'certification.h' file located in the 'aws_mqtts/' directory using the Root CA, Client Certificate, and Private Key downloaded in the previous “Create AWS IoT resources” step.

// certifiacation.h

// rootca
#define ROOTCA \												
    "-----BEGIN CERTIFICATE-----\r\n"\
    "...\r\n"\
    "-----END CERTIFICATE-----\r\n"

// certificate crt
#define CLEINT_CERT \										
    "-----BEGIN CERTIFICATE-----\r\n"\
    "...\r\n"\
    "-----END CERTIFICATE-----\r\n"

// private key
#define PRIVATE_KEY \										
    "-----BEGIN RSA PRIVATE KEY-----\r\n"\
    "...\r\n"\
    "-----END RSA PRIVATE KEY-----\r\n"

Setup network configuration such as IP and Port etc... in 'aws_mqtts_uart/spi.c' in 'aws_mqtts/' directory.

// aws_mqtts_uart.c

// ======= AWS MQTTS Information =======
const char* SERVER_IP   = "{your_aws_endpoint}.amazonaws.com";    // Remote Host: AWS endpoint
const char* SERVER_PORT = "8883";                                                   // Remote Port 
const char* MQTT_CLIENT_ID = "{your_thing}";                                            // AWS Things name
const char* PUB_TOPIC = "$aws/things/{your_thing}/shadow/update";                       // AWS Publish Topic
const char* SUB_TOPIC = "$aws/things/{your_thing}/shadow/update/accepted";              // AWS Subsribe Topic

int main() {
    											...
    printf("\n--- Config W55RP20 with AT command(UART) ---\n");
    {
        enter_command_mode();                   // Send +++ command
        factory_reset();                        // Send Factory Reset command
        // If you send Reset or Factory Reset command, W55RP20 will reboot and enter to default gateway mode
        enter_command_mode();                   // Send +++ command 
        at_set("OP", "6");                      // Set W55RP20 MQTTS client mode
        at_set("IM", "1");                      // Set W55RP20 DHCP
        at_set("LP", "5000");                   // Set W55RP20's Local Port : 5000
        at_set("RH", SERVER_IP);                // Set Remote IP(ex. PC)
        at_set("RP", SERVER_PORT);              // Set Remote Port
        at_set("QU", "wiznet");                 // Set MQTT user name
        at_set("QP", "");                       // Set MQTT password
        at_set("QC", MQTT_CLIENT_ID);           // Set MQTT client ID
        at_set("QK", "60");                     // Set MQTT Keep-alive
        at_set("PU", PUB_TOPIC);                // Set MQTT public topic
        at_set("U0", SUB_TOPIC);                // Set MQTT subscribe topic1
        at_set("Q0", "0");                      // Set MQTT QoS level
        at_set("RC", "2");                      // Set Root CA verify option : required
        at_set("CE", "1");                      // Set Client certificate enable
        at_set("OC", ROOTCA);                   // Set Root CA
        at_set("LC", CLEINT_CERT);              // Set Client Certificate
        at_set("PK", PRIVATE_KEY);              // Set Private Key
        at_set("SV", NULL);                     // Send Save command
        sleep_ms(100);
        device_reset();                         // Send Reset command
        uart_rx_flush();
    }
    											...
}
// aws_mqtts_spi.c

// ======= AWS MQTTS Information =======
const char* SERVER_IP   = "{your_aws_endpoint}.amazonaws.com";    // Remote Host: AWS endpoint
const char* SERVER_PORT = "8883";                                                   // Remote Port 
const char* MQTT_CLIENT_ID = "{your_thing}";                                            // AWS Things name
const char* PUB_TOPIC = "$aws/things/{your_thing}/shadow/update";                       // AWS Publish Topic
const char* SUB_TOPIC = "$aws/things/{your_thing}/shadow/update/accepted";              // AWS Subsribe Topic

int main() {
    											...
    printf("\n--- Config W55RP20 with AT command(SPI) ---\n");
    {
        at_set("FR", NULL);                     // Send Factory Reset command
        printf("W55RP20 is Rebooting...\n"); 
        sleep_ms(3000); 
        at_set("OP", "6");                      // Set W55RP20 MQTTS client mode
        at_set("IM", "1");                      // Set W55RP20 DHCP
        at_set("LP", "5000");                   // Set W55RP20's Local Port : 5000
        at_set("RH", SERVER_IP);                // Set Remote IP(ex. PC)
        at_set("RP", SERVER_PORT);              // Set Remote Port
        at_set("QU", "wiznet");                 // Set MQTT user name
        at_set("QP", "");                       // Set MQTT password
        at_set("QC", MQTT_CLIENT_ID);           // Set MQTT client ID
        at_set("QK", "60");                     // Set MQTT Keep-alive
        at_set("PU", PUB_TOPIC);                // Set MQTT public topic
        at_set("U0", SUB_TOPIC);                // Set MQTT subscribe topic1
        at_set("Q0", "0");                      // Set MQTT QoS level
        at_set("RC", "2");                      // Set Root CA verify option : required
        at_set("CE", "1");                      // Set Client certificate enable
        at_set("OC", ROOTCA);                   // Set Root CA
        at_set("LC", CLEINT_CERT);              // Set Client Certificate
        at_set("PK", PRIVATE_KEY);              // Set Private Key
        at_set("SV", NULL);                     // Send Save command
        at_set("RT", NULL);                     // Send Reset command
        printf("W55RP20 is Rebooting...\n"); 
        sleep_ms(3000); 
        spi_rx_pending = false;    
    }
            											...
}

W55RP20 EVB Pico

Please refer to the link below for instructions on how to use the W55RP20 S2E.

Getting started with W55RP20 EVB Pico

Step 4: Build and Download

Raspberry Pi Pico

To build the project in Visual Studio Code, select one of the three methods below:

1. Click Build in the bottom status bar

2. Press F7 on your keyboard

3. Run the following command in the Visual Studio Code terminal

$ mkdir build
$ cd ./build
$ cmake -G "NMake Makefiles" ..
$ nmake

When the build is completed, the '{example_name}_uart.uf2' file is generated for UART mode, and the '{example_name}_spi.uf2' file is generated for SPI mode in the {Repository}/build/aws_mqtts/ directory. Download the UF2 file to the Raspberry Pi Pico.

W55RP20 EVB Pico

Following Step 3 in the Getting Started Guide, program the W55RP20 EVB Pico with the UF2 file and write the MAC address to complete the setup.

Step 5: Run

Connect to the serial COM port of the Raspberry Pi Pico using Tera Term.

Step 5.1: UART mode

1. Configure the W55RP20-S2E as an MQTTS client and set up the network using AT commands.

2. Using the AWS IoT console, subscribe to the specified topic. Then publish a test message to the another specified  topic.

The published message is delivered to the W55RP20-S2E module subscribed to the topic through AWS IoT Core.

 

3. The W55RP20-S2E receives the message from the subscribed topic via AWS IoT Core and forwards it to the Raspberry Pi Pico through the UART interface.

The Raspberry Pi Pico prints the received message to a terminal, generates a publish message, and transmits it back to the W55RP20-S2E over UART.

4. The W55RP20-S2E publishes the response message received via UART to the configured topic in AWS IoT Core.

The published message can then be verified using the MQTT test client subscribed to the same topic.

Step 5.2: SPI mode

1. Configure the W55RP20-S2E as an MQTTS client and set up the network using AT commands.

2. Using the AWS IoT console, subscribe to the specified topic. Then publish a test message to the another specified  topic.

The published message is delivered to the W55RP20-S2E module subscribed to the topic through AWS IoT Core.

3. The W55RP20-S2E receives the message from the subscribed topic via AWS IoT Core and forwards it to the Raspberry Pi Pico through the SPI interface.

The Raspberry Pi Pico prints the received message to a terminal, generates a publish message, and transmits it back to the W55RP20-S2E over SPI.

4. The W55RP20-S2E publishes the response message received via SPI to the configured topic in AWS IoT Core.

The published message can then be verified using the MQTT test client subscribed to the same topic.

Documents
  • ioNIC AWS MQTTS Client C example

Comments Write