---
title: "W55RP20 MicroPython Examples for mqtt client"
url: "https://maker.wiznet.io/josephsr/projects/w55rp20-micropython-examples-for-mqtt-client/"
markdown_url: "https://maker.wiznet.io/josephsr/projects/w55rp20-micropython-examples-for-mqtt-client/md"
type: "WCC: WIZnet Created Content"
author: "Joseph"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "Joseph"
license: "MIT license (MIT)"
published: "2024-12-16"
language: "en"
tags: ["MQTT"]
hardware: ["WIZnet W55RP20-EVB-Pico"]
likes: 0
views: 1375
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# W55RP20 MicroPython Examples for mqtt client

> This MicroPython script implements an MQTT client for W55RP20, utilizing the umqttsimple library.

Original author: Joseph

## Components

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

- [ioNIC micropython MQTT client](https://github.com/WIZnet-ioNIC/WIZnet-ioNIC-micropython-examples/blob/main/mqtt_client_test.py) (code)

## Article

## MQTT Client

<https://github.com/WIZnet-ioNIC/WIZnet-ioNIC-micropython-examples#mqtt-client>

**File:** mqtt_client_test.py

### dependencies

<https://github.com/WIZnet-ioNIC/WIZnet-ioNIC-micropython-examples#dependencies>

**File:** w5x00.py, umqttsimple.py

This MicroPython script implements an MQTT client for W55RP20, utilizing the umqttsimple library. It connects to an MQTT broker, publishes messages periodically, and handles reconnections.

### Expected Output

<https://github.com/WIZnet-ioNIC/WIZnet-ioNIC-micropython-examples#expected-output-2>

#### this program

<https://github.com/WIZnet-ioNIC/WIZnet-ioNIC-micropython-examples#this-program>

```
Connected to 192.168.1.2 MQTT Broker
```

#### mosquitto mqtt broker

<https://github.com/WIZnet-ioNIC/WIZnet-ioNIC-micropython-examples#mosquitto-mqtt-broker>

```
1734315706: New connection from 222.98.173.219 on port 1883.
1734315706: New client connected from 222.98.173.219 as wiz2 (c1, k60).
1734315706: No will message specified.
1734315706: Sending CONNACK to wiz2 (0, 0)
1734315706: Received PUBLISH from wiz2 (d0, q0, r0, m0, 'kkk', ... (10 bytes))
1734315709: Received PUBLISH from wiz2 (d0, q0, r0, m0, 'kkk', ... (10 bytes))
1734315712: Received PUBLISH from wiz2 (d0, q0, r0, m0, 'kkk', ... (10 bytes))
...
```

### Important Considerations

<https://github.com/WIZnet-ioNIC/WIZnet-ioNIC-micropython-examples#important-considerations-1>

#### MQTT Broker Configuration

<https://github.com/WIZnet-ioNIC/WIZnet-ioNIC-micropython-examples#mqtt-broker-configuration>

```plaintext
The mqtt_server variable must be changed to the actual IP address of your MQTT broker. For example, if you're using AWS EC2, use the public IP address of your EC2 instance.
The port variable should be set to the actual port number of your MQTT broker. While MQTT typically uses port 1883, this may vary depending on your broker's configuration.
Set the topic_pub variable to the topic name you want to publish to. This defines the subject or category of your messages.
Configure the topic_msg variable with the actual message content you wish to publish. This is the payload that will be sent to the specified topic.
```

#### Additional Considerations

<https://github.com/WIZnet-ioNIC/WIZnet-ioNIC-micropython-examples#additional-considerations>

```plaintext
Adjust firewall settings to allow external access to the MQTT broker if required.
For enhanced security, it's recommended to set allow_anonymous to false and implement user authentication.
When connecting from external networks, ensure you're using the public IP address.
If using cloud services like EC2, open the necessary port (typically 1883) for MQTT communication in the security group settings.
Depending on your network environment, port forwarding may be necessary.
Regularly update your broker software and client libraries to ensure you have the latest security patches and features.
```

---

Source: https://maker.wiznet.io/josephsr/projects/w55rp20-micropython-examples-for-mqtt-client/
