---
title: "How to connect AWS IoT with Micropython using W5100S-EVB-Pico"
url: "https://maker.wiznet.io/rena/projects/how-to-connect-aws-iot-with-micropython-using-w5100s-evb-pico/"
markdown_url: "https://maker.wiznet.io/rena/projects/how-to-connect-aws-iot-with-micropython-using-w5100s-evb-pico/md"
type: "WCC: WIZnet Created Content"
author: "rena"
original_author: "Rena"
published: "2022-11-14"
language: "en"
tags: ["MicroPython", "MQTT"]
hardware: ["WIZnet W5100S-EVB-Pico"]
likes: 11
views: 7940
comments: 2
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# How to connect AWS IoT with Micropython using W5100S-EVB-Pico

> Let's connect to AWS IoT Core using the W5100S-EVB-Pico board and Micropython.

Original author: Rena

## Components

- **WIZnet W5100S-EVB-Pico** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5100S/w5100s-evb-pico))
- Software: **AmazonWebServices AWS IoT** ([docs](https://aws.amazon.com/iot/))

## Documents and links

- [Micropython main.py](https://github.com/renakim/RP2040-HAT-MicroPython/blob/add-example/examples/Cloud/AWS/main.py) (code)

## Article

Let’s connect to AWS IoT Core using the W5100S-EVB-Pico board.

I will implement it using Micropython and connect it with the MQTT protocol.

### **Prerequisite**

For reference, the host PC environment uses Windows 10 64bit, and the WSL2 environment is used together. (using OpenSSL)

**H/W**

- W5100S-EVB-Pico

- Micro 5-pin USB Cable

- LAN cable

**S/W or Platform**

- Thonny (Micropython development)

- AWS IoT Core

### **AWS Services**

How to create a device in AWS service linked external content.

This content summarizes the process of linking WizFi360-EVB-Pico to AWS IoT Core based on C. The process of creating a device in AWS IoT is well explained.

- [Connect WizFi360-EVB-Pico to AWS IoT Core](https://maker.wiznet.io/mason/projects/connect-wizfi360-evb-pico-to-aws-iot-core/)

A full description of the features can be found in the official guide document.

- [Create AWS IoT Resouces](https://docs.aws.amazon.com/en_us/iot/latest/developerguide/create-iot-resources.html)

If you have completed creating the device, you should be able to get a device certificate and a root certificate.

It is also highlighted in the guide, but you **must save the certificate on the device download certificate page** that appears when you create it. Otherwise, you have to go through the creation process again.

Only the device certificate and private key are used here.

### **Upload Micropython Firmware**

The process of building and uploading the firmware links content dealing with the existing Azure integration process instead.

- (English) [Connect to Azure IoT Hub using Micropython on W5100S-EVB-Pico](https://maker.wiznet.io/rena/projects/connect-to-azure-iot-hub-using-micropython-on-w5100s-evb-pico/)

### **Write application code**

Here, we need to modify the following variables:

- Device Id

- MQTT Topic (Assigned Topic or Free Topic)

- Hostname (Endpoint)

- Set device certificates (Device certificate & Private key)

The full example code can be found at the link below.

- <https://github.com/renakim/W5100S-EVB-Pico-Micropython/tree/main/examples/AWS>

**Modify variables**

Enter the variable values ​​below according to the device resource information created by AWS.

The topic can be used as a free topic or a predefined topic can be used. Since the specified topic is used here, it is not specified separately.

```plaintext
device_id = '<Device Id>'
hostname = '<Hostname or Endpoint>'
mqtt_topic = f'$aws/things/{device_id}/shadow/update'
```

- Device Id: Created Thing Name

- Hostname (Endpoint): Can be found `AWS IoT - Settings`

![](https://hackster.imgix.net/uploads/attachments/1513713/pico-micropython-aws-endpoint.png?auto=compress%2Cformat&w=740&h=555&fit=max)

**Config device certificate**

Upload the downloaded certificate from the AWS resource configuration section to W5100S-EVB-Pico and set the path.

The downloaded certificate will be in the following format.

- &lt;Certificate Id>-certificate.pem.crt

- &lt;Certificate Id>-private.pem.key

- &lt;Certificate Id>-public.pem.key

- AmazonRootCA1.pem

- AmazonRootCA3.pem

Among them, certificate.pem.crt and private.pem.key is used.

**Convert certificates**

You need to convert the certificate to a form that the Micropython library can recognize.

The downloaded certificate is in base64-based PEM format, and it will be converted to binary.der.

> OpenSSL is used for certificate conversion, and it is recommended to use WSL (Windows Subsystem Linux) environment for Windows 10 or higher environment.

Convert the device certificate and private key to der format using the command below.

```plaintext
# Convert Device Certificate
openssl x509 -outform der -in certificate.pem.crt -out certificate.crt.der
# Convert Key
openssl rsa -inform pem -in private.pem.key -outform DER -out private.key.der
```

**Upload certificates**

Upload the converted certificate to Pico and set the path.

If you cloned the example, there will be a directory called cert, copy the device certificate and key file converted to.der here and upload the folder to Pico.

![](https://hackster.imgix.net/uploads/attachments/1513714/pico-micropython-aws-thonny_files.png?auto=compress%2Cformat&w=740&h=555&fit=max)

> The left explorer window can be used with the View - Files option.

![](https://hackster.imgix.net/uploads/attachments/1513715/pico-micropython-aws-upload_cert.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Place the cursor on the cert directory, right-click, and select the `Upload to /` menu to upload the folder as it is.

If the path or file name is different, you can modify the certificate path in `main.py`.

```plaintext
# Certificate path
cert_file = 'cert/certificate.crt.der'
key_file = 'cert/privateKey.key.der'
```

**Install MQTT library for Micropython**

Install the library in the Thonny environment.

After selecting Tools - Manage packages from the top menu, enter umqtt and search.

![](https://hackster.imgix.net/uploads/attachments/1513716/pico-micropython-azure-07.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Select and install umqtt.simple among the found packages.

![](https://hackster.imgix.net/uploads/attachments/1513717/pico-micropython-azure-08.png?auto=compress%2Cformat&w=740&h=555&fit=max)

If the installation is successful, you can see the installed packages when you click umqtt in the list on the left.

![](https://hackster.imgix.net/uploads/attachments/1513718/pico-micropython-azure-10.png?auto=compress%2Cformat&w=740&h=555&fit=max)

**MonitoringMonitor Application**

With main.py open in Thonny, click the play button at the top or click F5 key to run the application.

The debug message is output as follows.

![](https://hackster.imgix.net/uploads/attachments/1513719/pico-micropython-thonny_mqtt.png?auto=compress%2Cformat&w=740&h=555&fit=max)

> If a connection error occurs, it is most likely a certificate problem. Check that the path is set correctly and that the certificate converted to.der is inserted.

**Monitor AWS IoT**

You can monitor device data by using the `MQTT test client` in the AWS IoT service.

![](https://hackster.imgix.net/uploads/attachments/1513720/pico-micropython-aws-mqtt_test_client.png?auto=compress%2Cformat&w=740&h=555&fit=max)

If you press the Subscribe button after entering the topic set in the Subscribe to a topic tab, you can start subscribing to MQTT messages and monitor messages sent from the device.

![](https://hackster.imgix.net/uploads/attachments/1513721/pico-micropython-aws-monitoring.png?auto=compress%2Cformat&w=740&h=555&fit=max)

So far, I have summarized how to connect to AWS IoT Core using Micropython using the W5100S-EVB-Pico device.

### **Related contents**

- [Connect to Azure IoT Hub using Micropython on W5100S-EVB-Pico](https://maker.wiznet.io/rena/projects/connect-to-azure-iot-hub-using-micropython-on-w5100s-evb-pico/)

### **Reference**

- [RP2040-HAT-MicroPython Repository](https://github.com/Wiznet/RP2040-HAT-MicroPython)

- [Micropython forum post from nickehallgren](https://forum.micropython.org/viewtopic.php?t=12955&p=70605)

---

Source: https://maker.wiznet.io/rena/projects/how-to-connect-aws-iot-with-micropython-using-w5100s-evb-pico/
