Wiznet makers

mark

Published May 16, 2026 ©

106 UCC

8 WCC

42 VAR

0 Contests

0 Followers

0 Following

Original Link

How to Prepare MQTT Messaging with WIZnet W5500 on AI8051U?

This AI8051U maker project prepares an MQTT test environment for a WIZnet W5500 Ethernet application by setting up EMQX on Windows.

COMPONENTS
PROJECT DESCRIPTION

How to Prepare MQTT Messaging with WIZnet W5500 on AI8051U?

Summary

This AI8051U maker project prepares an MQTT test environment for a WIZnet W5500 Ethernet application by setting up EMQX on Windows. The accessible source confirms the project goal is to learn EMQX usage for a W5500 MQTT workflow, while W5500’s role is to provide the wired TCP transport path between the AI8051U firmware and the MQTT broker. The article does not expose the full AI8051U firmware source, so project-specific W5500 code cannot be verified from the public page.

What the Project Does

The project is an early-stage MQTT preparation step for an AI8051U + W5500 workflow. The linked article is titled as a W5500 MQTT protocol preparation project and states its learning objective as using EMQX software on Windows. In practical terms, this prepares the broker side before the embedded board connects as an MQTT client.

The network flow is expected to be: AI8051U firmware controls W5500 over SPI, W5500 opens a TCP connection to the EMQX broker, the MQTT client sends a CONNECT packet, and then the device publishes or subscribes to MQTT topics. The accessible article focuses on EMQX rather than MCU code; it describes EMQX as an MQTT middleware for IoT scenarios and lists support for MQTT 3.1, 3.1.1, and 5.0.

For a maker project, this split is useful. The PC-side broker can be tested first, then the AI8051U + W5500 firmware can be added later. That reduces bring-up risk because broker installation, topic routing, client identity, and payload inspection can be verified before debugging SPI, socket state, or embedded MQTT packet handling.

Where WIZnet Fits

The exact WIZnet product is W5500. In this architecture, W5500 is the wired Ethernet controller and hardwired TCP/IP engine used by the AI8051U firmware to reach the MQTT broker. MQTT itself runs above TCP, so W5500’s main job is not MQTT parsing; it is the TCP socket transport that carries MQTT CONNECT, PUBLISH, SUBSCRIBE, PINGREQ, and DISCONNECT packets.

W5500 is suitable for this role because it provides hardwired TCP/IP, an SPI interface up to 80 MHz, embedded 10/100 Ethernet MAC and PHY, 8 independent sockets, and 32 KB of internal Tx/Rx buffer memory. WIZnet also documents ioLibrary as an MCU-independent library for WIZnet W5x00 and W6x00 chips, with supported services including MQTT.

For firmware performance, this matters because the AI8051U can treat the network path as a socket-driven peripheral. The MCU still owns MQTT session logic, keep-alive timing, reconnect policy, topic selection, and payload formatting, but W5500 handles the Ethernet-side TCP/IP work and packet buffering. This keeps the embedded firmware smaller than a design that places the full TCP/IP stack inside the MCU.

Implementation Notes

The accessible source confirms the W5500 MQTT preparation goal, but it does not expose complete AI8051U source files. The following code is not copied from the project.

Conceptual integration example based on WIZnet ioLibrary

 
#include "wizchip_conf.h"
#include "socket.h"
#include "MQTTClient.h"

#define MQTT_SOCKET     0
#define MQTT_PORT       1883

static uint8_t tx_size[8] = {2,2,2,2,2,2,2,2};
static uint8_t rx_size[8] = {2,2,2,2,2,2,2,2};

void w5500_init_for_mqtt(void)
{
    reg_wizchip_cs_cbfunc(w5500_select, w5500_deselect);
    reg_wizchip_spi_cbfunc(w5500_spi_read, w5500_spi_write);

    wizchip_init(tx_size, rx_size);
    wizchip_setnetinfo(&net_info);
}
 

This layer exists because WIZnet ioLibrary is platform-independent. The AI8051U must provide chip-select and SPI read/write functions before W5500 socket APIs can operate. WIZnet’s ioLibrary repository describes the driver as an “Internet Offload Library” for WIZnet chips including W5500 and provides Berkeley-style socket APIs.

 
Network net;
MQTTClient client;
uint8_t send_buf[256];
uint8_t recv_buf[512];

