# Setting up BACnet in CODESYS

In order to use the BACnet library, the setup of the BACnet IP datalink and the BACnet server in CODESYS must first be carried out.

## BACnet IP datalink

{% stepper %}
{% step %}
**Add Ethernet interface**

In the device tree the device *Ethernet* is attached. This sets the physical interface for BACnet communication.

<div align="left"><figure><img src="/files/fd66e4b1d87c4932ca73935db495e1e0efec7d3f" alt="" width="375"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Configure Ethernet interface**

Now the device is configured; the IP address of the target device (i.e. of the own CPU) must be specified. The IP address of the other BACnet participant is determined communicatively (*Who-Is* – request via broadcast telegram X.255).

<div align="left"><figure><img src="/files/39a2811db3645166bf7d2aed02e3b84dcab27bbb" alt="" width="375"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Add BACnet IP datalink**

In the device tree below the device *Ethernet* the device *BACnet IP datalink* is attached.

<div align="left"><figure><img src="/files/a2e0c55a166607b60fc68bc55aff1160285fc13b" alt="" width="375"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Configure BACnet IP datalink**

Here the BACnet network number and the UDP port used (default: 47808) are primarily specified.

<div align="left"><figure><img src="/files/419d81615ecfacb18581c846129a69bda9a1dead" alt="" width="375"><figcaption></figcaption></figure></div>
{% endstep %}
{% endstepper %}

## BACnet Server

{% stepper %}
{% step %}
**Add BACnet Server**

In the device tree the device *BACnet Server* is attached. It serves as the BACnet communication hub and must always be present. The client-server principle is applied: the client reads/writes data provided by the server.

<div align="left"><figure><img src="/files/fefeab16824a28e324b08e121116c7ea500421a7" alt="" width="375"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Configure BACnet Server**

The target device (our CPU) can be operated both as a BACnet server and as a BACnet client (also simultaneously).\
When operating as a BACnet server, the objects (for example a temperature actual value of the target device) are attached as devices beneath the BACnet server. When operating as a BACnet client, the objects are defined in CFC.\
\
Within it the character set used (UTF8) and the option *AutoStart* (automatic start of BACnet communication) are defined

<figure><img src="/files/3506d4d37dd6fb08bd8f04101b1555bcdf75489c" alt=""><figcaption></figcaption></figure>

Furthermore, the properties of the object *Device* (i.e. of the own BACnet server) can be specified here, which another BACnet participant can then read.

<figure><img src="/files/e022f9592ed026cb28d9338f31af016765517ad7" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://support.powerio.com/hub/codesys-hvac/en/hvac-bacnet2-library/beispiele/bacnet-einrichtung-in-codesys.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
