BACnet is an internationally standardized communication protocol for building automation that enables devices from different manufacturers—such as heating, ventilation, air conditioning, lighting, and security systems—to communicate with one another. While current BACnet systems typically use Ethernet as the transmission medium (BACnet/IP), older systems typically used RS485 (BACnet MSTP) as Layer 0.
Since BACnet stacks are very large and therefore place higher demands on RAM and program memory, it has been hard to integrate a BACnet server onto an small microcontroller.
BACnet operates on the client-server principle. A BACnet server provides data (such as temperatures, sensor readings, or switch states) within a building automation network. A BACnet client is the receiving device or control software that actively retrieves this data or sends commands to the server.
In this tutorial, I’d like to show you how to implement a simple BACnet MSTP server on the ESP32 (Huzzah 32 Feather board) and an additional RS485 Wing.
WiringAs for BACnet MS/TP, the most common connection method is the daisy-chain bus configuration, where all the devices in the network are connected in a linear chain using a single RS485 cable.
To do this, connect the “+” and “-” terminals of each device to one another. The RS485 Wing is equipped with a 5-pin connector, where two pins are labeled ‘A’ and “B.” Pin A must be connected to the “+” terminals, and pin B to the “-” terminals of the other devices.
For longer distances, it is recommended to use a twisted-pair cable. Distances of up to one mile are possible via RS485.
Configuring the RS485 wingFor BACnet MSTP communication, the DIP switches and jumpers on the RS485 wing must be configured correctly.
The Feather wing has two DIP switches and a slide switch, which must be set accordingly for proper function.
The S1 DIP switch can be used to select the control of the send/receive switchover. We let the wing automatically switch the transmit/receive direction. This means that we no longer have to worry about this later in the software. S1 is therefore set to OFF - ON - ON - OFF.
The wing can be configured to half or full duplex mode with S4. S4 can also be used to switch on the pull-up and pull-down resistors for fail safe biasing.
We need half-duplex for the RS485 function and also activate biasing. All S4 switches are therefore set to ON.
The terminating resistor can be switched on with slide switch S2. This is only necessary if the wing is connected to one of the two ends of the bus line. Otherwise, S2 remains off.
SoftwareHarish Patel’s BACnetLight library provides a stripped-down version of a BACnet stack that runs on a microcontroller. Although this stack is actually intended for the ESP32, it also runs without any issues on other microcontrollers.
Since this library cannot currently be installed via the Library Manager, we must first download the library from GitHub and unzip it into the Arduino\Library directory.
For an initial test, I created a small sample program that includes a simple BACnet MSTP server with two data points.
One data point is an analog input that, in our example, receives data from a temperature sensor (the sensor values are generated randomly by the program).
The other data point is a binary output, which in our example is implemented as a virtual “relay” and outputs the relay's switching state via the debug interface.
Test the MSTP serverWe now have a simple BACnet MSTP server that we can integrate into an existing installation. However, to test the device, we still need a client.
You can easily set up a client on a Windows or Linux PC using the free software YABE (Yet Another BACnet Explorer). In order for YABE to communicate via BACnet MSTP, we also need a standard USB-to-RS485 adapter.
Once the installation is complete, we can launch YABE. First, we go to Functions --> Add BACnet Channel:
Now, in the right-hand section of the window, under “BACnet/MSTP over serial, ” we set the COM port for the connected RS485 adapter (COM12 in my case) and, if necessary, the baud rate and other parameters:
Our BACnet device is now automatically detected and displayed under the channel. If we double-click on the detected device, we can see three objects in the “Objects” window: Device Properties, Analog_Value, and BINARY_OUTPUT.
When you click on an object, its properties are displayed in the “Properties” window on the right, and you can also modify those properties. For example, if we click on BINARY_OUTPUT, we can change the relay state by modifying the “Present Value” variable in the Properties window (0 = relay open, 1 = relay closed).
We can then see the result in the debug output of the Arduino IDE:










Comments