---
title: "CO2_Gateway"
url: "https://maker.wiznet.io/Aimee0/projects/co2-gateway/"
markdown_url: "https://maker.wiznet.io/Aimee0/projects/co2-gateway/md"
type: "UCC: User Created Content"
author: "inmind666"
author_url: "https://gitee.com/inmind666/co2_gateway"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "inmind666"
original_url: "https://gitee.com/inmind666/co2_gateway"
published: "2026-01-29"
language: "en"
hardware: ["WIZnet W5500"]
likes: 0
views: 317
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# CO2_Gateway

> STM32F103 and W5500 based gateway converting RS-485 Modbus sensor data into TCP/IP for smart factory, greenhouse and building monitoring systems.

Original author: inmind666 (source: https://gitee.com/inmind666/co2_gateway)

## Components

- **WIZnet W5500** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5500))

WIZnet parts: W5500 ([Datasheet](https://docs.wiznet.io/Product/Chip/Ethernet/W5500/datasheet?utm_source=maker&utm_medium=project&utm_campaign=w5500), [product hub](https://maker.wiznet.io/products/w5500/))

## Article

![](https://maker.wiznet.io/upload/ckeditor5/806164630%5F1772527663%2Epng)

### 📌 Overview

**STM32F103 + WIZnet W5500** 조합으로 **RS-485(Modbus RTU) 센서 데이터를 이더넷(TCP)으로 연동**하는 “현장 센서 ↔ 네트워크” 게이트웨이 예제입니다. MCU 설정 파일에서 STM32F103C8T6 계열 사용이 확인됩니다.

### 📌 Features

**RS-485(Modbus RTU) 질의/응답 기반 센서값 수집**

- CRC16 계산 후 프레임 송신, 수신 데이터 기반 파싱 구조가 포함됩니다.

**W5500 하드웨어 TCP/IP 오프로딩 기반 TCP Client 통신**

- MCU 부하를 낮추고, 임베디드에서 비교적 단순한 소켓 API로 TCP 연결을 구성합니다.

**멀티 태스크(FreeRTOS) 형태의 기능 분리**

- 통신 수신, 디스플레이, 로컬 온도(DS18B20), RS-485 수집을 태스크로 분리해 확장에 유리합니다.

**로컬 표시(OLED) 및 로컬 온도 센서(DS18B20) 포함**

- 게이트웨이가 단순 중계기 역할을 넘어 **현장 디버깅/상태 확인용 UI**를 가질 수 있는 형태입니다.

**고정 IP/포트 기반의 간단한 서버 연동 뼈대**

- 서버 IP/포트가 코드에 고정된 형태로 존재해, PoC(개념 검증) 구현이 빠릅니다.

### 📌 System Architecture

**구성 요소**

- **MCU:** STM32F103C8T6

- **Ethernet:** WIZnet **W5500** (SPI 연결, CS/RST 핀 사용)

- **Field I/F:** RS-485(UART 기반, Modbus RTU)

- **Local Sensor/UI:** DS18B20(1-Wire), OLED

**데이터 흐름**

- RS-485 센서 → (Modbus RTU 응답) → STM32

- STM32 → (W5500 소켓 send/recv) → TCP 서버

- TCP 서버 → STM32로 데이터 송신 시, 프로젝트는 문자열 파싱(예: co2, temperature 형태) 구조를 포함

- STM32 → OLED에 온도/습도 등 상태 표시

### 📌 Role and Application of the WIZnet's Chip

**사용 칩:WIZnet W5500네트워크에서의 역할:**

- **TCP Client 소켓 통신**(서버 IP/Port로 connect 후 send/recv)

### 📌 Market & Application Value

**적용 산업/시장**

- **스마트 팩토리/빌딩 자동화:** RS-485(센서/인버터/계측기) ↔ Ethernet(상위 관제) 변환 수요가 꾸준합니다.

- **온실/환경 모니터링:** CO2/온습도/공기질 센서가 RS-485(Modbus)로 제공되는 제품군이 존재합니다(센서 시장 일반 정보).

- **레거시 설비 데이터 수집:** “기존 RS-485 장비를 IP로 끌어올리는” 전환 수요

### 📌 WIZnet Strategic Value

**Maker 생태계 관점 의미**

- “W5500 + STM32 + RS-485”는 현장 IoT에서 반복 등장하는 조합이라, **게이트웨이 레퍼런스 템플릿**으로 가치가 있습니다.

- FreeRTOS 태스크 분리 구조는 Maker 사용자에게 “확장 가능한 코드 뼈대”로 교육 효과가 있습니다.

- W5500을 쓰면 고성능 MCU 없이도 **안정적인 이더넷 기반 필드 게이트웨이**를 빠르게 만들 수 있습니다.

### 📌 Summary

이 UCC는 **STM32F103 + W5500 기반 이더넷 게이트웨이**로, RS-485(Modbus) 센서 데이터를 TCP 서버와 연동하는 **현장 IoT 브릿지 구조**를 보여줍니다.

### 📌 FAQ

**Q1. STM32F103 + W5500 CO₂ Gateway 프로젝트는 무엇인가요?**

이 프로젝트는 STM32F103C8T6 MCU와 WIZnet W5500을 사용하여 RS-485(Modbus RTU) 센서 데이터를 TCP 서버로 전송하는 이더넷 게이트웨이 예제입니다.
현장 RS-485 기반 센서 데이터를 IP 네트워크로 변환하는 IoT 브릿지 구조를 구현합니다.

**Q2. 이 게이트웨이는 어떤 통신 구조를 사용하나요?**

게이트웨이는 다음과 같은 구조로 동작합니다:

- RS-485 (UART 기반 Modbus RTU) → STM32 수집

- STM32 → W5500 (SPI 연결) → TCP Client 통신

- TCP 서버 ↔ STM32 (문자열 기반 데이터 송수신)

- 로컬 OLED에 상태 표시

즉, Field Bus(RS-485) ↔ Ethernet(TCP/IP) 변환 구조입니다.

**Q3. WIZnet W5500의 역할은 무엇인가요?**

W5500은 하드웨어 TCP/IP 오프로딩 기능을 가진 SPI 기반 Ethernet 컨트롤러입니다.

이 프로젝트에서 W5500은:

- TCP Client 소켓 생성

- 서버 IP/Port로 connect 수행

- send()/recv() 기반 데이터 송수신 처리

- MCU 부하 감소

를 담당합니다.

**Q4. 왜 W5500을 사용하는 것이 유리한가요?**

W5500은 TCP/IP 스택을 하드웨어로 처리하므로:

- STM32F103과 같은 중급 MCU에서도 안정적인 TCP 통신 가능

- 메모리 사용량 감소

- 소프트웨어 네트워크 스택 구현 부담 제거

- 산업용 네트워크 환경에서 높은 안정성 제공

따라서 저비용 MCU 기반 게이트웨이 설계에 적합합니다.

**Q5. RS-485(Modbus RTU)는 어떻게 처리되나요?**

STM32는 UART 기반 RS-485 인터페이스를 통해 Modbus RTU 질의/응답을 수행합니다.

구현 특징:

- CRC16 계산 후 프레임 전송

- 수신 데이터 파싱 구조 포함

- CO₂, 온도 등 센서 값 추출

이를 통해 필드 센서 데이터를 디지털 네트워크로 변환합니다.

---

### 📌 Overview

This is an example of a “field sensor ↔ network” gateway that links RS-485 (Modbus RTU) sensor data to Ethernet (TCP) using a combination of STM32F103 + WIZnet W5500. It is confirmed from the MCU configuration file that the STM32F103C8T6 series is used.

### 📌 Features

**RS-485 (Modbus RTU) query/response-based sensor data collection**

- Includes a structure for transmitting frames after CRC16 calculation and parsing based on received data.

**TCP client communication based on W5500 hardware TCP/IP offloading**

- Reduces MCU load and enables TCP connection setup using a relatively simple socket API in embedded systems.

**Multi-task structure (FreeRTOS-based functional separation)**

- Separates communication reception, display, local temperature (DS18B20), and RS-485 collection into individual tasks, making it advantageous for scalability.

**Includes local display (OLED) and local temperature sensor (DS18B20)**

- Allows the gateway to go beyond a simple relay and provide a UI for on-site debugging and status monitoring.

**Basic server integration structure based on fixed IP/port**

- Server IP and port are hardcoded in the firmware, enabling rapid PoC (proof-of-concept) implementation.

### 📌 System Architecture

**Components**

- MCU: STM32F103C8T6

- Ethernet: WIZnet W5500 (SPI connection, using CS/RST pins)

- Field I/F: RS-485 (UART-based, Modbus RTU)

- Local Sensor/UI: DS18B20 (1-Wire), OLED

**Data Flow**

- RS-485 sensor → (Modbus RTU response) → STM32

- STM32 → (W5500 socket send/recv) → TCP server

- When the TCP server sends data to STM32, the project includes a string parsing structure (e.g., in the form of `co2`, `temperature`)

- STM32 → Displays temperature/humidity and other status information on the OLED

### 📌 Role and Application of the WIZnet's Chip

**Chip used: WIZnet W5500Role in the network:**

- TCP client socket communication (connect to server IP/port, then perform send/recv)

### 📌 Market & Application Value

**Applicable Industries/Markets**

- **Smart factory/building automation**: There is steady demand for converting RS-485 (sensors/inverters/meters) ↔ Ethernet (upper-level control/monitoring systems).

- **Greenhouse/environmental monitoring**: There are product lines where CO2, temperature/humidity, and air quality sensors are provided via RS-485 (Modbus) (general information about the sensor market).

- **Legacy equipment data acquisition**: Demand for transitioning “existing RS-485 devices to IP-based networks.”

### 📌 WIZnet Strategic Value

**Significance from the Maker ecosystem perspective**

- “W5500 + STM32 + RS-485” is a frequently recurring combination in field IoT, giving it value as a gateway reference template.

- The FreeRTOS task separation structure provides educational value to Maker users as a “scalable code framework.”

- By using the W5500, it is possible to quickly build a stable Ethernet-based field gateway without requiring a high-performance MCU.

### 📌 Summary

This UCC presents a field IoT bridge architecture based on an STM32F103 + W5500 Ethernet gateway, linking RS-485 (Modbus) sensor data with a TCP server.

### 📌 FAQ

**Q1. What is the STM32F103 + W5500 CO₂ Gateway project?**

This project is an Ethernet gateway example that uses the STM32F103C8T6 MCU and the WIZnet W5500 to transmit RS-485 (Modbus RTU) sensor data to a TCP server.
It implements an IoT bridge architecture that converts field RS-485-based sensor data into an IP network.

**Q2. What communication architecture does this gateway use?**

The gateway operates with the following structure:

- RS-485 (UART-based Modbus RTU) → Data collected by STM32

- STM32 → W5500 (SPI connection) → TCP client communication

- TCP server ↔ STM32 (string-based data transmission and reception)

- Local status displayed on OLED

In other words, it implements a Field Bus (RS-485) ↔ Ethernet (TCP/IP) conversion architecture.

**Q3. What is the role of the WIZnet W5500?**

The W5500 is an SPI-based Ethernet controller with hardware TCP/IP offloading capability.

In this project, the W5500 is responsible for:

Creating TCP client sockets

Connecting to the server IP/port

Handling data transmission and reception using send()/recv()

Reducing MCU load

**Q4. Why is it advantageous to use the W5500?**

Since the W5500 processes the TCP/IP stack in hardware:

- Stable TCP communication is possible even with mid-range MCUs like the STM32F103

- Reduced memory usage

- Eliminates the burden of implementing a software network stack

- Provides high stability in industrial network environments

Therefore, it is well suited for low-cost MCU-based gateway designs.

**Q5. How is RS-485 (Modbus RTU) handled?**

The STM32 performs Modbus RTU query/response communication through a UART-based RS-485 interface.

Implementation features:

- Frame transmission after CRC16 calculation

- Includes a structure for parsing received data

- Extracts sensor values such as CO₂ and temperature

Through this process, field sensor data is converted into a digital IP-based network format.

---

Source: https://maker.wiznet.io/Aimee0/projects/co2-gateway/
