michelmu/knxd-docker

By michelmu

Updated 5 months ago

KNXD docker container

Image
Networking
Internet of things
1

5.3K

michelmu/knxd-docker repository overview

knxd-docker

This repo is to build the KNX daemon. The container is used to have an IP tunnel using the busware USB device.

KNXD requires a knxd.ini file to define the communication. This docker uses for most of the parameters in the knxd.ini file environment variables. Therefore it's important to start the container with all the needed environment variables.

The basic configuration file is knxd-template.ini. Please check this file for reference of all environment variables.

Environment Variables

The following environment variables can be set to configure the container. All variables are used to populate the knxd.ini configuration file from the template.

Core Configuration Variables
VariableDescriptionRequiredDefaultExampleNotes
ADDRESSKNX physical address of the daemonYes-1.5.1Format: area.line.device (1-15.1-15.1-255)
CLIENT_ADDRESSKNX client address rangeYes-1.5.2:10Format: start_address:count
INTERFACEInterface driver typeYes-tpuart, usb, ipt, ft12Must match one of the supported drivers
DEBUG_ERROR_LEVELLogging levelNoerrorerror, warning, info, debugControls verbosity of log output
Interface-Specific Variables
TPUART Interface (Serial/USB)
VariableDescriptionRequiredDefaultExampleNotes
DEVICEDevice path for TPUART interfaceYes*-/dev/knx, /dev/ttyUSB0*Required for TPUART interface
FILTERSPacket filtering modeNosinglesingle, noneControls packet filtering
TPUART-IP Interface (Network-based TPUART)
VariableDescriptionRequiredDefaultExampleNotes
IP_ADDRESSIP address of TPUART deviceYes*-192.168.1.100*Required for TPUART-IP interface
DEST_PORTDestination portYes*-3671*Required for TPUART-IP interface
FILTERSPacket filtering modeNosinglesingle, noneControls packet filtering
USB Interface
VariableDescriptionRequiredDefaultExampleNotes
USB_DEVICEUSB device identifierNo-/dev/bus/usb/001/002Alternative to USB_BUS
USB_BUSUSB bus identifierNo-001:002Alternative to USB_DEVICE
FILTERSPacket filtering modeNosinglesingle, noneControls packet filtering
IP Tunneling Interface
VariableDescriptionRequiredDefaultExampleNotes
IP_ADDRESSKNX/IP gateway IP addressYes*-192.168.1.50*Required for IPT interface
DEST_PORTKNX/IP gateway portNo36713671Standard KNX/IP port
NATEnable NAT mode for tunnelingNofalsetrue, falseUse when behind NAT
FT12/FT12CEMI Interface (Serial)
VariableDescriptionRequiredDefaultExampleNotes
DEVICESerial device pathYes*-/dev/ttyS0, /dev/ttyUSB0*Required for FT12 interfaces
FILTERSPacket filtering modeNosinglesingle, noneControls packet filtering
NCN5120 Interface
VariableDescriptionRequiredDefaultExampleNotes
DEVICEDevice path for NCN5120Yes*-/dev/ttyUSB0*Required for NCN5120 interface
FILTERSPacket filtering modeNosinglesingle, noneControls packet filtering
NCN5120-IP Interface
VariableDescriptionRequiredDefaultExampleNotes
IP_ADDRESSIP address of NCN5120 deviceYes*-192.168.1.100*Required for NCN5120-IP interface
DEST_PORTDestination portYes*-3671*Required for NCN5120-IP interface
FILTERSPacket filtering modeNosinglesingle, noneControls packet filtering
Server Configuration Variables
VariableDescriptionRequiredDefaultExampleNotes
SERVER_INTERFACENetwork interface for multicastNo(default)eth0, eth1Useful for macvlan/bridge networks
Configuration Examples by Interface Type
TPUART (USB Serial Adapter)
ADDRESS=1.5.1
CLIENT_ADDRESS=1.5.2:10
INTERFACE=tpuart
DEVICE=/dev/knx
DEBUG_ERROR_LEVEL=error
FILTERS=single
USB Interface
ADDRESS=1.5.1
CLIENT_ADDRESS=1.5.2:10
INTERFACE=usb
USB_DEVICE=/dev/bus/usb/001/002
DEBUG_ERROR_LEVEL=error
FILTERS=single
IP Tunneling
ADDRESS=1.5.1
CLIENT_ADDRESS=1.5.2:10
INTERFACE=ipt
IP_ADDRESS=192.168.1.50
DEST_PORT=3671
NAT=false
DEBUG_ERROR_LEVEL=error
FT12 Serial
ADDRESS=1.5.1
CLIENT_ADDRESS=1.5.2:10
INTERFACE=ft12
DEVICE=/dev/ttyS0
DEBUG_ERROR_LEVEL=error
FILTERS=single

