Wiznet makers

mason

Published July 08, 2026 © MIT license (MIT)

173 UCC

21 WCC

33 VAR

0 Contests

0 Followers

0 Following

Original Link

BACnetLight

BACnetLight

COMPONENTS Hardware components

Espressif - ESP32

x 1


WIZnet - W5500

x 1


PROJECT DESCRIPTION

프로젝트 개요

BACnetLight는 ESP32에서 BACnet/IP와 BACnet/MSTP를 구현할 수 있도록 만든 경량 C++ 라이브러리입니다. 이 프로젝트에서 WIZnet W5500은 ESP32에 유선 Ethernet 연결을 제공하며, BACnet/IP 통신을 위한 UDP 전송 계층으로 사용됩니다.

빌딩 자동화 게이트웨이 관점에서 ESP32는 센서 값, 릴레이 상태, Modbus RTU 레지스터, 디지털 입력과 같은 현장 데이터를 수집합니다. 애플리케이션에서는 이 데이터를 BACnet Analog Value, Binary Value, Analog Output, Binary Output 같은 객체로 등록합니다. 이후 BMS, HVAC 컨트롤러, YABE 같은 BACnet 클라이언트가 W5500 기반 유선 네트워크를 통해 해당 데이터를 읽거나 제어할 수 있습니다.

프로젝트에는 Modbus RTU 데이터를 BACnet/IP로 변환하는 ModbusBACnetGateway 예제도 포함되어 있습니다. 이 구조는 RS485 기반 현장 장비를 Ethernet 기반 빌딩 자동화망에 연결하는 Industrial IoT 게이트웨이에 적합합니다.

BACnetLight는 대형 BACnet 스택을 그대로 포팅하는 방식이 아니라, ESP32 같은 마이크로컨트롤러 환경에 맞춘 작은 구현을 목표로 합니다. 따라서 제한된 메모리와 처리 성능 안에서 필요한 BACnet 기능만 선택적으로 구현하려는 프로젝트에 유용합니다.

이미지 출처 : AI 생성

Where WIZnet Fits

이 프로젝트에서 사용되는 WIZnet 제품은 W5500입니다. W5500은 ESP32와 SPI로 연결되는 유선 Ethernet 컨트롤러이며, BACnet/IP 네트워크와 ESP32 사이에서 UDP 기반 Ethernet 통신을 담당합니다.

W5500은 하드웨어 TCP/IP 스택, 10/100 Ethernet MAC/PHY, 32 KB 내부 버퍼, 8개 독립 소켓을 제공합니다. 이 구성에서 ESP32는 BACnet 객체 처리와 현장 데이터 매핑에 집중하고, W5500은 유선 네트워크 인터페이스를 담당합니다.

빌딩 자동화 환경에서는 네트워크 안정성이 중요합니다. BMS, HVAC, 에너지 미터, Modbus 장비는 장시간 고정 설치되는 경우가 많기 때문에 통신 경로가 예측 가능해야 합니다. Wi-Fi는 설치가 간단하지만 전파 간섭, AP 상태, 재연결 지연의 영향을 받을 수 있습니다. 반면 W5500 기반 유선 Ethernet은 링크 상태가 명확하고, VLAN 또는 전용 설비망에 연결하기 쉽습니다.

이러한 이유로 W5500은 작은 MCU 보드로 BACnet/IP 게이트웨이를 구현하면서도, 무선 연결보다 안정적인 설비망 구성을 만들고자 할 때 적합합니다.

Implementation Notes

examples/BasicDevice/BasicDevice.ino — BACnet/IP over W5500 초기화

#include <EthernetUdp.h>

BACnetLight bacnet;
EthernetUDP bacnetUdp;

Ethernet.init(5);
Ethernet.begin(mac, ip);

bacnet.begin(1234, "My-First-BACnet", bacnetTarget, bacnetUdp);

이 코드는 W5500을 Arduino Ethernet 라이브러리의 네트워크 장치로 초기화한 뒤, EthernetUDP 객체를 BACnetLight에 전달합니다. bacnet.begin()에서는 BACnet device instance, device name, broadcast target, UDP transport가 함께 설정됩니다.

BACnetLight는 W5500 레지스터를 직접 제어하지 않습니다. 대신 Arduino의 EthernetUDP 추상화를 통해 BACnet/IP 패킷을 송수신합니다. 예제에서는 W5500이 감지되지 않으면 "No W5500 Ethernet controller found" 메시지를 출력하고 실행을 중단하도록 구성되어 있습니다.

examples/ModbusBACnetGateway/ModbusBACnetGateway.ino — Industrial IoT 게이트웨이용 W5500 설정

#define ETH_CS   18
#define ETH_SCK  14
#define ETH_MISO 33
#define ETH_MOSI 13