void mqtt_connect_to_emqx(uint8_t broker_ip[4])
{
    NewNetwork(&net, MQTT_SOCKET);
    ConnectNetwork(&net, broker_ip, MQTT_PORT);

    MQTTClientInit(&client, &net, 1000,
                   send_buf, sizeof(send_buf),
                   recv_buf, sizeof(recv_buf));

    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
    data.MQTTVersion = 4;
    data.clientID.cstring = "ai8051u-w5500";
    data.keepAliveInterval = 60;
    data.cleansession = 1;

    MQTTConnect(&client, &data);
}
 

This conceptual MQTT layer follows the WIZnet ioLibrary MQTT interface model. The official MQTT interface defines NewNetwork(), ConnectNetwork(), W5x00 read/write functions, and a timer handler, while MQTTClient.h exposes MQTTClientInit(), MQTTConnect(), MQTTPublish(), MQTTSubscribe(), and MQTTYield().

For performance testing, the key firmware measurements should be MQTT reconnect time, publish latency, keep-alive stability, socket recovery after broker restart, and SPI utilization during payload transfer. W5500 has internal buffers, but the application still needs bounded MQTT packet buffers on the MCU side.

Practical Tips / Pitfalls

  • Verify EMQX locally before debugging the board. A desktop MQTT client should be able to connect, publish, and subscribe before the AI8051U firmware is tested.
  • Confirm W5500 SPI register access first. MQTT failures are meaningless if the MCU cannot read W5500 registers reliably.
  • Keep the broker IP stable during bring-up. Use a fixed Windows LAN IP or DHCP reservation so the embedded firmware does not chase a changing broker address.
  • Reserve one W5500 socket for MQTT and document it. W5500 has 8 sockets, but MQTT needs a long-lived TCP connection.
  • Implement MQTT keep-alive deliberately. If MQTTYield() or equivalent processing is not called often enough, the broker may close the session.
  • Size MQTT buffers around the largest expected topic plus payload, not only around a simple demo string.
  • Test broker restart and cable removal. Maker projects often work once, but reliable firmware needs reconnect logic after TCP disconnects, PHY link loss, or EMQX restart.

FAQ

Q: Why use WIZnet W5500 for MQTT on AI8051U?
A: MQTT runs over TCP, and W5500 provides the wired TCP socket path, Ethernet MAC/PHY, hardwired TCP/IP engine, and internal packet buffers. This lets the AI8051U firmware focus on MQTT session behavior, payload formatting, and device logic rather than maintaining the full TCP/IP stack in MCU software.

Q: How does W5500 connect to the AI8051U platform?
A: W5500 connects through SPI, plus chip select, reset, interrupt, power, ground, and the Ethernet transformer/RJ45 path. In firmware, the AI8051U must register W5500 chip-select and SPI read/write callbacks before using socket or MQTT client functions.

Q: What role does W5500 play in this project?
A: W5500 is the TCP transport device between the AI8051U and the EMQX MQTT broker. EMQX handles broker-side topic routing, while W5500 handles the embedded wired Ethernet path that carries MQTT packets over TCP.

Q: Can beginners follow this maker project?
A: Yes, if they separate the work into stages: install and test EMQX on Windows, verify W5500 SPI access, configure IP settings, open a TCP socket, then add MQTT CONNECT and publish/subscribe logic. The public article is mainly broker preparation, so beginners will still need a W5500 firmware reference when moving to the embedded side.

Q: How does W5500 compare with an LwIP-based MQTT design?
A: With W5500, TCP/IP handling and socket buffers are in the Ethernet controller, so the AI8051U mainly drives SPI and MQTT state. With LwIP, the MCU owns more of the stack integration, including packet buffers such as pbuf, memory pools, protocol timers, and network-interface handling; that is flexible, but it adds more firmware and RAM work before MQTT can run.

Source

Original article: CSDN, “[AI8051U入门第九步]W5500实现MQTT协议(前期准备工程)-EMQX在Windows下使用教程,” published on 2025-07-24. The accessible page confirms the EMQX-on-Windows learning objective and W5500 MQTT context, but the full article content is behind CSDN subscription access.

WIZnet product reference: W5500 documentation.

WIZnet driver reference: Wiznet/ioLibrary_Driver, MIT license.