Note: Variables marked with * are required only when using the corresponding interface type.

run the container

To start the container using docker with the busware usb stick, it would look like this:

docker run \
--name=knxd \
-p 6720:6720/tcp \
-p 3671:3671/udp \
--device=/dev/bus/usb:/dev/bus/usb:rwm \
--device=/dev/mem:/dev/mem:rw \
--device=/dev/serial/by-id/usb-busware.de_TPUART_transparent_95738343235351D032C0-if00:/dev/knx \
--cap-add=SYS_MODULE \
--cap-add=SYS_RAWIO \
-e ADDRESS="1.5.1" \
-e CLIENT_ADDRESS="1.5.2:10" \
-e INTERFACE=tpuart \
-e DEVICE="/dev/knx" \
-e DEBUG_ERROR_LEVEL="error" \
-e FILTERS="single" \
--restart unless-stopped michelmu/knxd-docker:latest

If you want to use docker-compose the following yaml file would look like this:

services:
  knxd:
    image: michelmu/knxd-docker:latest
    container_name: knxd
    ports:
      - "6720:6720/tcp"
      - "3671:3671/udp"
    devices:
      - "/dev/bus/usb:/dev/bus/usb:rwm"
      - "/dev/mem:/dev/mem:rw"
      - "/dev/serial/by-id/usb-busware.de_TPUART_transparent_95738343235351D032C0-if00:/dev/knx"
    cap_add:
      - SYS_MODULE
      - SYS_RAWIO
    environment:
      - ADDRESS=1.5.1
      - CLIENT_ADDRESS=1.5.2:10
      - INTERFACE=tpuart
      - DEVICE=/dev/knx
      - DEBUG_ERROR_LEVEL=error
      - FILTERS=single
    restart: unless-stopped

Health Checks and Verification

Container Status Check

First, verify that the container is running and healthy:

# Check if container is running
docker ps | grep knxd

# Check container logs for startup messages
docker logs knxd

# Check container resource usage
docker stats knxd --no-stream
Service Connectivity Tests
1. Check KNX Daemon Process
# Verify knxd process is running inside container
docker exec knxd ps aux | grep knxd

# Check if knxd is listening on expected ports
docker exec knxd netstat -ln | grep -E '(6720|3671)'
2. Network Port Verification
# Test TCP port 6720 (KNX daemon)
telnet localhost 6720

# Test UDP port 3671 (KNXnet/IP) - requires netcat
nc -u localhost 3671
3. KNX Bus Communication Test
# Access container shell
docker exec -it knxd bash

# Test basic KNX communication with knxtool
knxtool on ip:127.0.0.1 0/1/50    # Turn on device at group address 0/1/50
knxtool off ip:127.0.0.1 0/1/50   # Turn off device at group address 0/1/50

# Read group address value
knxtool read ip:127.0.0.1 0/1/50

# Monitor KNX bus traffic
knxtool groupsocketlisten ip:127.0.0.1
Docker Health Check Configuration

Add a health check to your docker-compose.yaml:

services:
  knxd:
    image: michelmu/knxd-docker:latest
    container_name: knxd
    ports:
      - "6720:6720/tcp"
      - "3671:3671/udp"
    devices:
      - "/dev/bus/usb:/dev/bus/usb:rwm"
      - "/dev/mem:/dev/mem:rw"
      - "/dev/serial/by-id/usb-busware.de_TPUART_transparent_95738343235351D032C0-if00:/dev/knx"
    cap_add:
      - SYS_MODULE
      - SYS_RAWIO
    environment:
      - ADDRESS=1.5.1
      - CLIENT_ADDRESS=1.5.2:10
      - INTERFACE=tpuart
      - DEVICE=/dev/knx
      - DEBUG_ERROR_LEVEL=error
      - FILTERS=single
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "sh", "-c", "ps aux | grep -v grep | grep knxd && netstat -ln | grep 6720"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

Or for docker run command:

docker run \
--name=knxd \
-p 6720:6720/tcp \
-p 3671:3671/udp \
--device=/dev/bus/usb:/dev/bus/usb:rwm \
--device=/dev/mem:/dev/mem:rw \
--device=/dev/serial/by-id/usb-busware.de_TPUART_transparent_95738343235351D032C0-if00:/dev/knx \
--cap-add=SYS_MODULE \
--cap-add=SYS_RAWIO \
--health-cmd="sh -c 'ps aux | grep -v grep | grep knxd && netstat -ln | grep 6720'" \
--health-interval=30s \
--health-timeout=10s \
--health-retries=3 \
--health-start-period=40s \
-e ADDRESS="1.5.1" \
-e CLIENT_ADDRESS="1.5.2:10" \
-e INTERFACE=tpuart \
-e DEVICE="/dev/knx" \
-e DEBUG_ERROR_LEVEL="error" \
-e FILTERS="single" \
--restart unless-stopped michelmu/knxd-docker:latest
Troubleshooting Common Issues
Container Won't Start
# Check detailed logs
docker logs knxd --details

# Check if configuration file was generated correctly
docker exec knxd cat /etc/knxd.ini

# Verify environment variables
docker exec knxd env | grep -E "(ADDRESS|INTERFACE|DEVICE)"
Device Permission Issues
# Check device permissions on host
ls -la /dev/serial/by-id/
ls -la /dev/ttyUSB*

# Check if devices are accessible inside container
docker exec knxd ls -la /dev/knx
docker exec knxd ls -la /dev/bus/usb/
Network Connectivity Issues
# Test from host system
telnet localhost 6720
nc -u localhost 3671

# Check firewall rules
sudo iptables -L | grep -E "(6720|3671)"

# Test KNX/IP gateway connectivity (for IP tunneling)
ping 192.168.1.50  # Replace with your gateway IP
telnet 192.168.1.50 3671
KNX Bus Communication Problems
# Enable debug logging
docker run ... -e DEBUG_ERROR_LEVEL="debug" ...

# Monitor all KNX traffic
docker exec -it knxd knxtool groupsocketlisten ip:127.0.0.1

# Test with different group addresses
docker exec knxd knxtool read ip:127.0.0.1 0/0/1  # Test with a known device
Monitoring and Logging
Log Analysis
# Follow logs in real-time
docker logs -f knxd

# Search for specific errors
docker logs knxd 2>&1 | grep -i error

# Check startup sequence
docker logs knxd | head -20
Performance Monitoring
# Monitor resource usage
docker stats knxd

# Check container health status
docker inspect knxd | grep -A 10 '"Health"'
Integration Testing
Home Assistant Integration Test
# Test KNX integration from Home Assistant
# Add to configuration.yaml:
# knx:
#   host: <docker_host_ip>
#   port: 3671

# Verify connection in Home Assistant logs
ETS Integration Test
# Configure ETS to connect to:
# IP: <docker_host_ip>
# Port: 3671
# Connection type: Tunneling

Tag summary

Content type

Image

Digest

sha256:5af7ff957

Size

9.7 MB

Last updated

5 months ago

docker pull michelmu/knxd-docker