SPI.begin(ETH_SCK, ETH_MISO, ETH_MOSI, ETH_CS);
Ethernet.init(ETH_CS);
Ethernet.begin(mac, ip);

이 예제는 ESP32의 HSPI 핀에 W5500을 연결하는 구성을 보여줍니다. CS, SCK, MISO, MOSI 핀을 코드에서 명시한 뒤 SPI.begin(), Ethernet.init(), Ethernet.begin() 순서로 Ethernet을 초기화합니다.

초기화 후에는 bacnet.begin(1234, "Modbus-BACnet-GW", bacnetTarget, bacnetUdp)로 BACnet/IP 장치를 시작하고, Modbus 레지스터 값을 BACnet Analog Value와 Binary Value로 매핑합니다. 이 방식은 RS485 기반 현장 장비를 BACnet/IP 기반 BMS에 연결할 때 유용합니다.

Practical Tips / Pitfalls

ESP32와 W5500의 CS, SCK, MISO, MOSI 핀 정의가 코드와 실제 배선에서 일치해야 합니다.

BACnet/IP 기본 포트는 UDP 47808입니다. 방화벽, VLAN, 라우터 설정에서 해당 트래픽이 차단되지 않는지 확인해야 합니다.

W5500이 감지되지 않으면 전원, GND, SPI 배선, CS 핀 설정을 먼저 점검하는 것이 좋습니다.

BACnet/IP는 기본적으로 인증과 암호화가 없는 UDP 기반 프로토콜입니다. 외부 인터넷에 직접 노출하지 말고, 빌딩 자동화 전용 VLAN 또는 내부망에 배치해야 합니다.

COV 알림을 사용할 때는 변화 감지 임계값을 너무 낮게 설정하지 않는 것이 좋습니다. 센서 노이즈가 많은 값은 불필요한 BACnet 트래픽을 만들 수 있습니다.

RS485 기반 Modbus 또는 BACnet/MSTP를 함께 사용할 경우 MAX485의 DE/RE 방향 제어, 공통 GND, 종단 저항, baud rate를 별도로 검증해야 합니다.

BACnetLight는 경량 구현이므로 segmentation, alarm/event reporting, scheduling object, trend logging, BACnet/SC 같은 기능은 지원 범위를 확인한 뒤 적용해야 합니다.

유사 프로젝트

Industrial Multi-Protocol Gateway (MTGateway)

유사점

비교 항목BACnetLightMTGateway
적용 분야빌딩 자동화, BACnet 장치 구현빌딩 자동화, 산업용 게이트웨이
BACnet/IPBACnet/IP와 BACnet/MSTP 지원BACnet/IP 지원
W5500 역할ESP32의 유선 Ethernet 인터페이스STM32의 유선 Ethernet 인터페이스
프로토콜 연동Modbus 데이터를 BACnet 객체로 매핑Modbus, BACnet/IP, MQTT 연동
네트워크 방식EthernetUDP 기반 BACnet/IP 통신W5500 소켓 기반 다중 통신
현장 데이터 처리센서 값과 레지스터를 BACnet 객체로 노출GPIO 입력을 BACnet 객체로 노출

차이점

비교 항목BACnetLightMTGateway
프로젝트 성격경량 BACnet 라이브러리다중 프로토콜 게이트웨이
MCU 플랫폼ESP32STM32F103RCT6
주요 목적BACnet 장치 구현산업용 프로토콜 통합
지원 프로토콜BACnet/IP, BACnet/MSTPModbus TCP/RTU/ASCII, BACnet/IP, MQTT, HTTP
설정 방식코드 기반 설정웹 브라우저 기반 설정 지원
W5500 활용BACnet/IP UDP 전송 중심HTTP, Modbus TCP, BACnet/IP 소켓 분리
확장 방향BACnet 장치, Modbus-to-BACnet 예제스마트 빌딩, IIoT, 클라우드 연동
난이도비교적 접근 쉬움구조가 더 복잡함

FAQ

Q: 왜 이 프로젝트에서 W5500을 사용하나요?
A: BACnet/IP는 UDP 기반 유선 네트워크와 잘 맞습니다. W5500은 ESP32에 SPI로 연결되는 Ethernet 컨트롤러이며, 하드웨어 TCP/IP 스택과 내부 버퍼를 제공하므로 ESP32가 BACnet 객체 처리와 현장 데이터 매핑에 집중할 수 있습니다.

Q: ESP32에는 어떻게 연결하나요?
A: W5500은 SPI로 연결합니다. 프로젝트 예제에서는 CS, SCK, MISO, MOSI 핀을 정의한 뒤 SPI.begin(), Ethernet.init(), Ethernet.begin() 순서로 Ethernet을 초기화합니다.