WIZnet MQTT interface reference: ioLibrary MQTT files.

Tags

#W5500 #WIZnet #AI8051U #MQTT #EMQX #Ethernet #SPI #ioLibrary #EmbeddedC #Maker #NetworkStack #Firmware #Performance #LwIP

 

AI8051U에서 WIZnet W5500으로 MQTT 메시징을 준비하는 방법은?

요약

이 AI8051U 메이커 프로젝트는 WIZnet W5500 이더넷 애플리케이션에서 MQTT를 테스트하기 위해 Windows 환경에 EMQX를 설정하는 준비 단계입니다. 접근 가능한 원문에서는 W5500 MQTT 워크플로우를 위한 EMQX 사용법 학습이 프로젝트 목표임을 확인할 수 있습니다. 이 구조에서 W5500은 AI8051U 펌웨어와 MQTT 브로커 사이의 유선 TCP 전송 경로를 제공합니다. 원문 공개 페이지에서는 전체 AI8051U 펌웨어 소스가 제공되지 않으므로, 프로젝트별 W5500 코드는 직접 검증할 수 없습니다.

프로젝트가 하는 일

이 프로젝트는 AI8051U + W5500 기반 MQTT 워크플로우의 초기 준비 단계입니다. 원문 글은 W5500 MQTT 프로토콜 준비 프로젝트로 구성되어 있으며, Windows에서 EMQX 소프트웨어를 사용하는 것을 학습 목표로 제시합니다. 실제 개발 흐름에서는 임베디드 보드가 MQTT 클라이언트로 접속하기 전에 브로커 측 환경을 먼저 준비하는 단계입니다.

예상되는 네트워크 흐름은 다음과 같습니다. AI8051U 펌웨어가 SPI로 W5500을 제어하고, W5500이 EMQX 브로커로 TCP 연결을 엽니다. 이후 MQTT 클라이언트가 CONNECT 패킷을 전송하고, 장치는 MQTT topic에 publish 또는 subscribe합니다. 접근 가능한 원문은 MCU 코드보다 EMQX 설정에 집중하며, EMQX를 IoT 시나리오에서 사용하는 MQTT 미들웨어로 설명하고 MQTT 3.1, 3.1.1, 5.0 지원을 언급합니다.

메이커 프로젝트에서는 이런 분리 방식이 유용합니다. PC 측 브로커를 먼저 테스트한 뒤 AI8051U + W5500 펌웨어를 연결할 수 있기 때문입니다. 이렇게 하면 SPI, 소켓 상태, 임베디드 MQTT 패킷 처리를 디버깅하기 전에 브로커 설치, topic 라우팅, client identity, payload 확인을 먼저 검증할 수 있습니다.

WIZnet이 들어가는 위치

이 프로젝트에서 사용되는 WIZnet 제품은 W5500입니다. 이 구조에서 W5500은 AI8051U 펌웨어가 MQTT 브로커에 접근하기 위해 사용하는 유선 이더넷 컨트롤러이자 하드웨어 TCP/IP 엔진입니다. MQTT 자체는 TCP 위에서 동작하므로, W5500의 주 역할은 MQTT 파싱이 아니라 MQTT CONNECT, PUBLISH, SUBSCRIBE, PINGREQ, DISCONNECT 패킷을 운반하는 TCP 소켓 전송입니다.

W5500은 이 역할에 적합합니다. W5500은 하드웨어 TCP/IP, 최대 80 MHz SPI 인터페이스, 내장 10/100 Ethernet MAC 및 PHY, 8개 독립 소켓, 32 KB 내부 Tx/Rx 버퍼 메모리를 제공합니다. WIZnet ioLibrary는 W5x00 및 W6x00 칩을 위한 MCU 독립형 라이브러리이며, MQTT를 포함한 네트워크 서비스를 지원합니다.

펌웨어 성능 관점에서도 이 구조는 의미가 있습니다. AI8051U는 네트워크 경로를 소켓 기반 주변장치처럼 다룰 수 있습니다. MCU는 여전히 MQTT 세션 로직, keep-alive 타이밍, 재연결 정책, topic 선택, payload 포맷을 담당하지만, W5500은 이더넷 측 TCP/IP 처리와 패킷 버퍼링을 담당합니다. 따라서 전체 TCP/IP 스택을 MCU 내부에 올리는 설계보다 임베디드 펌웨어를 더 작고 명확하게 유지할 수 있습니다.

