ESP32-Edge-Device
ESP32-Edge-Device
프로젝트가 하는 일
ESP32-Edge-Device는 단순한 스마트 플러그가 아니라, 전력 계측과 보호 제어를 함께 수행하는 산업용 IoT 노드에 가깝다.
PZEM-004T는 전압, 전류, 유효전력, 에너지, 주파수, 역률을 측정하고 ESP32로 데이터를 전달한다. AMC1200 절연 증폭기는 고전압 측과 저전압 로직을 분리하면서 전압 서지나 딥 같은 과도 상태를 감지하는 데 사용된다. 릴레이는 ESP32의 제어 신호에 따라 부하를 켜거나 차단한다.
통신 구조는 두 가지로 나뉜다. MQTT는 Node-RED 대시보드로 계측값과 상태 정보를 전송하는 데 사용된다. Modbus TCP는 PLC나 SCADA 시스템이 장치를 산업용 slave device처럼 읽을 수 있도록 한다. 즉, 이 프로젝트는 현장 전력 데이터를 수집하고, 보호 조건을 판단하며, 산업용 네트워크로 상태를 공유하는 edge device 구조를 가진다.
이미지 출처 : AI 생성


이미지 출처 : https://github.com/suvamseth/ESP32-Edge-Device
WIZnet이 들어가는 위치
이 프로젝트에서 사용되는 WIZnet 제품은 W5500이다. W5500은 ESP32와 SPI로 연결되는 Ethernet controller이며, ESP32가 유선 네트워크를 통해 MQTT와 Modbus TCP 통신을 수행할 수 있게 한다.
W5500의 역할은 센서 데이터 측정이 아니라 네트워크 전송 계층이다. ESP32는 PZEM-004T와 AMC1200에서 들어오는 데이터를 처리하고, W5500은 그 결과를 Ethernet 기반 TCP/IP 네트워크로 전달한다.
산업용 IoT 환경에서는 이 구조가 실용적이다. Wi-Fi는 설치가 쉽지만, 분전반, 모터, 릴레이, 긴 전원 배선이 있는 환경에서는 간섭과 신호 품질 저하가 발생할 수 있다. 반면 W5500 기반 Ethernet은 고정 배선, 명확한 link 상태, 예측 가능한 통신 경로를 제공한다. PLC, SCADA, Node-RED와 연동해야 하는 장치라면 유선 Ethernet이 유지보수 측면에서도 유리하다.
W5500은 하드웨어 TCP/IP stack, 내부 TX/RX 버퍼, 8개 socket을 제공하므로 ESP32가 네트워크 처리 부담을 줄이고 센싱, 보호 판단, 릴레이 제어에 더 집중할 수 있다.
구현 노트
저장소에서 확인 가능한 자료는 README와 KiCad 기반 하드웨어 설계 파일이다. ESP32 펌웨어 소스 파일은 공개 파일 목록에서 확인되지 않으므로, 실제 W5500 초기화 코드나 MQTT, Modbus TCP 구현 코드를 원문 코드처럼 인용할 수는 없다.
확인 가능한 내용은 다음과 같다.
README는 하드웨어 구성에 ESP32, PZEM-004T, W5500 Ethernet module을 포함한다. 또한 W5500이 SPI interface로 연결되며, MQTT와 Modbus TCP 통신에 사용된다고 설명한다.
아키텍처 관점에서 펌웨어는 다음 흐름으로 구성된다.
ESP32는 PZEM-004T에서 전력 계측값을 읽고, AMC1200 경로를 통해 이상 전압 상태를 판단한다. 보호 조건이 발생하면 릴레이를 차단하고, fault 상태를 내부 상태값으로 갱신한다. 이후 W5500 Ethernet을 통해 MQTT topic으로 데이터를 게시하거나, Modbus TCP register map을 통해 PLC/SCADA가 같은 값을 읽을 수 있게 한다.
MQTT는 이벤트성 telemetry와 dashboard 표시에는 적합하다. Modbus TCP는 PLC가 일정 주기로 전압, 전류, 전력, 에너지, relay state, fault state를 읽는 구조에 적합하다. 두 프로토콜을 함께 사용하면 현장 제어 시스템과 운영자 대시보드를 동시에 지원할 수 있다.
실무 팁 / 주의점
- ESP32와 W5500 사이의 SPI 배선은 짧게 유지하고, 릴레이 및 AC 입력부와 충분히 떨어뜨려야 한다.
- MQTT와 Modbus TCP를 동시에 사용하면 socket 사용량을 고려해야 한다. Broker 재접속이나 SCADA polling 증가 상황도 염두에 두어야 한다.
- 산업 현장에서는 DHCP보다 static IP 또는 DHCP reservation이 관리하기 쉽다.
- Ethernet link 상태를 watchdog 조건에 포함하면 케이블 분리, 스위치 장애, 전원 순서 문제를 빠르게 진단할 수 있다.
- 릴레이 차단 로직은 네트워크 처리 루프와 분리해야 한다. MQTT broker 장애가 보호 동작을 늦추면 안 된다.
- PZEM-004T는 계측과 모니터링에 적합하지만, 빠른 보호 판단은 AMC1200 같은 별도 아날로그 경로와 함께 처리하는 것이 안전하다.
- AC mains와 릴레이를 다루는 설계이므로 creepage, clearance, fuse, MOV/TVS, 접지, enclosure를 반드시 검토해야 한다.
FAQ
Q: 왜 이 프로젝트에서 W5500을 사용하나요?
A: 전력 계측 장치는 네트워크 연결이 불안정하면 대시보드 표시뿐 아니라 PLC/SCADA 연동도 영향을 받는다. W5500은 ESP32에 유선 Ethernet을 추가해 MQTT와 Modbus TCP 통신을 안정적으로 처리할 수 있게 한다.
Q: W5500은 ESP32에 어떻게 연결되나요?
A: W5500은 SPI로 ESP32와 연결된다. 기본적으로 SCK, MOSI, MISO, CS가 필요하며, 보드 설계에 따라 reset 또는 interrupt 핀을 추가할 수 있다.
Q: 이 프로젝트에서 W5500이 맡는 역할은 무엇인가요?
A: W5500은 센서가 아니라 통신 인터페이스다. ESP32가 수집한 전력 데이터, 릴레이 상태, fault 상태를 Ethernet 네트워크로 전달하는 역할을 한다.
Q: 초보자도 따라 할 수 있나요?
A: 난이도는 중급 이상이다. ESP32, SPI Ethernet, MQTT, Modbus TCP, AC 전원 안전, 릴레이 제어를 함께 다뤄야 한다. 단순 센서 예제보다는 산업용 edge device 설계에 가깝다.
Q: ESP32 Wi-Fi 대신 W5500 Ethernet을 쓰는 이유는 무엇인가요?
A: Wi-Fi는 배선이 줄어드는 장점이 있지만, 산업 현장에서는 간섭과 신호 품질 변화가 문제가 될 수 있다. W5500 Ethernet은 고정 배선 기반이라 PLC/SCADA 연동처럼 예측 가능한 통신이 필요한 경우에 더 적합하다.
What the Project Does
ESP32-Edge-Device is not just a simple smart plug. It is closer to an industrial IoT node that performs both power measurement and protective control.
The PZEM-004T measures voltage, current, active power, energy, frequency, and power factor, then sends the data to the ESP32. The AMC1200 isolation amplifier separates the high-voltage side from the low-voltage logic side while helping detect transient conditions such as voltage surges and dips. The relay turns the load on or off according to control signals from the ESP32.
The communication structure is divided into two paths. MQTT is used to send measurement values and status information to a Node-RED dashboard. Modbus TCP allows a PLC or SCADA system to read the device as an industrial slave device. In other words, this project has an edge device architecture that collects field power data, evaluates protection conditions, and shares device status over an industrial network.
Image source: AI-generated