Q: W5500은 이 게이트웨이에서 어떤 역할을 하나요?
A: W5500은 BACnet/IP 측 유선 Ethernet 인터페이스를 담당합니다. ESP32가 Modbus 레지스터나 센서 값을 BACnet 객체로 만들면, W5500은 해당 데이터를 BMS 또는 BACnet 클라이언트가 UDP 기반 BACnet/IP로 읽고 쓸 수 있게 합니다.

Q: 초보자도 따라 할 수 있나요?
A: 기본 BACnet 장치 예제는 Arduino Ethernet 라이브러리와 ESP32 개발 경험이 있으면 접근 가능합니다. 다만 Industrial IoT 게이트웨이로 사용하려면 BACnet object model, IP 주소와 브로드캐스트, UDP 47808, RS485 방향 제어, Modbus 레지스터 매핑을 이해해야 합니다.

Q: Wi-Fi 대신 W5500 유선 Ethernet을 쓰는 이유는 무엇인가요?
A: Wi-Fi도 BACnet/IP 전송에 사용할 수 있지만, 빌딩 자동화 게이트웨이는 보통 장시간 고정 설치됩니다. W5500 기반 유선 Ethernet은 링크 상태와 배선 경로가 명확하고, VLAN이나 설비망 분리에 적합합니다. HVAC, 에너지 계측, Modbus-BACnet 브리지처럼 안정성이 중요한 Industrial IoT 구성에서는 유선 연결이 더 적합할 수 있습니다.

 

Project Overview

BACnetLight is a lightweight C++ library designed to implement BACnet/IP and BACnet/MSTP on the ESP32. In this project, the WIZnet W5500 provides a wired Ethernet connection for the ESP32 and is used as the UDP transport layer for BACnet/IP communication.

From a building automation gateway perspective, the ESP32 collects field data such as sensor values, relay states, Modbus RTU registers, and digital inputs. In the application layer, this data is registered as BACnet objects such as Analog Value, Binary Value, Analog Output, and Binary Output. BACnet clients such as a BMS, HVAC controller, or YABE can then read or control this data through the W5500-based wired network.

The project also includes a ModbusBACnetGateway example that converts Modbus RTU data into BACnet/IP. This structure is suitable for an Industrial IoT gateway that connects RS485-based field devices to an Ethernet-based building automation network.

BACnetLight does not aim to port a large BACnet stack directly. Instead, it focuses on a smaller implementation suited to microcontroller environments such as the ESP32. This makes it useful for projects that need to selectively implement required BACnet functions within limited memory and processing resources.

Image source: AI-generated

Where WIZnet Fits

The WIZnet product used in this project is the W5500. The W5500 is a wired Ethernet controller connected to the ESP32 via SPI, and it handles UDP-based Ethernet communication between the BACnet/IP network and the ESP32.

The W5500 provides a hardware TCP/IP stack, 10/100 Ethernet MAC/PHY, a 32 KB internal buffer, and 8 independent sockets. In this configuration, the ESP32 focuses on BACnet object processing and field data mapping, while the W5500 handles the wired network interface.

Network stability is important in building automation environments. BMS systems, HVAC equipment, energy meters, and Modbus devices are often installed for long-term operation, so the communication path must be predictable. Wi-Fi is easy to deploy, but it can be affected by radio interference, access point conditions, and reconnection delays. In contrast, W5500-based wired Ethernet provides a clear link status and is easier to connect to a VLAN or dedicated facility network.

For this reason, the W5500 is well suited for building a BACnet/IP gateway on a small MCU board while maintaining a more stable facility network configuration than wireless connectivity.

Implementation Notes

examples/BasicDevice/BasicDevice.ino — Initializing BACnet/IP over W5500

#include <EthernetUdp.h>

BACnetLight bacnet;
EthernetUDP bacnetUdp;

Ethernet.init(5);
Ethernet.begin(mac, ip);

bacnet.begin(1234, "My-First-BACnet", bacnetTarget, bacnetUdp);

This code initializes the W5500 as a network device through the Arduino Ethernet library and then passes the EthernetUDP object to BACnetLight. In bacnet.begin(), the BACnet device instance, device name, broadcast target, and UDP transport are configured together.

BACnetLight does not directly control the W5500 registers. Instead, it sends and receives BACnet/IP packets through Arduino’s EthernetUDP abstraction. In the example, if the W5500 is not detected, the program prints "No W5500 Ethernet controller found" and stops execution.

examples/ModbusBACnetGateway/ModbusBACnetGateway.ino — W5500 Setup for an Industrial IoT Gateway

#define ETH_CS   18
#define ETH_SCK  14
#define ETH_MISO 33
#define ETH_MOSI 13

