---
title: "W55RP20-S2E MQTTS(AWS) client Example (MicroPython)"
url: "https://maker.wiznet.io/Grace_Koo/projects/w55rp20-s2e-mqtts-aws-client-example-micropython/"
markdown_url: "https://maker.wiznet.io/Grace_Koo/projects/w55rp20-s2e-mqtts-aws-client-example-micropython/md"
type: "WCC: WIZnet Created Content"
author: "Grace"
author_url: "https://maker.wiznet.io/Grace_Koo/"
original_author: "Grace_Koo"
published: "2026-02-25"
language: "en"
tags: ["AWS IoT Core", "wow-contest-ref"]
hardware: ["WIZnet W55RP20", "WIZnet W55RP20-EVB-Pico"]
likes: 0
views: 805
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# W55RP20-S2E MQTTS(AWS) client Example (MicroPython)

> This example demonstrates MQTTS(AWS) client on W55RP20 S2E via UART/SPI using MicroPython on a Raspberry Pi Pico (Master)

Original author: Grace_Koo

## Components

- **WIZnet W55RP20** x 1 ([docs](https://wiznet.io/products/ionic-chips/w55rp20))
- **WIZnet W55RP20-EVB-Pico** x 1 ([docs](https://wiznet.io/products/powered-by-raspberry-pi/w55rp20-evb-pico))
- Software: **MicroPython** ([docs](http://micropython.org/))

## Documents and links

- [GitHub : W55RP20-S2E_master_Micropython](https://github.com/WIZnet-ioNIC/WoW-io-Design-Contest/tree/main/MicroPython) (code)

## Article

## How to MQTTS (AWS IoT Core) Client Example (MicroPython)

This program demonstrates how to configure the W55RP20-S2E board as an MQTTS Client (OP=6) using a Raspberry Pi Pico (Host) via UART or SPI. It establishes a secure connection to AWS IoT Core using SSL/TLS certificates to publish and subscribe to messages.

## Step 1: Prepare software

The following software is required to run and test the MicroPython example.

- [**Thonny**](https://thonny.org/) : An integrated development environment for MicroPython. used to write, upload, and run code.

- AWS IoT Setup & Certificate Download:

- Please refer to the <https://docs.wiznet.io/Product/Chip/MCU/Pre-programmed-MCU/W55RP20-S2E/mqtt-connection-guide-en#how-to-connect-to-aws-using-mqtt>

- Following the link, you must create a "Thing" in the AWS IoT Console.

- Crucial: During the creation process, you must download the Device Certificate, Private Key, and the Amazon Root CA 1 file to your PC.

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

- Important Note on Mode Switching: In this example setup, GPIO 13 of the W55RP20 EVB Pico is physically connected to GPIO 13 of the Raspberry Pi Pico. The Host Pico sets the mode (High/Low) automatically based on the software configuration.

- If you change the **`**MODE**`** in the code (e.g., UART ↔ SPI): You MUST reset both boards (Raspberry Pi Pico and W55RP20 EVB Pico) to ensure the mode is switched and recognized correctly.

**If UART mode :**

| Raspberry Pi Pico | W55RP20 EVB Pico |
| --- | --- |
| GPIO4 (UART_TX) | GPIO5 (UART_RX) |
| GPIO5 (UART_RX) | GPIO4 (UART_TX) |
| GPIO13 (MODE_SEL) | GPIO13 (MODE_SEL) |
| GND | GND |

**If SPI mode :**

| Raspberry Pi Pico(Master) | W55RP20 EVB Pico(Slave) |
| --- | --- |
| 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) |
| GPIO13 (MODE_SEL) | GPIO13 (MODE_SEL) |
| GND | GND |

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 Example

- Raspberry Pi Pico (Master) : [Getting started with Raspberry Pi Pico (MicroPython)](https://www.raspberrypi.com/documentation/microcontrollers/micropython.html)

Please refer to the link below to install the MicroPython firmware on the Raspberry Pi Pico.

- **W55RP20 EVB Pico : **[Getting started with W55RP20 EVB Pico](https://docs.wiznet.io/Product/Chip/MCU/Pre-programmed-MCU/W55RP20-S2E/w55rp20-evb-pico-s2e)

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

- **Configure Certificates in Example Code : **Before running the example, you must manually input the downloaded certificate data into `09_mqtts_client.py`.

1. Open the downloaded certificate files (.pem or .txt) using a text editor (like Notepad).

2. Copy the text and paste it into the corresponding variables in the code.

3. Note: Ensure you include the `\r\n` line breaks as shown in the template to maintain the correct PEM format.

```python
# 09_mqtts_client.py - Certificate Section

# Paste 'AmazonRootCA1.pem' content here
AWS_CA_CERT = (
    "-----BEGIN CERTIFICATE-----\r\n"
    "..."
    "-----END CERTIFICATE-----\r\n"
)

# Paste 'xxx-certificate.pem.crt' content here
AWS_CLIENT_CERT = (
    "-----BEGIN CERTIFICATE-----\r\n"
    "..."
    "-----END CERTIFICATE-----\r\n"
)

# Paste 'xxx-private.pem.key' content here
AWS_PRIVATE_KEY = (
    "-----BEGIN RSA PRIVATE KEY-----\r\n"
    "..."
    "-----END RSA PRIVATE KEY-----\r\n"
)
```

## Step 4: Upload Code

- **Raspberry Pi Pico**

Open Thonny IDE and connect to the Raspberry Pi Pico. Upload the following driver and example files to the Pico's storage.

![](https://maker.wiznet.io/upload/ckeditor5/408384515%5F1769791777%2Epng)

*PICO's storage*

Required Files:

1. `w55rp20_s2e_uart.py` (Required for UART mode)

2. `w55rp20_s2e_spi.py` (Required for SPI mode)

Example Application Files (Choose one to test):

- `09_mqtts_client.py` (The main application)

Configuration: Before running an example, open the Python file you intend to use and modify the User Configuration section at the top.

```python
# 09_mqtts_client.py
#
# MQTTS (AWS IoT Core) example (Supports both SPI and UART modes):
# - Configure the module as MQTTS client (OP=6) + DHCP
# - Upload Root CA / Client Certificate / Private Key via AT commands
# - Publish initial message and receive subscribed topic data
#
# Select mode by changing the MODE variable below.

import time

# -------------------------------------------------------------------------
# Configuration
# -------------------------------------------------------------------------
MODE     = "spi"  # Set to "spi" or "uart"
USE_DHCP = True    # True: DHCP (IM=1), False: Static IP (IM=0)

# AWS IoT Settings
BROKER_HOST = "YOUR_AWS_ENDPOINT"
BROKER_PORT = "8883"
CLIENT_ID   = "w55rp20_aws_client"
SUB_TOPIC   = "sdk/test/python"
PUB_TOPIC   = "sdk/test/python1"
PUB_MESSAGE = "Hello from W55RP20-S2E to AWS IoT"
KEEP_ALIVE  = 60

# Network Configuration
LOCAL_IP    = "192.168.11.100"  # Local IP (Used when USE_DHCP=False)
SUBNET_MASK = "255.255.255.0"   # Subnet Mask (Used when USE_DHCP=False)
GATEWAY     = "192.168.11.1"    # Gateway (Used when USE_DHCP=False)
DNS_SERVER  = "8.8.8.8"         # DNS Server (Used when USE_DHCP=False)
.
.
```

## Step 5: Testing with Mosquitto (PC Side)

![](https://maker.wiznet.io/upload/ckeditor5/810853661%5F1772031375%2Epng)

**Log in to AWS IoT Console: Navigate to Test > MQTT test client.**

---

![](https://maker.wiznet.io/upload/ckeditor5/810853661%5F1772031423%2Epng)

**Monitor Incoming Messages:**

- In the Subscribe to a topic tab, enter sdk/test/python1.

- Click Subscribe.

---

![](https://maker.wiznet.io/upload/ckeditor5/810853661%5F1772031448%2Epng)

**Prepare to Send Messages:**

- In the Publish to a topic tab, enter sdk/test/python.

- Enter a message (e.g., {"message": "Hello from AWS IoT console"}).

Bash

```
# Send a message to the Pico
mosquitto_pub -h localhost -t w55rp20/sub -m "LED_ON"
```

## Step 6: Run

![](https://maker.wiznet.io/upload/ckeditor5/810853661%5F1772031674%2Epng)

Pico (Thonny):

- Open `09_mqtts_client.py`.

- Run the script (F5).

- Wait for the TLS handshake (this takes longer than standard MQTT—about 15 seconds).

---

![](https://maker.wiznet.io/upload/ckeditor5/810853661%5F1772031690%2Epng)

AWS IoT (Verify Publish):

- You should see `"Hello from W55RP20-S2E to AWS IoT"`

---

![](https://maker.wiznet.io/upload/ckeditor5/810853661%5F1772031716%2Epng)

Pico (Thonny) : **Verify Subscribe**

- Publish a message from the AWS Console to `sdk/test/python`.

- You should see `[RX] sdk/test/python : {"message": "Hello from AWS IoT console"}` in the Thonny shell.

---

Source: https://maker.wiznet.io/Grace_Koo/projects/w55rp20-s2e-mqtts-aws-client-example-micropython/