Image source: https://github.com/suvamseth/ESP32-Edge-Device
Where WIZnet Fits
The WIZnet product used in this project is the W5500. The W5500 is an Ethernet controller connected to the ESP32 over SPI, allowing the ESP32 to perform MQTT and Modbus TCP communication over a wired network.
The role of the W5500 is not sensor data measurement. It acts as the network transport layer. The ESP32 processes data from the PZEM-004T and AMC1200, while the W5500 sends the processed results over an Ethernet-based TCP/IP network.
This structure is practical in industrial IoT environments. Wi-Fi is easy to install, but in environments with distribution panels, motors, relays, and long power wiring, interference and signal quality degradation can occur. In contrast, W5500-based Ethernet provides fixed wiring, clear link status, and a predictable communication path. For devices that need to connect with PLCs, SCADA systems, and Node-RED, wired Ethernet is also advantageous from a maintenance perspective.
The W5500 provides a hardware TCP/IP stack, internal TX/RX buffers, and 8 sockets, reducing the ESP32’s network processing burden and allowing it to focus more on sensing, protection decisions, and relay control.
Implementation Notes
The materials available in the repository are the README and KiCad-based hardware design files. Since ESP32 firmware source files are not visible in the public file list, it is not possible to quote actual W5500 initialization code or MQTT and Modbus TCP implementation code as original source code.
The verifiable information is as follows.
The README includes ESP32, PZEM-004T, and a W5500 Ethernet module in the hardware configuration. It also explains that the W5500 is connected through an SPI interface and is used for MQTT and Modbus TCP communication.
From an architecture perspective, the firmware can be understood as the following flow.
The ESP32 reads power measurement values from the PZEM-004T and evaluates abnormal voltage conditions through the AMC1200 path. When a protection condition occurs, it turns off the relay and updates the fault state as an internal status value. Then, through W5500 Ethernet, it publishes data to MQTT topics or exposes the same values through a Modbus TCP register map so that a PLC or SCADA system can read them.
MQTT is suitable for event-based telemetry and dashboard visualization. Modbus TCP is suitable for a structure where a PLC periodically reads voltage, current, power, energy, relay state, and fault state. By using both protocols together, the device can support both field control systems and operator dashboards.
Practical Tips / Pitfalls
Keep the SPI wiring between the ESP32 and W5500 short, and place it far enough away from the relay and AC input section.
When using MQTT and Modbus TCP at the same time, socket usage must be considered. Broker reconnection and increased SCADA polling should also be taken into account.
In industrial sites, a static IP address or DHCP reservation is easier to manage than ordinary DHCP.
Including Ethernet link status in the watchdog conditions makes it easier to diagnose cable disconnection, switch failure, and power sequencing issues.
The relay cutoff logic should be separated from the network processing loop. An MQTT broker failure must not delay the protection operation.
The PZEM-004T is suitable for measurement and monitoring, but fast protection decisions are safer when handled together with a separate analog path such as the AMC1200.
Because this design handles AC mains and relays, creepage, clearance, fuse, MOV/TVS, grounding, and enclosure design must be reviewed carefully.
FAQ
Q: Why is the W5500 used in this project?
A: In a power measurement device, an unstable network connection can affect not only dashboard visualization but also PLC/SCADA integration. The W5500 adds wired Ethernet to the ESP32, allowing MQTT and Modbus TCP communication to be handled more reliably.
Q: How is the W5500 connected to the ESP32?
A: The W5500 is connected to the ESP32 over SPI. SCK, MOSI, MISO, and CS are basically required, and reset or interrupt pins may be added depending on the board design.
Q: What role does the W5500 play in this project?
A: The W5500 is not a sensor. It is a communication interface. Its role is to send the power data, relay status, and fault status collected by the ESP32 to the Ethernet network.
Q: Can beginners follow this project?
A: The difficulty level is intermediate or higher. It requires working with ESP32, SPI Ethernet, MQTT, Modbus TCP, AC power safety, and relay control. It is closer to designing an industrial edge device than building a simple sensor example.
Q: Why use W5500 Ethernet instead of ESP32 Wi-Fi?
A: Wi-Fi has the advantage of reducing wiring, but in industrial sites, interference and signal quality changes can become problems. W5500 Ethernet is based on fixed wiring, making it more suitable when predictable communication is required, such as PLC/SCADA integration.


