Wiznet makers

Hannah

Published February 20, 2026 ©

69 UCC

22 WCC

1 VAR

0 Contests

0 Followers

0 Following

ioNIC MQTT Client Arduino Example

The W55RP20-S2E operates as an MQTT client and publishes messages to, and subscribes to topics from, an MQTT broker.

COMPONENTS Hardware components

WIZnet - W55RP20-EVB-Pico

x 1

Software Apps and online services

Arduino - Arduino IDE

x 1


PROJECT DESCRIPTION

How to MQTT 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 MQTT client mode. 

After the MQTT client configuration is completed, the W55RP20-S2E connects to an MQTT broker running on a PC. 

When a message is published to a subscribed topic from the MQTT broker, 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 configured topic via the MQTT broker.

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: Arduino IDE Setup

Install Board Support Package

  1. Open Arduino IDE
  2. Go to File → Preferences
  3. Add the following to "Additional Boards Manager URLs": https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
  4. Go to Tools → Board → Boards Manager
  5. Search for "Raspberry Pi Pico" and install Raspberry Pi Pico/RP2040 by Earle F. Philhower, III
  6. Select Tools → Board → Raspberry Pi RP2040 Boards → Raspberry Pi Pico

Step 4: Code Examples

Each example provides a .ino file to upload to the Pico.

  1. SPI Communication
  2. UART Communication

 

Step 5: Setup MQTT Client Example

 

PC(Mosquitto)

Execute the following command to start the MQTT broker using Mosquitto.

If the MQTT broker starts successfully, the broker’s IP address will be the current IP address of your desktop or laptop, and the default port is 1883.

 ## Windows cmd.exe 
 #Mosquitto Broker

> mosquitto -c mosquitto.conf -v

 

Step 6: Upload and Test

6.1 Select Raspberry Pi Pico

  1. Go to Tools → Board → Raspberry Pi RP2040 Boards → Raspberry Pi Pico
  2. Select Tools → Port → Choose your COM port

6.2 Upload Code

  1. Open the desired example .ino file
  2. Modify IP addresses and port numbers as needed
// MQTT broker config
static const char *BROKER_HOST = "192.168.11.100";
static const char *BROKER_PORT = "1883";
static const char *MQTT_USER = "user";
static const char *MQTT_PASS = "";
static const char *MQTT_CLIENT_ID = "pico-spi";
static const char *MQTT_KEEPALIVE = "60";
static const char *MQTT_PUB_TOPIC = "/w55rp20/pub";
static const char *MQTT_SUB_TOPIC = "/w55rp20/sub";
static const char *MQTT_PAYLOAD = "hello from pico-spi\r\n"; 
void setup() {
...
  at_set("LI192.168.11.2"); 
  at_set("SM255.255.255.0");
  at_set("GW192.168.11.1");
  at_set("DS8.8.8.8");
...
}

3. Click Upload button or press Ctrl+U

4. Wait for upload to complete

6.3 Open Serial Monitor

  1. Go to Tools → Serial Monitor
  2. Set baud rate to 115200
  3. Verify network information and connection status

Step 7: Run

1. Configuring the W55RP20 S2E as a MQTT Client and Setting Up the Network with AT command.

2. After the W55RP20-S2E is configured as an MQTT client and successfully connects to the MQTT broker running on the PC, the Windows terminal displays a message as shown below.

3. After starting the Mosquitto MQTT broker on the PC, open two separate terminal windows.

In one terminal window, use the mosquitto_sub command to subscribe to a specific topic.
In the other terminal window, use the mosquitto_pub command to publish a message (e.g., “Hello World!”) to the same topic.

The published message is delivered to the subscribed W55RP20-S2E module through the MQTT broker.

> mosquitto_sub -h 192.168.11.100 -p 1883 -t /w55rp20/pub
> mosquitto_pub -h 192.168.11.100 -p 1883 -t /w55rp20/sub -m "Hello World!"

 

4. The W55RP20-S2E receives messages from a subscribed topic through the MQTT broker and forwards them to the Raspberry Pi Pico via 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.

5. The W55RP20-S2E publishes the response message received via UART to the configured topic through the MQTT broker.

Afterward, the published message can be verified in the terminal window that is subscribing to the same topic using the mosquitto_sub command.

Documents
  • ioNIC MQTT arduino example

Comments Write