Skip to content

Server_based_Relay_control_W5500

A complete IoT relay control solution featuring STM32 firmware with W5500, a Node.js TCP/HTTP server, and a web admin dashboard.

Lihan__

Published June 22, 2026

Original author: Darshan KOriginal source (new tab)

Server_based_Relay_control_W5500

Project description

Server-Based Relay Control System β€” Industrial-Grade Remote Switching with a Web Dashboard

#RelayControl #IoT #SmartBuilding #TOE-TCP #STM32 #W5500 #Node.js #WebDashboard #JSON-over-TCP #RemoteControl

πŸ“š Individual hobby/learning project β€” STM32F103 + W5500 firmware + Node.js backend + web dashboard full-stack Firmware confirmed on STM32F103C8; TCP socket mode verified in app_relay.c


01 β€” What is this project?

Flipping a relay remotely sounds simple β€” until you need it to be reliable, auditable, and manageable from any browser without installing anything. Most DIY relay solutions stop at "send a UDP packet, toggle a pin." There is no acknowledgement, no log of who turned what on or when, and no way to see the current state from a dashboard.

This project delivers the full stack: an STM32F103 firmware node connects outward to a central Node.js TCP server over W5500 Ethernet, receives JSON commands, controls a physical relay, and sends back acknowledgements. The Node.js backend stores device state, writes timestamped event logs, and exposes REST endpoints to a browser-based admin dashboard. The result is a relay controller that behaves less like a hobby gadget and more like a managed IoT device β€” with heartbeat monitoring, authentication, and a live audit trail.


02 β€” Why Networked Relay Control?

πŸ”· The Gap Between "Smart" and "Managed"

Consumer smart plugs use proprietary cloud APIs that disappear when the vendor shuts down, block local-only operation, and offer no audit log. Industrial relay controllers with proper management are expensive and overcomplicated for small deployments. This project sits in the middle: fully local, fully open, REST-accessible, and log-keeping β€” without proprietary cloud dependency.

πŸ”· Reliability Through TCP + Heartbeat

The system uses a persistent TCP connection with a 5-second heartbeat ({"type":"hb"}). If the connection drops, the firmware detects SOCK_ESTABLISHED loss and automatically reconnects. The server marks the device online: false on socket close. This closed-loop availability model means the dashboard always reflects actual device state, not stale cache.

πŸ”· Full-Stack in One Repository

Firmware (C/STM32), backend (Node.js), and frontend (HTML/CSS/JS) coexist in a single repo with clear separation. Any developer can clone, configure two IP addresses, and have the system running end-to-end within minutes. The build dependencies (npm install, STM32CubeIDE) are standard and documented.


03 β€” System Architecture

03 β€” System Architecture

04 β€” Why W5500?

πŸ”· TOE TCP Socket Mode β€” Client-Initiated Persistent Connection

This project uses W5500's hardware TCP socket mode (Sn_MR_TCP) in an unusual pattern: the STM32 acts as the TCP client, initiating a persistent outbound connection to the Node.js server. This is the correct topology for a device behind NAT or in a network where inbound connections to the MCU are not desirable.

c
// From Core/Src/app_relay.c β€” confirmed socket(RELAY_SOCKET, Sn_MR_TCP, 5000, 0);          // local port 5000 connect(RELAY_SOCKET, server_ip, SERVER_PORT);       // connect to server :9000 send_hello();                                        // {"type":"hello","deviceId":"relay-f105-01"} send_status();                                       // {"type":"status","relay1":"off"}

W5500's TOE handles TCP state, retransmission, and ACK entirely in hardware. The STM32 loop calls getSn_SR() to check connection health and recv() to get incoming commands β€” no TCP stack in firmware code at all.

πŸ”· PHY Link Monitoring β€” Hardware-Level Connectivity Awareness

The firmware polls wizphy_getphylink() during initialization and waits up to 2 seconds for the physical Ethernet link to come up before attempting any socket operations. This prevents connection attempts before the cable is live β€” a common failure mode in DIY projects that skip PHY state checking.

c
if (WaitForPhyLink(PHY_LINK_TIMEOUT_MS))     UART_Print("LAN OK\r\n"); else     UART_Print("LAN FAIL\r\n");

W5500's embedded PHY status register makes this one function call. On a raw MAC+external PHY design, this would require reading PHY registers over MDIO.

πŸ”· Auto-Reconnect Loop β€” Always-Connected Device Behavior

