Skip to content

BACnet/IP

You can run the XRT BACnet/IP Device Service in a docker container.

The following examples use the iotechsys/xrt:1.1.49 docker image.

You can run on either of the following networks when running the XRT docker container:

  • Host
  • Docker bridge

Run on Host Network

To run on the host network, the docker image must run on the host machine's subnet. This allows the XRT BACnet/IP Device Service component to see any locally-connected BACnet devices that are on the same subnet as the host machine.

In the following example command the network flag is set to host, <xrt-bacnet-ip> provides the name of the running container, <config_directory> provides the location of the config folder, and [time_in_seconds] can optionally define the time for which XRT is to run in seconds:

docker run --rm --name <xrt-bacnet-ip> \
  -v <config_directory>/config:/opt/iotech/xrt/config \
  --network host -it iotechsys/xrt:1.1.49 [time_in_seconds]

Run on Docker Bridge Network

To run on a docker bridge network, you must setup a macvlan network after you have setup your docker bridge network. To setup a macvlan network, complete the following steps:

  1. Get the name and subnet information for your host's physical network interface, as follows:

       ifconfig
       eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 \
           inet 192.168.1.91 netmask 255.255.255.0 broadcast 192.168.1.255
    
  2. Create the macvlan network as shown in the following example where we create a macvlan network called xrt_macvlan:

       docker network create - d macvlan \
         --subnet=192.168.1.0/24 \
         -o parent=eno1 xrt_macvlan
    
  3. In the container, interface names are set to ethx, where x is a number that is assigned based on the alphabetical order of the network names. In this example this means that xrt_bridge is set to eth0 and xrt_macvlan is set to eth1.

    As we want the Device Service to communicate with BACnet devices using macvlan, we use the NetworkInterface driver and set it to eth1, as shown in the following extract from the bacnet_ip_device.json file:

    ...
    "Bus": "bus",
    "Driver": {
    "NetworkInterface": "eth1"
    }
    
  4. Create the docker container and connect to the bridge network, using the following command where <xrt-bacnet-ip> is the name of the container, <config_directory> provides the location of the config folder and [timeout in secs] can optionally define the timeout in seconds:

       docker create --rm --name <xrt-bacnet-ip> 
         -v <config_directory>/config:/opt/iotech/xrt/config  \
         --network xrt_bridge -it iotechsys/xrt:1.1.49 [timeout in secs]
    
  5. Connect the container to the macvlan network, as follows where <xrt-bacnet-ip> is the name of the container:

    docker network connect xrt_macvlan <xrt-bacnet-ip>
    
  6. Run XRT using the following command, where <xrt-bacnet-ip> is the name of the container:

    docker start <xrt-bacnet-ip>
    

BACnet Simulator

The BACnet Simulator simulates a BACnet device, which is controlled by a Lua script. The Lua script used in this example is located in the examples/device-bacnet-c/bacnet-simulator directory. XRT connects to the BACnet Simulator and reads events from the simulated device.

To start the BACnet Simulator, using the example Lua script with the configuration located in the examples/device-bacnet-c/configdirectory, to communicate with the XRT Docker container, complete the following steps:

  1. create a Docker network, called bacnet to allow the XRT Docker container and BACnet Docker container to communicate on the same Docker network, using the following command:

    docker network create bacnet
    
  2. Start the BACnet Simulator with the example Lua script using the following command:

    docker run -it --rm --name=bacnet-server -e RUN_MODE=IP \
      --network bacnet \
      -v /opt/iotech/xrt/examples/device-bacnet-c/bacnet-simulator/:/docker-lua-script/ \
      iotechsys/bacnet-server:1.8.3 --script /docker-lua-script/example.lua --instance 1234
    
  3. Start XRT as a Docker container with the example BACnet configuration using the following command:

    docker run -it -v /opt/iotech/xrt/examples/device-bacnet-c/config/:/opt/iotech/xrt/config/ \
      --network bacnet iotechsys/xrt-server:1.2.0 5
    

    XRT connects to the BACnet Simulator over the docker network and reads events from the simulated BACnet device.

Back to top