SPI.begin(ETH_SCK, ETH_MISO, ETH_MOSI, ETH_CS);
Ethernet.init(ETH_CS);
Ethernet.begin(mac, ip);

This example shows how the W5500 is connected to the ESP32’s HSPI pins. The CS, SCK, MISO, and MOSI pins are defined in the code, and Ethernet is initialized in the order of SPI.begin(), Ethernet.init(), and Ethernet.begin().

After initialization, the BACnet/IP device is started with bacnet.begin(1234, "Modbus-BACnet-GW", bacnetTarget, bacnetUdp), and Modbus register values are mapped to BACnet Analog Value and Binary Value objects. This method is useful when connecting RS485-based field devices to a BACnet/IP-based BMS.

Practical Tips / Pitfalls

The CS, SCK, MISO, and MOSI pin definitions for the ESP32 and W5500 must match the actual wiring.

The default BACnet/IP port is UDP 47808. Make sure this traffic is not blocked by firewall, VLAN, or router settings.

If the W5500 is not detected, first check the power, GND, SPI wiring, and CS pin configuration.

BACnet/IP is a UDP-based protocol that does not provide authentication or encryption by default. Do not expose it directly to the public internet. It should be placed on a dedicated building automation VLAN or internal network.

When using COV notifications, avoid setting the change detection threshold too low. Noisy sensor values can generate unnecessary BACnet traffic.

When using RS485-based Modbus or BACnet/MSTP together, the MAX485 DE/RE direction control, common GND, termination resistor, and baud rate must be verified separately.

BACnetLight is a lightweight implementation, so features such as segmentation, alarm/event reporting, scheduling objects, trend logging, and BACnet/SC should be checked before deployment.

Similar Project

Industrial Multi-Protocol Gateway (MTGateway)

Similarities

Comparison ItemBACnetLightMTGateway
Application fieldBuilding automation, BACnet device implementationBuilding automation, industrial gateway
BACnet/IPSupports BACnet/IP and BACnet/MSTPSupports BACnet/IP
W5500 roleWired Ethernet interface for ESP32Wired Ethernet interface for STM32
Protocol integrationMaps Modbus data to BACnet objectsIntegrates Modbus, BACnet/IP, and MQTT
Network methodBACnet/IP communication based on EthernetUDPMulti-channel communication based on W5500 sockets
Field data handlingExposes sensor values and registers as BACnet objectsExposes GPIO inputs as BACnet objects

Differences

Comparison ItemBACnetLightMTGateway
Project typeLightweight BACnet libraryMulti-protocol gateway
MCU platformESP32STM32F103RCT6
Main purposeBACnet device implementationIndustrial protocol integration
Supported protocolsBACnet/IP, BACnet/MSTPModbus TCP/RTU/ASCII, BACnet/IP, MQTT, HTTP
Configuration methodCode-based configurationWeb browser-based configuration support
W5500 usageFocused on BACnet/IP UDP transportSeparates sockets for HTTP, Modbus TCP, and BACnet/IP
Expansion directionBACnet devices, Modbus-to-BACnet examplesSmart buildings, IIoT, cloud connectivity
DifficultyRelatively accessibleMore complex structure

FAQ

Q: Why is the W5500 used in this project?
A: BACnet/IP works well with UDP-based wired networks. The W5500 is an Ethernet controller connected to the ESP32 via SPI, and it provides a hardware TCP/IP stack and internal buffer. This allows the ESP32 to focus on BACnet object processing and field data mapping.

Q: How is it connected to the ESP32?
A: The W5500 is connected through SPI. In the project example, the CS, SCK, MISO, and MOSI pins are defined first, and Ethernet is initialized in the order of SPI.begin(), Ethernet.init(), and Ethernet.begin().

Q: What role does the W5500 play in this gateway?
A: The W5500 handles the wired Ethernet interface on the BACnet/IP side. When the ESP32 converts Modbus registers or sensor values into BACnet objects, the W5500 allows a BMS or BACnet client to read and write that data over UDP-based BACnet/IP.

Q: Can beginners follow this project?
A: The basic BACnet device example is accessible if the developer has experience with the Arduino Ethernet library and ESP32 development. However, using it as an Industrial IoT gateway requires an understanding of the BACnet object model, IP addressing and broadcast behavior, UDP 47808, RS485 direction control, and Modbus register mapping.

Q: Why use W5500 wired Ethernet instead of Wi-Fi?
A: Wi-Fi can also be used for BACnet/IP transport, but building automation gateways are usually installed for long-term fixed operation. W5500-based wired Ethernet provides a clear link state and physical communication path, and it is better suited for VLAN or facility network separation. For Industrial IoT configurations where stability is important, such as HVAC, energy monitoring, and Modbus-to-BACnet bridges, wired Ethernet can be the more suitable option.

Documents
  • Github Code

Comments Write