c
void socket_loop(void) {     if (getSn_SR(RELAY_SOCKET) != SOCK_ESTABLISHED) {         close(RELAY_SOCKET);         HAL_Delay(1000);         socket_connect();   // re-open Sn_MR_TCP socket and reconnect         return;     }     // recv() β†’ parse_cmd() }

Every main loop iteration checks TCP connection health. Drop detected β†’ reconnect within 1 second. The server-side socket.on("close") handler marks the device offline instantly. Together these form a closed-loop availability model with no manual intervention needed.

πŸ”· Static IP β€” Deterministic Network Identity

NETINFO_STATIC, IP 192.168.31.50. The device is reachable immediately after power-on. No DHCP boot delay, no address change surprises. For a relay node in a fixed-location deployment, static IP is always the right choice.

πŸ”· Verified Evidence βœ…

  • socket(RELAY_SOCKET, Sn_MR_TCP, 5000, 0) confirmed in app_relay.c
  • connect(), send(), recv(), getSn_SR() confirmed in application code
  • wizchip_init(), wizchip_setnetinfo(), getVERSIONR() confirmed β€” chip version read at boot
  • WaitForPhyLink() with wizphy_getphylink() confirmed β€” PHY link gate before socket
  • Serial debug log (teraterm_logs.txt) included in repo β€” boot sequence captured on real hardware
  • Server_based_Relay_controll.pdf included β€” project documentation

05 β€” Key Components

🌐 WIZnet W5500 β€” TCP TOE Mode (Sn_MR_TCP), Client Mode

Hardware TCP/IP offload over SPI1. The STM32 opens an outbound TCP connection to the Node.js server on port 9000. JSON messages flow over this persistent socket. No TCP stack in firmware β€” W5500 handles it in silicon.

πŸ”§ STM32F103C8T6

72 MHz Cortex-M3. SPI1 drives W5500 (CS: PA4, RST: PB1). PB5 drives the relay output (active high). UART1 outputs debug messages to Tera Term. STM32CubeIDE project included (.ioc + .cproject).

πŸ–₯️ Node.js Backend (server.js)

Single-file server running both TCP listener (:9000, device side) and HTTP server (:8080, dashboard side). JSON line-protocol parsing, session-based authentication (PBKDF2 password hashing), JSON file datastore for users/devices/logs, REST API for dashboard control. No external database needed.

🌐 Web Admin Dashboard (frontend/)

Static HTML/CSS/JS dashboard. Login β†’ overview summary β†’ device list β†’ relay toggle β†’ per-device event log. Fully functional from any browser with no installation. Reads/writes via REST API to the Node.js backend.


06 β€” Application Scenarios

01. Smart Building Subsystem

Building automation engineers deploy STM32+W5500 relay nodes to control HVAC dampers, lighting circuits, or door locks. The central Node.js server aggregates all nodes into a unified dashboard, with timestamped logs satisfying basic audit requirements for facilities management.

02. Lab Equipment Power Management

A research lab installs one relay node per instrument rack. The admin dashboard shows which instruments are powered at a glance. Instruments can be toggled remotely without walking the lab. The event log provides a record of power cycling β€” useful for troubleshooting instrument failures correlated to power events.

03. Industrial Pilot Line Control

A small manufacturing line uses relay nodes to enable/disable conveyor motors or pneumatic valves from a central HMI browser interface. The heartbeat monitoring ensures the operator knows immediately if a node loses network connection β€” critical for safety-aware process control.

04. Home Automation Gateway

A maker installs relay nodes behind mains switches for lights, fans, or irrigation valves. The self-hosted Node.js server (Raspberry Pi or NAS) provides local-only control with no cloud dependency. The web dashboard is accessible from any device on the home network.


Conclusion

This project demonstrates that W5500's hardware TCP offload turns a bare STM32F103 into a fully managed IoT relay node β€” complete with JSON protocol, heartbeat monitoring, REST dashboard, and event logging.

  • βœ… W5500 TCP TOE client mode confirmed β€” socket(Sn_MR_TCP) + connect() in app_relay.c
  • βœ… PHY link gate before socket β€” wizphy_getphylink() polling confirmed
  • βœ… Auto-reconnect loop β€” connection health checked every main loop iteration
  • βœ… JSON line-protocol bidirectional: hello / status / command / ack / heartbeat
  • βœ… Node.js backend with authentication, REST API, and persistent event log (up to 5,000 entries)
  • βœ… Browser-based admin dashboard β€” no client installation, works from any device
  • βœ… Serial boot log (teraterm_logs.txt) captured on real hardware
  • βœ… Full-stack in one repo: firmware + backend + frontend, 3-commit clean history

A relay, an STM32, and an Ethernet jack. This kind of project also uses W5500.


07 β€” Similar Projects on WIZnet Makers

Several projects on the platform address the same relay-over-Ethernet space.

Relay control via HTTP Rest Protocol (WIZnet official) demonstrates the concept using HTTP REST directly on the device. Simpler topology β€” no central server, browser talks directly to the MCU. β†’ https://maker.wiznet.io/WIZnet/projects/relay-control-via-http-rest-protocol/

ESP32 (38-pin) + W5500: Offline LAN Relay Control with a Simple Web Server (sophia, 2026) uses ESP32+W5500 with an embedded web server β€” no separate backend server, browser hits the MCU directly. β†’ https://maker.wiznet.io/sophia/projects/esp32-38-pin-w5500-offline-lan-relay-control-with-a-simple-web-server/

8 Channel Ethernet Relay Controller (Alan, 2025) scales up to 8 channels with PoE support β€” hardware-focused, no software dashboard. β†’ https://maker.wiznet.io/Alan/projects/8-channel-ethernet-relay-controller-support-poe-and-usb/

 This ProjectHTTP REST (WIZnet)ESP32 Web Server8-Ch PoE Controller
MCUSTM32F103β€”ESP32β€”
W5500 roleTCP KM channelHTTP serverOn-boardOn-board
ProtocolJSON over TCPHTTP RESTHTTP (embedded)β€”
Central serverβœ… Node.js❌❌❌
Web dashboardβœ… separateβœ… (on MCU)βœ… (on MCU)❌
Auth + loggingβœ…βŒβŒβŒ
Relay channels1variesvaries8
Heartbeat / reconnectβœ…βŒβŒβŒ

The key differentiator of this project is the centralized server architecture with authentication and logging β€” the only one in this group that treats the relay node as a managed device rather than a standalone controller. The trade-off is deployment complexity: Node.js backend must run separately. The insight is that as relay deployments grow beyond one or two nodes, centralized management becomes essential β€” and this project is the only one in the ecosystem already built for that.


Q&A

Q: Why does the STM32 connect outward to the server rather than the server connecting to the STM32? A: Client-initiated TCP is the correct model for devices behind NAT or on dynamic IPs. The device always knows the server's fixed IP; the server never needs to know the device's IP in advance. The hello message carries the device ID, letting the server register any device that connects.

Q: Why JSON over raw TCP rather than HTTP or MQTT? A: JSON over newline-delimited TCP is the lightest full-featured option for an STM32F103 with 64KB flash. HTTP adds request/response framing overhead; MQTT requires a broker. The Node.js server can parse newline-delimited JSON with three lines of code. For a single-channel prototype, this is the right trade-off.

Q: Can the system scale to multiple relay nodes? A: Yes by design. The deviceSockets Map and devices.json datastore on the server side are keyed by deviceId. Each firmware node just needs a unique DEVICE_ID string and the same server IP. The dashboard automatically lists all connected devices.



μ„œλ²„ 기반 릴레이 μ œμ–΄ μ‹œμŠ€ν…œ β€” μ›Ή λŒ€μ‹œλ³΄λ“œλ₯Ό κ°–μΆ˜ μ‚°μ—…κΈ‰ 원격 μŠ€μœ„μΉ­

#λ¦΄λ ˆμ΄μ œμ–΄ #IoT #μŠ€λ§ˆνŠΈλΉŒλ”© #TOE-TCP #STM32 #W5500 #Node.js #μ›ΉλŒ€μ‹œλ³΄λ“œ #JSON-over-TCP #μ›κ²©μ œμ–΄

πŸ“š 개인 μ·¨λ―Έ/ν•™μŠ΅ ν”„λ‘œμ νŠΈ β€” STM32F103 + W5500 νŽŒμ›¨μ–΄ + Node.js λ°±μ—”λ“œ + μ›Ή λŒ€μ‹œλ³΄λ“œ ν’€μŠ€νƒ STM32F103C8 νŽŒμ›¨μ–΄ 확인 μ™„λ£Œ; app_relay.cμ—μ„œ TCP μ†ŒμΌ“ λͺ¨λ“œ 검증됨


01 β€” 이 ν”„λ‘œμ νŠΈλŠ” 무엇인가?

릴레이λ₯Ό μ›κ²©μœΌλ‘œ 켜고 λ„λŠ” 것은 λ‹¨μˆœν•΄ 보인닀 β€” μ‹ λ’°μ„±, 감사 좔적, λΈŒλΌμš°μ € μ–΄λ””μ„œλ‚˜ 접근이 ν•„μš”ν•  λ•ŒκΉŒμ§€λŠ”. λŒ€λΆ€λΆ„μ˜ DIY 릴레이 μ†”λ£¨μ…˜μ€ "UDP νŒ¨ν‚· ν•˜λ‚˜ 보내고 ν•€ ν† κΈ€"μ—μ„œ λ©ˆμΆ˜λ‹€. 응닡 확인도 μ—†κ³ , λˆ„κ°€ μ–Έμ œ 무엇을 μΌ°λŠ”μ§€ 기둝도 μ—†μœΌλ©°, λŒ€μ‹œλ³΄λ“œμ—μ„œ ν˜„μž¬ μƒνƒœλ₯Ό λ³Ό 방법도 μ—†λ‹€.

이 ν”„λ‘œμ νŠΈλŠ” ν’€μŠ€νƒμ„ μ œκ³΅ν•œλ‹€: STM32F103 νŽŒμ›¨μ–΄ λ…Έλ“œκ°€ W5500 이더넷을 톡해 쀑앙 Node.js TCP μ„œλ²„μ— μ ‘μ†ν•˜κ³ , JSON λͺ…령을 μˆ˜μ‹ ν•˜κ³ , 물리 릴레이λ₯Ό μ œμ–΄ν•˜κ³ , 확인 응닡을 λŒλ €λ³΄λ‚Έλ‹€. Node.js λ°±μ—”λ“œλŠ” λ””λ°”μ΄μŠ€ μƒνƒœλ₯Ό μ €μž₯ν•˜κ³ , νƒ€μž„μŠ€νƒ¬ν”„κ°€ 찍힌 이벀트 둜그λ₯Ό κΈ°λ‘ν•˜λ©°, λΈŒλΌμš°μ € 기반 관리 λŒ€μ‹œλ³΄λ“œμ— REST μ—”λ“œν¬μΈνŠΈλ₯Ό μ œκ³΅ν•œλ‹€. 결과물은 μ·¨λ―Έ 가젯보닀 κ΄€λ¦¬ν˜• IoT λ””λ°”μ΄μŠ€μ— 가깝닀 β€” ν•˜νŠΈλΉ„νŠΈ λͺ¨λ‹ˆν„°λ§, 인증, μ‹€μ‹œκ°„ 감사 λ‘œκ·ΈκΉŒμ§€.


02 β€” μ™œ λ„€νŠΈμ›Œν¬ 릴레이 μ œμ–΄μΈκ°€?

πŸ”· "슀마트"와 "관리됨"의 κ°„κ·Ή

μ†ŒλΉ„μžμš© 슀마트 ν”ŒλŸ¬κ·ΈλŠ” 벀더가 μ„œλΉ„μŠ€λ₯Ό μ’…λ£Œν•˜λ©΄ μ‚¬λΌμ§€λŠ” 독점 ν΄λΌμš°λ“œ APIλ₯Ό μ‚¬μš©ν•˜κ³ , 둜컬 μ „μš© λ™μž‘μ„ λ§‰μœΌλ©°, 감사 둜그λ₯Ό μ œκ³΅ν•˜μ§€ μ•ŠλŠ”λ‹€. μ œλŒ€λ‘œ 된 관리 κΈ°λŠ₯을 κ°–μΆ˜ μ‚°μ—…μš© 릴레이 μ»¨νŠΈλ‘€λŸ¬λŠ” μ†Œκ·œλͺ¨ 배포에 κ³Όν•˜κ²Œ λ³΅μž‘ν•˜κ³  λΉ„μ‹Έλ‹€. 이 ν”„λ‘œμ νŠΈλŠ” κ·Έ 쀑간에 μœ„μΉ˜ν•œλ‹€: μ™„μ „ 둜컬, μ™„μ „ μ˜€ν”ˆ, REST μ ‘κ·Ό κ°€λŠ₯, 둜그 보쑴 β€” 독점 ν΄λΌμš°λ“œ 의쑴 없이.

πŸ”· TCP + ν•˜νŠΈλΉ„νŠΈλ₯Ό ν†΅ν•œ μ‹ λ’°μ„±

μ‹œμŠ€ν…œμ€ 5초 ν•˜νŠΈλΉ„νŠΈ({"type":"hb"})와 ν•¨κ»˜ μ˜μ† TCP 연결을 μ‚¬μš©ν•œλ‹€. 연결이 끊기면 νŽŒμ›¨μ–΄κ°€ SOCK_ESTABLISHED 손싀을 κ°μ§€ν•˜κ³  μžλ™μœΌλ‘œ μž¬μ ‘μ†ν•œλ‹€. μ„œλ²„λŠ” μ†ŒμΌ“ μ’…λ£Œ μ‹œ λ””λ°”μ΄μŠ€λ₯Ό μ¦‰μ‹œ online: false둜 ν‘œμ‹œν•œλ‹€. 이 폐루프 κ°€μš©μ„± λͺ¨λΈμ€ λŒ€μ‹œλ³΄λ“œκ°€ 항상 μ‹€μ œ λ””λ°”μ΄μŠ€ μƒνƒœλ₯Ό λ°˜μ˜ν•˜λ„λ‘ 보μž₯ν•œλ‹€.

πŸ”· 단일 μ €μž₯μ†Œμ˜ ν’€μŠ€νƒ

νŽŒμ›¨μ–΄(C/STM32), λ°±μ—”λ“œ(Node.js), ν”„λ‘ νŠΈμ—”λ“œ(HTML/CSS/JS)κ°€ λͺ…ν™•ν•œ 뢄리 ꡬ쑰둜 ν•˜λ‚˜μ˜ μ €μž₯μ†Œμ— κ³΅μ‘΄ν•œλ‹€. 개발자 λˆ„κ΅¬λ“  ν΄λ‘ ν•˜κ³  IP μ£Όμ†Œ 두 개λ₯Ό μ„€μ •ν•˜λ©΄ λͺ‡ λΆ„ μ•ˆμ— μ—”λ“œ-투-μ—”λ“œλ‘œ λ™μž‘ν•˜λŠ” μ‹œμŠ€ν…œμ„ 얻을 수 μžˆλ‹€.


03 β€” μ‹œμŠ€ν…œ μ•„ν‚€ν…μ²˜

 
03 β€” μ‹œμŠ€ν…œ μ•„ν‚€ν…μ²˜

04 β€” μ™œ W5500인가?

πŸ”· TOE TCP μ†ŒμΌ“ λͺ¨λ“œ β€” ν΄λΌμ΄μ–ΈνŠΈ κ°œμ‹œ μ˜μ† μ—°κ²°

이 ν”„λ‘œμ νŠΈλŠ” W5500의 **ν•˜λ“œμ›¨μ–΄ TCP μ†ŒμΌ“ λͺ¨λ“œ(Sn_MR_TCP)**λ₯Ό λ…νŠΉν•œ νŒ¨ν„΄μœΌλ‘œ μ‚¬μš©ν•œλ‹€: STM32κ°€ TCP ν΄λΌμ΄μ–ΈνŠΈλ‘œμ„œ Node.js μ„œλ²„μ— μ•„μ›ƒλ°”μš΄λ“œ 연결을 κ°œμ‹œν•œλ‹€. NAT 뒀에 μžˆλŠ” λ””λ°”μ΄μŠ€λ‚˜ μΈλ°”μš΄λ“œ 연결이 λ°”λžŒμ§ν•˜μ§€ μ•Šμ€ λ„€νŠΈμ›Œν¬μ—μ„œ μ˜¬λ°”λ₯Έ ν† ν΄λ‘œμ§€λ‹€.

c
// Core/Src/app_relay.c μ—μ„œ 확인 socket(RELAY_SOCKET, Sn_MR_TCP, 5000, 0);          // 둜컬 포트 5000 connect(RELAY_SOCKET, server_ip, SERVER_PORT);       // μ„œλ²„ :9000으둜 μ—°κ²° send_hello();                                        // {"type":"hello","deviceId":"relay-f105-01"} send_status();                                       // {"type":"status","relay1":"off"}

W5500의 TOEκ°€ TCP μƒνƒœ, μž¬μ „μ†‘, ACKλ₯Ό ν•˜λ“œμ›¨μ–΄μ—μ„œ μ „λΆ€ μ²˜λ¦¬ν•œλ‹€. STM32 λ£¨ν”„λŠ” getSn_SR()둜 μ—°κ²° μƒνƒœλ₯Ό ν™•μΈν•˜κ³  recv()둜 λͺ…령을 μˆ˜μ‹ ν•  뿐이닀 β€” νŽŒμ›¨μ–΄ μ½”λ“œμ— TCP μŠ€νƒμ΄ μ „ν˜€ μ—†λ‹€.

πŸ”· PHY 링크 λͺ¨λ‹ˆν„°λ§ β€” ν•˜λ“œμ›¨μ–΄ 레벨 μ—°κ²° 인식

νŽŒμ›¨μ–΄λŠ” μ΄ˆκΈ°ν™” 쀑 wizphy_getphylink()λ₯Ό 폴링해 μ†ŒμΌ“ λ™μž‘ μ‹œλ„ μ „ μ΅œλŒ€ 2μ΄ˆκ°„ 물리 이더넷 링크가 올라였기λ₯Ό κΈ°λ‹€λ¦°λ‹€. 케이블이 μ—°κ²°λ˜κΈ° 전에 μ†ŒμΌ“ λ™μž‘μ„ μ‹œλ„ν•˜λŠ” DIY ν”„λ‘œμ νŠΈμ˜ ν”ν•œ μ‹€νŒ¨ λͺ¨λ“œλ₯Ό λ°©μ§€ν•œλ‹€. W5500의 λ‚΄μž₯ PHY μƒνƒœ λ ˆμ§€μŠ€ν„°κ°€ 이λ₯Ό ν•¨μˆ˜ 호좜 ν•˜λ‚˜λ‘œ κ°€λŠ₯ν•˜κ²Œ ν•œλ‹€.

πŸ”· μžλ™ μž¬μ ‘μ† 루프 β€” 항상 μ—°κ²°λœ λ””λ°”μ΄μŠ€ λ™μž‘

메인 루프 λ§€ λ°˜λ³΅λ§ˆλ‹€ TCP μ—°κ²° μƒνƒœλ₯Ό ν™•μΈν•œλ‹€. μ—°κ²° λŠκΉ€ 감지 β†’ 1초 λ‚΄ μž¬μ ‘μ†. μ„œλ²„ μΈ‘ socket.on("close") ν•Έλ“€λŸ¬κ°€ λ””λ°”μ΄μŠ€λ₯Ό μ¦‰μ‹œ μ˜€ν”„λΌμΈμœΌλ‘œ ν‘œμ‹œν•œλ‹€. 이 두 κ°€μ§€κ°€ 합쳐져 μˆ˜λ™ κ°œμž… μ—†λŠ” 폐루프 κ°€μš©μ„± λͺ¨λΈμ„ ν˜•μ„±ν•œλ‹€.

πŸ”· Static IP β€” 결정둠적 λ„€νŠΈμ›Œν¬ 신원

NETINFO_STATIC, IP 192.168.31.50. 전원 νˆ¬μž… 직후 μ¦‰μ‹œ 도달 κ°€λŠ₯. DHCP λΆ€νŒ… μ§€μ—° μ—†μŒ, μ£Όμ†Œ λ³€κ²½ μ—†μŒ. κ³ μ • μœ„μΉ˜ 배포의 릴레이 λ…Έλ“œμ—μ„œ 항상 μ˜¬λ°”λ₯Έ 선택이닀.

πŸ”· κ²€μ¦λœ 증거 βœ…

  • socket(RELAY_SOCKET, Sn_MR_TCP, 5000, 0) β€” app_relay.cμ—μ„œ 직접 확인
  • connect(), send(), recv(), getSn_SR() β€” μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μ½”λ“œμ—μ„œ 확인
  • wizchip_init(), wizchip_setnetinfo(), getVERSIONR() β€” λΆ€νŒ… μ‹œ μΉ© 버전 읽기 확인
  • WaitForPhyLink()와 wizphy_getphylink() β€” μ†ŒμΌ“ μ „ PHY 링크 게이트 확인
  • teraterm_logs.txt β€” μ‹€μ œ ν•˜λ“œμ›¨μ–΄ λΆ€νŒ… μ‹œν€€μŠ€ μ‹œλ¦¬μ–Ό 둜그 μ €μž₯μ†Œμ— 포함
  • Server_based_Relay_controll.pdf β€” ν”„λ‘œμ νŠΈ λ¬Έμ„œ 포함

05 β€” 핡심 μ»΄ν¬λ„ŒνŠΈ

🌐 WIZnet W5500 β€” TCP TOE λͺ¨λ“œ (Sn_MR_TCP), ν΄λΌμ΄μ–ΈνŠΈ λͺ¨λ“œ

SPI1 λ²„μŠ€μ˜ ν•˜λ“œμ›¨μ–΄ μ˜€ν”„λ‘œλ“œ TCP/IP. STM32κ°€ μ„œλ²„ 포트 9000으둜 μ•„μ›ƒλ°”μš΄λ“œ TCP 연결을 κ°œμ‹œ. JSON λ©”μ‹œμ§€κ°€ 이 μ˜μ† μ†ŒμΌ“μœΌλ‘œ 흐름. νŽŒμ›¨μ–΄μ— TCP μŠ€νƒ μ—†μŒ β€” W5500이 μ‹€λ¦¬μ½˜μ—μ„œ 처리.

πŸ”§ STM32F103C8T6

72 MHz Cortex-M3. SPI1이 W5500 ꡬ동 (CS: PA4, RST: PB1). PB5κ°€ 릴레이 좜λ ₯ ꡬ동 (Active High). UART1이 Tera Term 디버그 좜λ ₯. STM32CubeIDE ν”„λ‘œμ νŠΈ 포함 (.ioc + .cproject).

πŸ–₯️ Node.js λ°±μ—”λ“œ (server.js)

TCP λ¦¬μŠ€λ„ˆ(:9000, λ””λ°”μ΄μŠ€ μΈ‘)와 HTTP μ„œλ²„(:8080, λŒ€μ‹œλ³΄λ“œ μΈ‘)λ₯Ό λͺ¨λ‘ μ‹€ν–‰ν•˜λŠ” 단일 파일 μ„œλ²„. JSON 라인 ν”„λ‘œν† μ½œ νŒŒμ‹±, μ„Έμ…˜ 기반 인증(PBKDF2 νŒ¨μŠ€μ›Œλ“œ ν•΄μ‹±), μ‚¬μš©μž/λ””λ°”μ΄μŠ€/둜그λ₯Ό μœ„ν•œ JSON 파일 λ°μ΄ν„°μŠ€ν† μ–΄, λŒ€μ‹œλ³΄λ“œ μ œμ–΄μš© REST API. μ™ΈλΆ€ λ°μ΄ν„°λ² μ΄μŠ€ λΆˆν•„μš”.

🌐 μ›Ή 관리 λŒ€μ‹œλ³΄λ“œ (frontend/)

정적 HTML/CSS/JS λŒ€μ‹œλ³΄λ“œ. 둜그인 β†’ κ°œμš” μš”μ•½ β†’ λ””λ°”μ΄μŠ€ λͺ©λ‘ β†’ 릴레이 ν† κΈ€ β†’ λ””λ°”μ΄μŠ€λ³„ 이벀트 둜그. μ„€μΉ˜ 없이 μ–΄λŠ λΈŒλΌμš°μ €μ—μ„œλ‚˜ μ™„μ „ λ™μž‘. Node.js λ°±μ—”λ“œ REST API둜 읽기/μ“°κΈ°.


06 β€” ν™œμš© μ‹œλ‚˜λ¦¬μ˜€

01. 슀마트 λΉŒλ”© μ„œλΈŒμ‹œμŠ€ν…œ

λΉŒλ”© μžλ™ν™” μ—”μ§€λ‹ˆμ–΄κ°€ HVAC 댐퍼, μ‘°λͺ… 회둜, 도어락 μ œμ–΄λ₯Ό μœ„ν•΄ STM32+W5500 릴레이 λ…Έλ“œλ₯Ό λ°°ν¬ν•œλ‹€. 쀑앙 Node.js μ„œλ²„κ°€ λͺ¨λ“  λ…Έλ“œλ₯Ό 톡합 λŒ€μ‹œλ³΄λ“œλ‘œ μ§‘κ³„ν•˜λ©°, νƒ€μž„μŠ€νƒ¬ν”„ λ‘œκ·Έκ°€ μ‹œμ„€ κ΄€λ¦¬μ˜ κΈ°λ³Έ 감사 μš”κ±΄μ„ μΆ©μ‘±ν•œλ‹€.

02. 연ꡬ싀 μž₯λΉ„ 전원 관리

연ꡬ싀이 μž₯λΉ„ λž™λ§ˆλ‹€ 릴레이 λ…Έλ“œλ₯Ό μ„€μΉ˜ν•œλ‹€. κ΄€λ¦¬μž λŒ€μ‹œλ³΄λ“œκ°€ μ–΄λ–€ μž₯비에 전원이 듀어와 μžˆλŠ”μ§€ ν•œλˆˆμ— 보여쀀닀. μž₯λΉ„λ₯Ό 물리적으둜 μ΄λ™ν•˜μ§€ μ•Šκ³  μ›κ²©μœΌλ‘œ 전원을 ν† κΈ€ν•  수 μžˆλ‹€. 이벀트 λ‘œκ·Έκ°€ 전원 사이클링 기둝을 μ œκ³΅ν•œλ‹€.

03. μ‚°μ—…μš© 파일럿 라인 μ œμ–΄

μ†Œκ·œλͺ¨ 제쑰 라인이 릴레이 λ…Έλ“œλ₯Ό μ‚¬μš©ν•΄ 컨베이어 λͺ¨ν„°λ‚˜ 곡압 밸브λ₯Ό 쀑앙 HMI λΈŒλΌμš°μ € μΈν„°νŽ˜μ΄μŠ€μ—μ„œ ν™œμ„±ν™”/λΉ„ν™œμ„±ν™”ν•œλ‹€. ν•˜νŠΈλΉ„νŠΈ λͺ¨λ‹ˆν„°λ§μ΄ λ…Έλ“œκ°€ λ„€νŠΈμ›Œν¬ 연결을 μžƒμœΌλ©΄ μš΄μ˜μžμ—κ²Œ μ¦‰μ‹œ μ•Œλ¦°λ‹€.

04. ν™ˆ μ˜€ν† λ©”μ΄μ…˜ κ²Œμ΄νŠΈμ›¨μ΄

메이컀가 μ‘°λͺ…, 선풍기, κ΄€κ°œ 밸브의 전원 μŠ€μœ„μΉ˜ 뒀에 릴레이 λ…Έλ“œλ₯Ό μ„€μΉ˜ν•œλ‹€. 자체 ν˜ΈμŠ€νŒ… Node.js μ„œλ²„(라즈베리 파이 λ˜λŠ” NAS)κ°€ ν΄λΌμš°λ“œ 의쑴 없이 둜컬 μ „μš© μ œμ–΄λ₯Ό μ œκ³΅ν•œλ‹€.


κ²°λ‘ 

이 ν”„λ‘œμ νŠΈλŠ” W5500의 ν•˜λ“œμ›¨μ–΄ TCP μ˜€ν”„λ‘œλ“œκ°€ 맨 STM32F103을 JSON ν”„λ‘œν† μ½œ, ν•˜νŠΈλΉ„νŠΈ λͺ¨λ‹ˆν„°λ§, REST λŒ€μ‹œλ³΄λ“œ, 이벀트 λ‘œκΉ…μ„ κ°–μΆ˜ μ™„μ „ κ΄€λ¦¬ν˜• IoT 릴레이 λ…Έλ“œλ‘œ μ „ν™˜μ‹œν‚¨λ‹€λŠ” 것을 보여쀀닀.

  • βœ… W5500 TCP TOE ν΄λΌμ΄μ–ΈνŠΈ λͺ¨λ“œ 확인 β€” app_relay.cμ—μ„œ socket(Sn_MR_TCP) + connect()
  • βœ… μ†ŒμΌ“ μ „ PHY 링크 게이트 β€” wizphy_getphylink() 폴링 확인
  • βœ… μžλ™ μž¬μ ‘μ† 루프 β€” 메인 루프 λ§€ 반볡 μ—°κ²° μƒνƒœ 확인
  • βœ… JSON 라인 ν”„λ‘œν† μ½œ μ–‘λ°©ν–₯: hello / status / command / ack / heartbeat
  • βœ… 인증, REST API, μ˜μ† 이벀트 둜그(μ΅œλŒ€ 5,000건)λ₯Ό κ°–μΆ˜ Node.js λ°±μ—”λ“œ
  • βœ… λΈŒλΌμš°μ € 기반 관리 λŒ€μ‹œλ³΄λ“œ β€” ν΄λΌμ΄μ–ΈνŠΈ μ„€μΉ˜ λΆˆν•„μš”
  • βœ… μ‹€μ œ ν•˜λ“œμ›¨μ–΄μ—μ„œ μΊ‘μ²˜ν•œ μ‹œλ¦¬μ–Ό λΆ€νŒ… 둜그(teraterm_logs.txt) 포함
  • βœ… 단일 μ €μž₯μ†Œ ν’€μŠ€νƒ: νŽŒμ›¨μ–΄ + λ°±μ—”λ“œ + ν”„λ‘ νŠΈμ—”λ“œ, 3컀밋 κΉ”λ”ν•œ 이λ ₯

릴레이 ν•˜λ‚˜, STM32, 이더넷 잭 ν•˜λ‚˜. 이런 μ’…λ₯˜μ˜ ν”„λ‘œμ νŠΈλ„ W5500을 μ‚¬μš©ν•œλ‹€.


07 β€” WIZnet Makers μœ μ‚¬ ν”„λ‘œμ νŠΈ

ν”Œλž«νΌμ—μ„œ 같은 릴레이-over-이더넷 곡간을 λ‹€λ£¨λŠ” ν”„λ‘œμ νŠΈλ“€μ΄ λ‹€μˆ˜ μ‘΄μž¬ν•œλ‹€.

Relay control via HTTP Rest Protocol (WIZnet 곡식)은 HTTP RESTλ₯Ό λ””λ°”μ΄μŠ€μ—μ„œ 직접 μ²˜λ¦¬ν•œλ‹€. 더 λ‹¨μˆœν•œ ν† ν΄λ‘œμ§€ β€” 쀑앙 μ„œλ²„ 없이 λΈŒλΌμš°μ €κ°€ MCU에 직접 톡신. β†’ https://maker.wiznet.io/WIZnet/projects/relay-control-via-http-rest-protocol/

ESP32 (38-pin) + W5500: Offline LAN Relay Control with a Simple Web Server (sophia, 2026)λŠ” ESP32+W5500κ³Ό λ‚΄μž₯ μ›Ή μ„œλ²„λ₯Ό μ‚¬μš©ν•œλ‹€ β€” 별도 λ°±μ—”λ“œ μ„œλ²„ 없이 λΈŒλΌμš°μ €κ°€ MCU에 직접 접속. β†’ https://maker.wiznet.io/sophia/projects/esp32-38-pin-w5500-offline-lan-relay-control-with-a-simple-web-server/

8 Channel Ethernet Relay Controller (Alan, 2025)λŠ” PoE μ§€μ›μœΌλ‘œ 8μ±„λ„κΉŒμ§€ ν™•μž₯ν•œλ‹€ β€” ν•˜λ“œμ›¨μ–΄ 쀑심, μ†Œν”„νŠΈμ›¨μ–΄ λŒ€μ‹œλ³΄λ“œ μ—†μŒ. β†’ https://maker.wiznet.io/Alan/projects/8-channel-ethernet-relay-controller-support-poe-and-usb/

 μ΄ ν”„λ‘œμ νŠΈHTTP RESTESP32 μ›Ή μ„œλ²„8채널 PoE
MCUSTM32F103β€”ESP32β€”
W5500 μ—­ν• TCP μ œμ–΄ 채널HTTP μ„œλ²„μ˜¨λ³΄λ“œμ˜¨λ³΄λ“œ
ν”„λ‘œν† μ½œJSON over TCPHTTP RESTHTTP (λ‚΄μž₯)β€”
쀑앙 μ„œλ²„βœ… Node.js❌❌❌
μ›Ή λŒ€μ‹œλ³΄λ“œβœ… λΆ„λ¦¬ν˜•βœ… (MCU λ‚΄)βœ… (MCU λ‚΄)❌
인증 + λ‘œκΉ…βœ…βŒβŒβŒ
릴레이 채널1λ‹€μ–‘λ‹€μ–‘8
ν•˜νŠΈλΉ„νŠΈ/μž¬μ ‘μ†βœ…βŒβŒβŒ

이 ν”„λ‘œμ νŠΈμ˜ 핡심 차별점은 인증과 λ‘œκΉ…μ„ κ°–μΆ˜ 쀑앙화 μ„œλ²„ μ•„ν‚€ν…μ²˜ β€” 릴레이 λ…Έλ“œλ₯Ό λ…λ¦½ν˜• μ»¨νŠΈλ‘€λŸ¬κ°€ μ•„λ‹Œ κ΄€λ¦¬ν˜• λ””λ°”μ΄μŠ€λ‘œ μ·¨κΈ‰ν•˜λŠ” μœ μΌν•œ ν”„λ‘œμ νŠΈλ‹€. νŠΈλ ˆμ΄λ“œμ˜€ν”„λŠ” 배포 λ³΅μž‘μ„±: Node.js λ°±μ—”λ“œκ°€ λ³„λ„λ‘œ μ‹€ν–‰λ˜μ–΄μ•Ό ν•œλ‹€. μΈμ‚¬μ΄νŠΈλŠ” 릴레이 배포가 λ…Έλ“œ ν•œλ‘ 개λ₯Ό λ„˜μ–΄ ν™•μž₯되면 쀑앙화 관리가 ν•„μˆ˜κ°€ λœλ‹€λŠ” 것이고, 이 ν”„λ‘œμ νŠΈλŠ” 이미 그것을 μœ„ν•΄ μ„€κ³„λœ μƒνƒœκ³„ λ‚΄ μœ μΌν•œ μ‘΄μž¬λ‹€.


Q&A

Q: STM32κ°€ μ„œλ²„μ— μ•„μ›ƒλ°”μš΄λ“œλ‘œ μ—°κ²°ν•˜λŠ” μ΄μœ λŠ”? A: ν΄λΌμ΄μ–ΈνŠΈ κ°œμ‹œ TCPκ°€ NAT 뒀에 μžˆκ±°λ‚˜ 동적 IPλ₯Ό κ°€μ§„ λ””λ°”μ΄μŠ€μ— μ˜¬λ°”λ₯Έ λͺ¨λΈμ΄λ‹€. λ””λ°”μ΄μŠ€λŠ” 항상 μ„œλ²„μ˜ κ³ μ • IPλ₯Ό μ•Œκ³  있고, μ„œλ²„λŠ” λ””λ°”μ΄μŠ€ IPλ₯Ό 미리 μ•Œ ν•„μš”κ°€ μ—†λ‹€. hello λ©”μ‹œμ§€κ°€ λ””λ°”μ΄μŠ€ IDλ₯Ό 전달해 μ„œλ²„κ°€ μ ‘μ†ν•˜λŠ” λͺ¨λ“  λ””λ°”μ΄μŠ€λ₯Ό 등둝할 수 있게 ν•œλ‹€.

Q: HTTPλ‚˜ MQTT λŒ€μ‹  TCP μœ„ JSON을 μ‚¬μš©ν•œ μ΄μœ λŠ”? A: 뉴라인 ꡬ뢄 JSON over TCPλŠ” 64KB ν”Œλž˜μ‹œλ₯Ό κ°€μ§„ STM32F103μ—μ„œ κ°€μž₯ κ°€λ²Όμš΄ μ™„μ „ κΈ°λŠ₯ μ˜΅μ…˜μ΄λ‹€. HTTPλŠ” μš”μ²­/응닡 ν”„λ ˆμ΄λ° μ˜€λ²„ν—€λ“œλ₯Ό μΆ”κ°€ν•˜κ³ , MQTTλŠ” λΈŒλ‘œμ»€κ°€ ν•„μš”ν•˜λ‹€. Node.js μ„œλ²„λŠ” μ„Έ μ€„μ˜ μ½”λ“œλ‘œ 뉴라인 ꡬ뢄 JSON을 νŒŒμ‹±ν•  수 μžˆλ‹€.

Q: μ—¬λŸ¬ 릴레이 λ…Έλ“œλ‘œ ν™•μž₯될 수 μžˆλ‚˜? A: 섀계상 κ°€λŠ₯ν•˜λ‹€. μ„œλ²„ μΈ‘ deviceSockets Mapκ³Ό devices.json λ°μ΄ν„°μŠ€ν† μ–΄λŠ” deviceIdλ₯Ό ν‚€λ‘œ ν•œλ‹€. 각 νŽŒμ›¨μ–΄ λ…Έλ“œλŠ” κ³ μœ ν•œ DEVICE_ID λ¬Έμžμ—΄κ³Ό λ™μΌν•œ μ„œλ²„ IP만 있으면 λœλ‹€. λŒ€μ‹œλ³΄λ“œκ°€ μ—°κ²°λœ λͺ¨λ“  λ””λ°”μ΄μŠ€λ₯Ό μžλ™μœΌλ‘œ λ‚˜μ—΄ν•œλ‹€.

Comments

Similar projects you might like

Comments