Skip to content

BACnet/IP Docker

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

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

You can run on either of the following networks when running the Edge 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 Edge Xrt is to run in seconds:

docker run --rm --name xrt-bacnet-ip \
  -v <deployment_directory>/deployment:/opt/iotech/xrt/2.1/deployment \
  --network host iotechsys/xrt:2.1 [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 called xrt_macvlan as shown in the following example:

    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 <deployment_directory>/deployment:/opt/iotech/xrt/2.1/deployment \
      --network xrt_bridge -it iotechsys/xrt:2.1 [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 Edge 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. Edge 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-sim:2.0 --script /docker-lua-script/example.lua --instance 1234
    
  3. Start Edge Xrt as a Docker container with the example BACnet configuration using the following command:

    docker run -it -v <deployment_directory>/deployment:/opt/iotech/xrt/2.1/deployment \
      --network bacnet iotechsys/xrt:2.1 5
    

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