EthWiFiManager
EthWiFiManager enables Ethernet-first connectivity on ESP32, with automatic Wi-Fi fallback to maintain stable network access in industrial environments.
0
Project description

๐ Overview
EthWiFiManager๋ ESP32์์ โ์ ์ (SPI Ethernet) ์ฐ์ + Wi-Fi ์๋ ํด๋ฐฑ(fallback)โ ์ฐ๊ฒฐ ์ ์ฑ ์ ์ ๊ณตํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋๋ค. ์ฆ, ํ์์๋ W5500 ๊ฐ์ SPI ์ด๋๋ท์ ์ฃผ ์ฐ๊ฒฐ๋ก ์ฐ๊ณ , ์ผ์ด๋ธ ๋จ์ /์ค์์น ์ฅ์ ๋ฑ์ผ๋ก ์ ์ ์ด ๋ถ์์ ํด์ง๋ฉด Wi-Fi๋ก ์๋ ์ ํํ๋ ๋ฐฉ์์ ๋๋ค.
๐ Features
- ์ ์ ์ฐ์ + Wi-Fi ํด๋ฐฑ(Combined mode): ๊ธฐ๋ณธ์ ์ด๋๋ท์ ์ฐ์ ์ฌ์ฉํ๊ณ ์ฅ์ ์ Wi-Fi๋ก ์๋ ์ ํํฉ๋๋ค.
- Wi-Fi Only ๋ชจ๋ ์ง์: ์ค์ ์ผ๋ก ์ด๋๋ท์ ๋นํ์ฑํํ๊ณ Wi-Fi๋ง ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค.
- DHCP ๊ธฐ๋ณธ ์ง์(์ ์ /๋ฌด์ ๋ชจ๋): ํ์ฅ ์ค์น ์ ๋คํธ์ํฌ ์ค์ ๋ถ๋ด์ ์ค์ ๋๋ค.
- ์ ์ /๋ฌด์ ๊ฐ๊ฐ Static IP ์ต์ ์ ๊ณต: ๊ณ ์ IP๊ฐ ํ์ํ ์ค๋น๋ง(OT๋ง)์์๋ ์ ์ฉ ์ฌ์ง๊ฐ ์์ต๋๋ค.
- WiFi์ ์ ์ฌํ ๋จ์ API:
begin(),status(),localIP()๋ฑ ์ต์ ํ์ต์ผ๋ก ์ ์ฉ ๊ฐ๋ฅํ ํํ์ ๋๋ค. - AP Router ๋ชจ๋ ์ง์ (์ต์ ๊ธฐ๋ฅ) : ์กฐ๊ฑด๋ถ ์ปดํ์ผ ์ ESP32๊ฐ Wi-Fi AP๋ฅผ ์์ฑํ๊ณ , Ethernet์ WAN์ผ๋ก ์ฌ์ฉํ์ฌ ์ํ NAT Router๋ก ๋์ํ ์ ์์ต๋๋ค.
๐ System Architecture
๊ตฌ์ฑ ์์
- ESP32(MCU/SoC) + SPI Ethernet ๋ชจ๋(W5500 ๋ฑ) + ๋ด์ฅ Wi-Fi
- ์ค์์น/๋ผ์ฐํฐ(์ ์ ๋ง) ๋ฐ Wi-Fi AP(๋ฌด์ ๋ง)
- ์์ ์๋ฒ/ํด๋ผ์ฐ๋(MQTT/HTTP/TCP ๋ฑ ์ ํ๋ฆฌ์ผ์ด์ ํ๋กํ ์ฝ์ ํ๋ก์ ํธ์ ๋ฐ๋ผ ์ ํ)
๋ฐ์ดํฐ ํ๋ฆ
- ์ ์: ESP32 โ(SPI)โ W5500 โ(Ethernet)โ LAN/Internet
- ์ฅ์ /๋จ์ : ๋งํฌ/๋๋ผ์ด๋ฒ ์ํ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก Wi-Fi๋ก ์ ํํ์ฌ ์ฐ๊ฒฐ ์ ์ง
๊ตฌํ ๊ธฐ๋ฐ: ESP-IDF์ ์ด๋๋ท ๋๋ผ์ด๋ฒ๋ฅผ ์ฌ์ฉํ๋ฉฐ, SPI ์ด๋๋ท ๋ชจ๋(W5500/DM9051/KSZ8851SNL)์ ์ ํ ๊ฐ๋ฅํ๋๋ก ๋์ด ์์ต๋๋ค.
๐Code Implementation
Link : https://github.com/gmag11/EthWiFiManager/blob/main/src/EthWiFiManager.cpp
EthWiFiManager๋ ESP-IDF ์ด๋ฒคํธ ๊ธฐ๋ฐ ๊ตฌ์กฐ๋ก ๋์ํฉ๋๋ค.
Wi-Fi, Ethernet, IP ์ด๋ฒคํธ๋ฅผ ๊ฐ๊ฐ ๋ฑ๋กํ๊ณ (esp_event_handler_register),
๋งํฌ ์ํ ๋ฐ IP ํ๋ ์ฌ๋ถ์ ๋ฐ๋ผ ๋คํธ์ํฌ ๊ฒฝ๋ก๋ฅผ ์๋ ์ ํํฉ๋๋ค.
โ ์ ์ ์ฐ์ ๋ก์ง์ ํต์ฌ
- ๊ธฐ์ค ๋ณ์:
m_ethHasIp - Ethernet์ด IP๋ฅผ ํ๋ํ๋ฉด โ Wi-Fi ์ค์ง
- Ethernet์ด ๋งํฌ ๋ค์ด๋๋ฉด โ Wi-Fi ์๋ ์์
์ฆ, ๋จ์ ๋งํฌ ์ํ๊ฐ ์๋๋ผ โ์ค์ IP ๋ณด์ ์ฌ๋ถโ๋ฅผ ๊ธฐ์ค์ผ๋ก ์ฐ์ ์์๋ฅผ ๊ฒฐ์ ํฉ๋๋ค.
โ DHCP / Static IP ๋ชจ๋ ์ง์
- Wi-Fi:
WiFi.config()๋๋ DHCP - Ethernet:
esp_netif_set_ip_info()๋๋ DHCP client
์ ์ /๋ฌด์ ๋ชจ๋ ๋์ผํ ์ ์ฑ ๊ตฌ์กฐ๋ก ์ค๊ณ๋์ด ์์ต๋๋ค.
โ SPI Ethernet ๋ชจ๋ ์๋ ๊ฐ์ง
probeSpiModule()์์ SPI๋ก ์ค์ ์นฉ ๋ ์ง์คํฐ๋ฅผ ์ฝ์ด
W5500(VERSIONR=0x04) ๋ฑ ๋ชจ๋ ์กด์ฌ ์ฌ๋ถ๋ฅผ ํ์ธํฉ๋๋ค.
๊ฐ์ง ์คํจ ์:
- Ethernet ๋นํ์ฑํ
- Wi-Fi Only ๋ชจ๋๋ก ์๋ ์ ํ
ํ์ฅ ์ค์น ์ค๋ฅ์ ๋๋นํ ์์ ์ค๊ณ์ ๋๋ค.
โ AP Router ๋ชจ๋ (์ต์ ๊ธฐ๋ฅ)
์กฐ๊ฑด๋ถ ์ปดํ์ผ ์:
- ESP32๊ฐ Wi-Fi AP ์์ฑ
- Ethernet์ WAN์ผ๋ก ์ฌ์ฉ
- lwIP NAPT ํ์ฑํ
- DNS ํ๋ก์ ํ์คํฌ ์คํ
์ฆ, ๋จ์ ์ฐ๊ฒฐ ๊ด๋ฆฌ์์ ์ํ ๋ผ์ฐํฐ ๊ธฐ๋ฅ๊น์ง ํ์ฅ ๊ฐ๋ฅํฉ๋๋ค.
๐ Role and Application of the WIZnet's Chip
์ฌ์ฉ๋ WIZnet ์นฉ: W5500
๋คํธ์ํฌ์์์ ์ญํ
- ๋ณธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๊ด์ ์์ W5500์ **SPI ๊ธฐ๋ฐ ์ ์ ์ด๋๋ท ์ธํฐํ์ด์ค(10/100 MAC+PHY ํฌํจ)**๋ก ๋์ํ๋ฉฐ, ์ ์ ์ฐ๊ฒฐ์ โ๊ธฐ๋ณธ ์ฃผ ๊ฒฝ๋กโ๋ก ์ ๊ณตํฉ๋๋ค.
๐ Market & Application Value
์ ์ฉ ๊ฐ๋ฅํ ์ฐ์ /์์ฅ
- ์ค๋งํธ ํฉํ ๋ฆฌ/์ฐ์ ์๋ํ(OT): Wi-Fi ์์/๊ฐ์ญ์ด ์๋ ํ์ฅ์์ ์ ์ ์ฐ์ ์ ์ฑ ์ ์ด์ ์์ ์ฑ์ ์ง์ ๊ธฐ์ฌํฉ๋๋ค.
- ๋น๋ฉ/์์ค ๊ด๋ฆฌ, ์๋์ง ๋ชจ๋ํฐ๋ง, ํค์ค์คํฌ/PoS, ๋ฌผ๋ฅ ๊ฒ์ดํธ์จ์ด: โ์ ์ ์ด ๊ธฐ๋ณธ์ด๋, ์ฅ์ ์ ๋ฌด์ ์ผ๋ก ์ด์๋จ๋โ ๊ตฌ์ฑ์ ์ ์ง๋ณด์ ๋น์ฉ์ ๋ฎ์ถ ์ ์์ต๋๋ค.
๐ Summary
EthWiFiManager๋ ESP32์์ W5500(SPI Ethernet) ๊ธฐ๋ฐ ์ ์ ์ฐ๊ฒฐ์ ์ฐ์ ์ฌ์ฉํ๊ณ , ์ฅ์ ์ Wi-Fi๋ก ์๋ ์ ํํ๋ ์ฐ๊ฒฐ ๊ด๋ฆฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋๋ค.
๊ธฐ์ ์ ์ผ๋ก๋ ESP-IDF ํ์ค ์ด๋๋ท ๋๋ผ์ด๋ฒ ๊ธฐ๋ฐ์ผ๋ก ๊ตฌํ๋์ด ๊ตฌ์กฐ๊ฐ ๋ช ํํ๋ฉฐ, ํ์ฅ ์ ์ฉ์์ ์ค์ํ **์ฐ๊ฒฐ ์์ ์ฑ(์ด์ค ๊ฒฝ๋ก)**์ด๋ผ๋ ๊ฐ์น๋ฅผ ๊ฒจ๋ฅํฉ๋๋ค.
๐ FAQ
Q1. EthWiFiManager๋ ๋ฌด์์ธ๊ฐ์?
EthWiFiManager๋ ESP32์์ ์ ์ ์ด๋๋ท(SPI ๊ธฐ๋ฐ, ์: W5500)์ ์ฐ์ ์ฌ์ฉํ๊ณ , ์ฅ์ ๋ฐ์ ์ Wi-Fi๋ก ์๋ ์ ํํ๋ ๋คํธ์ํฌ ๊ด๋ฆฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋๋ค.
Q2. ์ ์ ์ฐ์ + Wi-Fi ํด๋ฐฑ์ ์ด๋ป๊ฒ ๋์ํ๋์?
์ด๋๋ท์ด ์ ์ ์ฐ๊ฒฐ ์ํ์ด๋ฉด ์ ์ ์ ๊ธฐ๋ณธ ๊ฒฝ๋ก๋ก ์ฌ์ฉํฉ๋๋ค. ์ผ์ด๋ธ ๋จ์ ์ด๋ ๋งํฌ ๋ค์ด์ด ๊ฐ์ง๋๋ฉด ์๋์ผ๋ก Wi-Fi๋ก ์ ํํ์ฌ ๋คํธ์ํฌ ์ฐ๊ฒฐ์ ์ ์งํฉ๋๋ค.
Q3. WIZnet W5500์ ์ญํ ์ ๋ฌด์์ธ๊ฐ์?
W5500์ SPI ๊ธฐ๋ฐ 10/100Mbps Ethernet ์ปจํธ๋กค๋ฌ(MAC+PHY ๋ด์ฅ)๋ก, ESP32์ ์์ ์ ์ธ ์ ์ ๋คํธ์ํฌ ์ฐ๊ฒฐ์ ์ ๊ณตํฉ๋๋ค. ๋ณธ ๊ตฌ์กฐ์์ ๊ธฐ๋ณธ ์ฃผ ํต์ ๊ฒฝ๋ก ์ญํ ์ ์ํํฉ๋๋ค.
Q4. ์ด๋ค ์ด๋๋ท ์นฉ์ ์ง์ํ๋์?
ESP-IDF Ethernet ๋๋ผ์ด๋ฒ ๊ธฐ๋ฐ์ผ๋ก W5500, DM9051, KSZ8851SNL ๋ฑ์ ์ง์ํฉ๋๋ค. ์ด ์ค W5500์ด ๊ฐ์ฅ ์ผ๋ฐ์ ์ผ๋ก ์ฌ์ฉ๋ฉ๋๋ค.
Q5. DHCP์ ๊ณ ์ IP๋ฅผ ๋ชจ๋ ์ง์ํ๋์?
๋ค. ์ ์ ๊ณผ Wi-Fi ๋ชจ๋ DHCP๋ฅผ ์ง์ํ๋ฉฐ, ๊ฐ๊ฐ์ ๋ํด Static IP ์ค์ ๋ ๊ฐ๋ฅํฉ๋๋ค.
Q6. Wi-Fi ์ ์ฉ ๋ชจ๋๋ก ์ฌ์ฉ ๊ฐ๋ฅํ๊ฐ์?
๋ค. ์ค์ ์ ํตํด ์ด๋๋ท์ ๋นํ์ฑํํ๊ณ Wi-Fi Only ๋ชจ๋๋ก ๋์ํ ์ ์์ต๋๋ค.
Q7. ์ฐ์ ํ๊ฒฝ์์ ์ ์ ์ ์ฐ์ ์ ์ฑ ์ด ์ค์ํ๊ฐ์?
์ฐ์ ํ์ฅ์ Wi-Fi ๊ฐ์ญ๊ณผ ์ ํธ ๊ฐ์ ๊ฐ ๋น๋ฒํฉ๋๋ค. ์ ์ ์ฐ์ ์ ์ฑ ์ ์์ ์ฑ์ ํ๋ณดํ๋ฉด์, ์ฅ์ ์ ์๋ ๋ฌด์ ์ ํ์ผ๋ก ๋ค์ดํ์์ ์ต์ํํฉ๋๋ค.
Q8. ์ฃผ์ ์ ์ฉ ๋ถ์ผ๋ ๋ฌด์์ธ๊ฐ์?
์ค๋งํธ ํฉํ ๋ฆฌ, ์ฐ์ ์ฉ IoT ๊ฒ์ดํธ์จ์ด, ๋น๋ฉ ๊ด๋ฆฌ ์์คํ , ์๋์ง ๋ชจ๋ํฐ๋ง, ํค์ค์คํฌ/PoS, ๋ฌผ๋ฅ ์ฅ๋น ๋ฑ์ ์ ํฉํฉ๋๋ค.
Q9. ๊ฐ๋ฐ์๋ ์ด๋ป๊ฒ ์ฝ๊ฒ ์ ์ฉํ ์ ์๋์?
begin(), status(), localIP() ๋ฑ WiFi ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์ ์ฌํ API๋ฅผ ์ ๊ณตํ์ฌ ๊ธฐ์กด ESP32 ํ๋ก์ ํธ์ ์ฝ๊ฒ ํตํฉํ ์ ์์ต๋๋ค.
Q10. W5500 ๊ธฐ๋ฐ ์ค๊ณ์ ์ฅ์ ์ ๋ฌด์์ธ๊ฐ์?
์์ ์ ์ธ ์ง์ฐ ์๊ฐ, ๋ฎ์ ํจํท ์์ค, ํ๋์จ์ด TCP/IP ์คํ๋ก๋ฉ, ๋์ EMI ๋ด์ฑ ๋ฑ์ผ๋ก ์ฐ์ ์ฉ IoT ์์คํ ์ ์ ๋ขฐ์ฑ์ ํฅ์์ํต๋๋ค.
๐ Overview
EthWiFiManager is a library for ESP32 that provides a โwired (SPI Ethernet) priority + automatic Wi-Fi fallbackโ connection policy. In other words, it normally uses SPI Ethernet such as the W5500 as the primary connection, and automatically switches to Wi-Fi if the wired connection becomes unstable due to a cable disconnection, switch failure, or similar issues.
๐ Features
- Wired priority + Wi-Fi fallback (Combined mode): By default, Ethernet is used as the primary connection, and it automatically switches to Wi-Fi in case of failure.
- Wi-Fi Only mode support: Ethernet can be disabled via settings to use Wi-Fi only.
- DHCP supported by default (both wired and wireless): Reduces network configuration burden during on-site installation.
- Static IP option for both wired and wireless: Can be applied in facility networks (OT networks) where a fixed IP is required.
- Simple API similar to WiFi: Designed for easy adoption with minimal learning, using functions such as begin(), status(), and localIP().
- AP Router mode support (optional feature): When conditionally compiled, the ESP32 can create a Wi-Fi AP and operate as a small NAT router using Ethernet as the WAN.
๐ System Architecture
Components
- ESP32 (MCU/SoC) + SPI Ethernet module (W5500, etc.) + built-in Wi-Fi
- Switch/router (wired network) and Wi-Fi AP (wireless network)
- Upstream server/cloud (application protocols such as MQTT/HTTP/TCP are selected depending on the project)
Data Flow
- Normal: ESP32 โ (SPI) โ W5500 โ (Ethernet) โ LAN/Internet
- Failure/disconnection: Switches to Wi-Fi based on link/driver status to maintain connectivity
Implementation Base: Uses the Ethernet driver of ESP-IDF and allows selection of SPI Ethernet modules (W5500/DM9051/KSZ8851SNL).
๐Code Implementation
Link : https://github.com/gmag11/EthWiFiManager/blob/main/src/EthWiFiManager.cpp
EthWiFiManager operates based on the ESP-IDF event-driven architecture.
It registers Wi-Fi, Ethernet, and IP events individually (esp_event_handler_register), and automatically switches the network path based on link status and IP acquisition.
โ Core Logic of Wired Priority
- Reference variable: m_ethHasIp
- When Ethernet acquires an IP โ Wi-Fi is stopped
- When the Ethernet link goes down โ Wi-Fi automatically starts
In other words, priority is determined based on โactual IP possession,โ not just simple link status.
โ Supports Both DHCP and Static IP
- Wi-Fi: WiFi.config() or DHCP
- Ethernet: esp_netif_set_ip_info() or DHCP client
Both wired and wireless are designed with the same policy structure.
โ Automatic Detection of SPI Ethernet Module
In probeSpiModule(), the actual chip register is read via SPI
to verify the presence of modules such as the W5500 (VERSIONR = 0x04).
If detection fails:
- Ethernet is disabled
- Automatically switches to Wi-Fi Only mode
This is a fail-safe design to prepare for on-site installation errors.
โ AP Router Mode (Optional Feature)
When conditionally compiled:
- ESP32 creates a Wi-Fi AP
- Uses Ethernet as WAN
- Enables lwIP NAPT
- Runs a DNS proxy task
In other words, it can be extended from simple connection management to small router functionality.
๐ Role and Application of the WIZnet's Chip
WIZnet chip used: W5500
Role in the network
- From the perspective of this library, the W5500 operates as an SPI-based wired Ethernet interface (including 10/100 MAC+PHY) and provides the wired connection as the โdefault primary path.โ
๐ Market & Application Value
Applicable Industries/Markets
- Smart factory/industrial automation (OT): In environments with Wi-Fi shadowing or interference, a wired-first policy directly contributes to operational stability.
- Building/facility management, energy monitoring, kiosks/PoS, logistics gateways: A configuration where โwired is primary, but switches to wireless in case of failureโ can reduce maintenance costs.
๐ Summary
EthWiFiManager is a connection management library for ESP32 that prioritizes wired connectivity based on W5500 (SPI Ethernet) and automatically switches to Wi-Fi in case of failure.
Technically, it is implemented based on the standard Ethernet driver of ESP-IDF, providing a clear architecture and targeting the value of connection reliability (dual-path redundancy), which is critical in real-world deployments.
๐ FAQ
Q1. What is EthWiFiManager?
EthWiFiManager is a network management library for ESP32 that prioritizes wired Ethernet (SPI-based, e.g., W5500) and automatically switches to Wi-Fi in case of failure.
Q2. How does wired priority + Wi-Fi fallback work?
When Ethernet is in a normal connected state, it is used as the primary path. If a cable disconnection or link-down event is detected, it automatically switches to Wi-Fi to maintain network connectivity.
Q3. What is the role of the WIZnet W5500?
The W5500 is an SPI-based 10/100Mbps Ethernet controller (with integrated MAC+PHY) that provides stable wired network connectivity to the ESP32. In this architecture, it serves as the primary communication path.
Q4. Which Ethernet chips are supported?
Based on the ESP-IDF Ethernet driver, it supports W5500, DM9051, and KSZ8851SNL. Among them, the W5500 is the most commonly used.
Q5. Are both DHCP and Static IP supported?
Yes. Both wired and Wi-Fi support DHCP, and Static IP configuration is also available for each interface.
Q6. Can it operate in Wi-Fi only mode?
Yes. Ethernet can be disabled through configuration, allowing operation in Wi-Fi Only mode.
Q7. Why is a wired-priority policy important in industrial environments?
Industrial environments frequently experience Wi-Fi interference and signal attenuation. A wired-priority policy ensures stability while minimizing downtime through automatic wireless switching during failures.
Q8. What are the main application areas?
It is suitable for smart factories, industrial IoT gateways, building management systems, energy monitoring, kiosks/PoS, and logistics equipment.
Q9. How can developers easily apply it?
It provides APIs similar to the WiFi library, such as begin(), status(), and localIP(), making it easy to integrate into existing ESP32 projects.
Q10. What are the advantages of a W5500-based design?
Stable latency, low packet loss, hardware TCP/IP offloading, and high EMI immunity improve the reliability of industrial IoT systems.
