Wiznet makers

gunn

Published March 07, 2026 ©

64 UCC

0 VAR

0 Contests

0 Followers

0 Following

Original Link

STM32+W5500以太网芯片配置实现MQTT通讯(二)

STM32 + W5500 이더넷 칩 설정을 통한 MQTT 통신 구현
Implementation of MQTT Communication via STM32 + W5500 Ethernet Chip Configuration (Part 2)

COMPONENTS Hardware components

WIZnet - W5500

x 1


PROJECT DESCRIPTION

Title : Implementation of MQTT Communication via STM32 + W5500 Ethernet Chip Configuration (Part 2)
*(Original: STM32+W5500以太网芯片配置实现MQTT通讯(二))*

---

Key Content Summary

This article is the second part of a practical tutorial covering how to communicate using the MQTT protocol with an STM32 microcontroller and a W5500 Ethernet chip.

1. Hardware and Basic Setup

* Utilizing the W5500 Chip: The W5500 Ethernet chip, which supports a hardware TCP/IP stack, is connected to the STM32 via an SPI interface.
* Prerequisites: The guide assumes that the basic W5500 driver and Ping function implementation (covered in the previous post) are already completed.

2. Software Configuration and MQTT Porting

* Porting the MQTT Library: It explains the process of including the official MQTT source code in the project and configuring the header file paths.
* Application Layer Implementation: It creates `mqtt_app.c` and `mqtt_app.h` files to implement core functions:
* Connection Management: Establishes a TCP connection and then connects to the MQTT broker (server).
* Message Subscription: Subscribes to specific topics and processes (prints) data through a callback function (`messageArrived`) when a message is received.
* Message Publishing: Composes temperature data or time information in JSON format and sends it to the server periodically (every 10 seconds).
* Keep-Alive (Maintenance): Uses the `MQTTYield` function to maintain the heartbeat and continuously handle network events to ensure the connection remains active.

 

3. Server Setup and Experimental Results

* EMQX Broker: Configures a test environment by deploying an EMQX server locally or in the cloud.
* Operation Verification: Monitors the network initialization, successful MQTT connection, and the process of data publishing/receiving through a serial monitor log.

Conclusion

This post serves as a guide for developers looking to build stable, wired network-based IoT devices using the STM32 and W5500 combination, providing specific code examples and implementation procedures. It covers the entire process from library porting to periodic data reporting.

====

2026년 3월 3일 12시 56분 34초에 게시됨 · 786회 조회

====

이 글은 STM32 마이크로컨트롤러와 W5500 이더넷 칩을 이용해 MQTT 통신을 구현하는 방법을 설명한 IoT 실습 튜토리얼입니다.


이전 글에서 Ping 통신을 구현한 상태를 기반으로 MQTT 기능을 추가합니다.

(1) 시스템 구성

MCU: STM32

Ethernet 칩: W5500

통신 방식: SPI

프로토콜: MQTT

즉, STM32 + W5500 → MQTT 브로커와 IoT 메시지 통신 구조입니다.


(2) 구현된 주요 기능

글에서는 MQTT 클라이언트 기능을 다음과 같이 구현합니다.

① MQTT 연결 관리

MQTT 브로커와 연결

네트워크 연결 상태 관리

② Topic 구독 (Subscribe)

특정 Topic 메시지를 수신

메시지 수신 시 payload 출력

예:

Topic: xxx
Payload: xxx

③ 메시지 발행 (Publish)

특정 Topic으로 메시지 전송

QoS 0 방식 사용 (최대 1회 전달)

예:

mqtt_publish(topic, payload)

④ MQTT Keep Alive 처리

메인 루프에서 다음 함수를 호출해 연결 유지

MQTTYield(&client, 100);

⑤ 주기적 데이터 전송

예시 코드에서는 10초마다 데이터 전송

{
"temp":25.5,
"time":12345
}

 

즉 IoT 센서 데이터를 MQTT로 전송하는 구조입니다.


3️⃣ 글의 핵심 목적

이 글의 목적은 다음입니다.

STM32 + W5500 기반 IoT 장치가 MQTT를 이용해 서버와 데이터를 주고받도록 구현하는 방법 설명

구체적으로는

1️⃣ W5500 기반 Ethernet 통신
2️⃣ MQTT 클라이언트 구현
3️⃣ IoT 데이터 송수신

을 단계적으로 설명합니다.


4️⃣ IoT 관점에서 의미

이 글이 보여주는 IoT 구조는 매우 전형적인 구조입니다.

Sensor (STM32)
     ↓
W5500 Ethernet
     ↓
MQTT Broker
     ↓
Cloud / Server

유선 IoT 장치 → MQTT → 서버 구조입니다. 

 

[FAQ]

Q) EMQX 가 무슨 역할을 하는 프로그램이야?

A) 

EMQX는 사물인터넷(IoT) 환경에서 수많은 기기들이 서로 데이터를 주고받을 수 있게 해주는 'MQTT 브로커(Broker)' 프로그램입니다.

쉽게 비유하자면, 수만 명의 우체국 직원이 상주하며 전 세계에서 오는 편지를 실시간으로 분류해 정확한 주소로 배달해 주는 '초고속 디지털 우체국'과 같습니다.

 

 

Documents
Comments Write