---
title: "WIZnet Ethernet HAT[RP2040] + MQTT publish [mosquitto]"
url: "https://maker.wiznet.io/WIZnet/projects/wiznet-ethernet-hat%5Brp2040%5D-mqtt-publish-%5Bmosquitto%5D/"
markdown_url: "https://maker.wiznet.io/WIZnet/projects/wiznet-ethernet-hat%5Brp2040%5D-mqtt-publish-%5Bmosquitto%5D/md"
type: "UCC: User Created Content"
author: "louis_m"
author_url: "https://www.hackster.io/louis_m/wiznet-ethernet-hat-rp2040-mqtt-publish-mosquitto-03a1f5"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "louis_m"
original_url: "https://www.hackster.io/louis_m/wiznet-ethernet-hat-rp2040-mqtt-publish-mosquitto-03a1f5"
published: "2023-02-16"
language: "en"
hardware: ["WIZnet Ethernet HAT"]
likes: 8
views: 751
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# WIZnet Ethernet HAT[RP2040] + MQTT publish [mosquitto]

> Source where the WIZnet Ethernet module becomes an MQTT publisher and another module becomes a Client.

Original author: louis_m (source: https://www.hackster.io/louis_m/wiznet-ethernet-hat-rp2040-mqtt-publish-mosquitto-03a1f5)

## Components

- **WIZnet Ethernet HAT** x 1

## Article

### **Overview**

WIZnet Ethernet HAT (Hardware Attached on Top) is a Raspberry Pi Pico pin-compatible board that utilizes W5100S and supports both 3.3V & 5V.

Please refer to this link to find more information about [W5100S.](https://docs.wiznet.io/Product/iEthernet/W5100S/overview)

- Raspberry Pi Pico Pin-Compatible

- Ethernet (W5100S Hardwired TCP/IP CHIP)

- Product page : <https://docs.wiznet.io/Product/iEthernet/W5100S/overview>

- Support **4 Independent Hardware SOCKET**s simultaneously

- Support SOCKET-less new Command: **ARP-Request, PING-Request**

- Support **Auto-MDIX only when Auto-Negotiation mode**

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

![WIZnet Ethernet HAT](https://hackster.imgix.net/uploads/attachments/1363631/image_ot1Du7k3q0.png?auto=compress%2Cformat&w=740&h=555&fit=max)

WIZnet Ethernet HAT

![RP2040](https://hackster.imgix.net/uploads/attachments/1363632/image_rjXDwkzhto.png?auto=compress%2Cformat&w=740&h=555&fit=max)

RP2040

### **Prepare**

> ***Prepare Hardware***

1.Combine WIZnet Ethernet HAT with Raspberry Pi Pico.

2.Connect ethernet cable to Ethernet HAT ethernet port.

3.Connect Raspberry Pi Pico to desktop or laptop using 5 pin micro USB cable.

– If you use W5100S-EVB-Pico, you can skip ‘1. Combine…’

> ***Prepare Software*Installing CircuitPython**

Install `CircuitPython` on Raspberry Pi Pico by referring to the link above.

<https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/circuitpython>

**Setup WIZnet Ethernet Library**

Copy the [**WIZnet library**](https://github.com/Wiznet/RP2040-HAT-CircuitPython)[I](https://github.com/Wiznet/RP2040-HAT-CircuitPython/tree/master/lib)nto the lib folder inside the Raspberry Pi Pico. <https://learn.adafruit.com/ethernet-for-circuitpython/circuitpython-setup>

Before continuing, make sure your board’s lib folder has at least the following files and folders copied over: <https://github.com/Wiznet/RP2040-HAT-CircuitPython>

`adafruit_bus_device`

`adafruit_wiznet5k`

`adafrui_minimqtt`

![CircuitPython libraries](https://hackster.imgix.net/uploads/attachments/1363633/image_T8Qu48gc5Z.png?auto=compress%2Cformat&w=740&h=555&fit=max)

CircuitPython libraries

**Install Programs**

The following serial terminal program is required for **MQTT Publish** test, download and install from below links.

![✔](https://s.w.org/images/core/emoji/11.2.0/svg/2714.svg)[Tera Term](https://osdn.net/projects/ttssh2/releases/)

![✔](https://s.w.org/images/core/emoji/11.2.0/svg/2714.svg)[Mosquitto](https://mosquitto.org/download/)

### **Run PICO**

Before this, you should find the Raspberry Pi Pico COM port number from “Device Manager” on your PC.

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

### **How to MQTT_publish Example**

> ***Setup MQTT_PublishExample***

– download<https://github.com/Wiznet/RP2040-HAT-CircuitPython/tree/master/examples/MQTT/Publish>

– Copy all code from download **W5x00_MQTT_pub.py** file or below code section.

– Paste code into **code.py **on your Raspberry Pi Pico and Save it.

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

Create broker using mosquitto by executing the following command. If the broker is created normally, the broker’s IP address is the current IP of your desktop or laptop, and the port is 1883 by default.

```plaintext
mosquitto -c mosquitto.conf -p 1883 -v
```

![MQTT Broker](https://hackster.imgix.net/uploads/attachments/1363638/image_fLbCdHDqL8.png?auto=compress%2Cformat&w=740&h=555&fit=max)

MQTT Broker

> ***Connect to Mosquitto Broker***

If the MQTT publish example works normally on Raspberry Pi Pico, you can see the network information of Raspberry Pi Pico, connecting to the broker and publishing the message.

– Press “**Ctrl+D**” on the terminal window. you can see the messages as follows.

![Pico Run and Client connet](https://hackster.imgix.net/uploads/attachments/1363639/image_DXEiL1wJaW.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Pico Run and Client connet

Subscribe to the broker with the above command. Subscribe will receive a message from the broker.

```plaintext
mosquitto_sub -h 192.168.1.11 -t WIZnetTest
```

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

### **Appendix**

- In Mosquitto versions earlier than 2.0 the default is to allow clients to connect without authentication. In 2.0 and up, you must choose your authentication options explicitly before clients can connect. Therefore, if you are using version 2.0 or later, refer to following link to setup ‘mosquitto.conf’ in the directory where Mosquitto is installed.<https://mosquitto.org/documentation/authentication-methods/>

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

**DOCUMENTS**

Code

WIZnet/RP2040-HAT-CircuitPython[![](https://oldmaker.wiznet.io/wp-content/themes/onepress/assets/images/icon-link.png)](https://github.com/Wiznet/RP2040-HAT-CircuitPython)

Schematics

WIZnet Ethernet HAT

---

Source: https://maker.wiznet.io/WIZnet/projects/wiznet-ethernet-hat%5Brp2040%5D-mqtt-publish-%5Bmosquitto%5D/