구현 참고 사항

접근 가능한 원문에서는 W5500 MQTT 준비 목표를 확인할 수 있지만, 전체 AI8051U 소스 파일은 공개되어 있지 않습니다. 따라서 아래 코드는 해당 프로젝트에서 복사한 코드가 아닙니다.

WIZnet ioLibrary 기반 개념적 통합 예제

 
#include "wizchip_conf.h"
#include "socket.h"
#include "MQTTClient.h"

#define MQTT_SOCKET     0
#define MQTT_PORT       1883

static uint8_t tx_size[8] = {2,2,2,2,2,2,2,2};
static uint8_t rx_size[8] = {2,2,2,2,2,2,2,2};

void w5500_init_for_mqtt(void)
{
    reg_wizchip_cs_cbfunc(w5500_select, w5500_deselect);
    reg_wizchip_spi_cbfunc(w5500_spi_read, w5500_spi_write);

    wizchip_init(tx_size, rx_size);
    wizchip_setnetinfo(&net_info);
}
 

이 계층은 WIZnet ioLibrary가 플랫폼 독립 구조이기 때문에 필요합니다. AI8051U는 W5500 소켓 API를 사용하기 전에 칩 셀렉트와 SPI 읽기/쓰기 함수를 제공해야 합니다. WIZnet ioLibrary는 W5500을 포함한 WIZnet 칩용 Internet Offload Library이며 Berkeley 스타일 소켓 API를 제공합니다.

 
Network net;
MQTTClient client;
uint8_t send_buf[256];
uint8_t recv_buf[512];

void mqtt_connect_to_emqx(uint8_t broker_ip[4])
{
    NewNetwork(&net, MQTT_SOCKET);
    ConnectNetwork(&net, broker_ip, MQTT_PORT);

    MQTTClientInit(&client, &net, 1000,
                   send_buf, sizeof(send_buf),
                   recv_buf, sizeof(recv_buf));

    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
    data.MQTTVersion = 4;
    data.clientID.cstring = "ai8051u-w5500";
    data.keepAliveInterval = 60;
    data.cleansession = 1;

    MQTTConnect(&client, &data);
}
 

이 개념적 MQTT 계층은 WIZnet ioLibrary MQTT 인터페이스 모델을 따릅니다. MQTT 인터페이스는 NewNetwork(), ConnectNetwork(), W5x00 read/write 함수, timer handler를 사용하며, MQTTClient.hMQTTClientInit(), MQTTConnect(), MQTTPublish(), MQTTSubscribe(), MQTTYield() 같은 함수를 제공합니다.

성능 테스트에서는 MQTT 재연결 시간, publish 지연, keep-alive 안정성, 브로커 재시작 후 소켓 복구, payload 전송 중 SPI 사용량을 확인하는 것이 좋습니다. W5500은 내부 버퍼를 제공하지만, 애플리케이션은 MCU 측에서도 제한된 MQTT 패킷 버퍼를 안전하게 관리해야 합니다.

실무 팁 / 주의점

  • 보드를 디버깅하기 전에 EMQX를 로컬에서 먼저 검증해야 합니다. 데스크톱 MQTT 클라이언트가 connect, publish, subscribe를 정상 수행해야 합니다.
  • W5500 SPI 레지스터 접근을 먼저 확인해야 합니다. MCU가 W5500 레지스터를 안정적으로 읽지 못하면 MQTT 오류 분석은 의미가 없습니다.
  • bring-up 단계에서는 브로커 IP를 고정하는 것이 좋습니다. Windows LAN IP를 고정하거나 DHCP reservation을 사용하면 임베디드 펌웨어가 변경되는 브로커 주소를 따라가지 않아도 됩니다.
  • MQTT용 W5500 소켓 하나를 예약하고 문서화해야 합니다. W5500은 8개 소켓을 제공하지만, MQTT는 장시간 유지되는 TCP 연결을 필요로 합니다.
  • MQTT keep-alive를 명확히 구현해야 합니다. MQTTYield() 또는 이에 해당하는 처리가 충분히 자주 호출되지 않으면 브로커가 세션을 종료할 수 있습니다.
  • MQTT 버퍼 크기는 단순 데모 문자열이 아니라 최대 topic 길이와 payload 크기를 기준으로 정해야 합니다.
  • 브로커 재시작과 케이블 분리를 테스트해야 합니다. 메이커 프로젝트는 한 번 연결되면 성공처럼 보이지만, 안정적인 펌웨어는 TCP disconnect, PHY link loss, EMQX restart 이후 재연결 로직을 가져야 합니다.

FAQ

Q: AI8051U에서 MQTT를 구현할 때 왜 WIZnet W5500을 사용하나요?
A: MQTT는 TCP 위에서 동작하며, W5500은 유선 TCP 소켓 경로, Ethernet MAC/PHY, 하드웨어 TCP/IP 엔진, 내부 패킷 버퍼를 제공합니다. AI8051U 펌웨어는 전체 TCP/IP 스택을 MCU 소프트웨어로 유지하지 않고 MQTT 세션 동작, payload 포맷, 장치 로직에 집중할 수 있습니다.

Q: W5500은 AI8051U 플랫폼에 어떻게 연결하나요?
A: W5500은 SPI, 칩 셀렉트, 리셋, 인터럽트, 전원, GND, 이더넷 트랜스포머 및 RJ45 경로를 통해 연결합니다. 펌웨어에서는 소켓 또는 MQTT 클라이언트 함수를 사용하기 전에 AI8051U의 W5500 칩 셀렉트 및 SPI 읽기/쓰기 콜백을 등록해야 합니다.

Q: 이 프로젝트에서 W5500은 어떤 역할을 하나요?
A: W5500은 AI8051U와 EMQX MQTT 브로커 사이의 TCP 전송 장치입니다. EMQX는 브로커 측 topic 라우팅을 처리하고, W5500은 MQTT 패킷을 TCP로 운반하는 임베디드 유선 이더넷 경로를 담당합니다.

Q: 초보자도 이 메이커 프로젝트를 따라할 수 있나요?
A: 가능합니다. 다만 작업을 단계별로 나누는 것이 좋습니다. 먼저 Windows에서 EMQX를 설치하고 테스트한 뒤, W5500 SPI 접근을 확인하고, IP 설정을 구성하고, TCP 소켓을 연 다음 MQTT CONNECT와 publish/subscribe 로직을 추가하는 순서가 적합합니다. 공개 원문은 주로 브로커 준비 단계이므로, 임베디드 단계로 넘어갈 때는 별도의 W5500 펌웨어 참고 자료가 필요합니다.

Q: W5500 방식은 LwIP 기반 MQTT 설계와 어떻게 다른가요?
A: W5500을 사용하면 TCP/IP 처리와 소켓 버퍼가 이더넷 컨트롤러 내부에 있으므로 AI8051U는 주로 SPI와 MQTT 상태를 구동합니다. LwIP를 사용하면 MCU가 pbuf 같은 패킷 버퍼, 메모리 풀, 프로토콜 타이머, 네트워크 인터페이스 처리를 더 많이 담당합니다. 이 방식은 유연하지만 MQTT를 실행하기 전까지 더 많은 펌웨어와 RAM 통합 작업이 필요합니다.

출처

Original article: CSDN, “[AI8051U入门第九步]W5500实现MQTT协议(前期准备工程)-EMQX在Windows下使用教程,” 2025-07-24 게시. 접근 가능한 페이지에서는 Windows 환경의 EMQX 학습 목표와 W5500 MQTT 맥락을 확인할 수 있지만, 전체 글 내용은 CSDN 구독 접근 뒤에 있습니다.
https://blog.csdn.net/sinat_58149788/article/details/149600598

WIZnet product reference: W5500 documentation.
https://docs.wiznet.io/Product/Chip/Ethernet/W5500

WIZnet driver reference: Wiznet/ioLibrary_Driver, MIT license.
https://github.com/Wiznet/ioLibrary_Driver

WIZnet MQTT interface reference: ioLibrary MQTT files.
https://raw.githubusercontent.com/Wiznet/ioLibrary_Driver/master/Internet/MQTT/mqtt_interface.h

태그

#W5500 #WIZnet #AI8051U #MQTT #EMQX #Ethernet #SPI #ioLibrary #EmbeddedC #Maker #NetworkStack #Firmware #Performance #LwIP

Documents
Comments Write