Raspberry PI: EIB/KNX IP Gateway and Router

Hi,

this Post is a tutorial to build an IP EIB/KNX Gateway based on a Raspberry Pi completely from the scratch. The core components are the eib daemon from the bcusdk in conjunction with the TPUART EIB Bustranceiver module.

The Hardware

3 components are needed:

  • A Raspberry PI
  • A EIB Buscoupling Unit
  • Adapter Board to connecting both

You can use A or the B Model of Raspberry Pi. The eibd daemon has minimal hardware requirements.

There are two possibilities for connecting a computer to the EIB/KNX Bus over a RS232 serial interface. Both are supported by eibd.

  • Buscoupler 2 with FT12 protocol
  • TPUART module


I use the second one. It has the best price and is stablest solution.  You can buy the TPUART modul decretely for about 40€ or you order a Siemens Bustranceiver Module BTM UP117 5WG1117-2AB11 where a TPUART module is inside and which is available for about 25€ :-).

Siemens Bus Tranceiver Module BTM BU117
Siemens Bus Tranceiver Module BTM BU117

For connecting the TPUART module to the fruit I developed a adapter board which also provides galvanic isolation between EIB bus and Ethernet Network.
The galvanic isolation is done by a ADUM1201 Analog devices dual-channel digital isolator.
The board has a 10 Pin header which is pin compatible with the Raspberry and another 10 pin header to plug-on the TPUART.

Raspberry Pi KNX Board Top

The Schematic and PCB are available in Eagle format and can be downloaded above.

Raspberry Pi KNX Board Schematic
Raspberry Pi KNX Board Layout

The part list of the board is very short 🙂 The screwed connection on the board an be used to suppling the Raspberry Pi with 5V.

Part Device Type Costs
IC1 Integrated Circuit ADUM1201 2,50€
C2 Capacitor 1µF 10Cent
C3 Capacitor 10µF 10Cent
J1,J2 Header 10pin header 50Cent

Connect the Raspberry pi KNX Board

Raspberry KNX IP Gateway/Router

The Software part

Update: eibd is no longer under development please install knxd.
Install Raspbian as operating system for Rasperry Pi. All developing tools to compile the eibd daemon are already included. For the current version you need a SD card with at least 4GB. The installation of rapbian is described here in detail. Its simple:-)

When your operating system is up, login as user pi and set a static IP Address to ensure the gateway is always reachable at the same IP Address.

For Debian 7 Wheezy edit the following files with your favorite editor. For me its vi :-). For Debian 8 and systemd based network configuration scroll down.

pi@raspberry~: $ sudo vi /etc/network/interfaces

comment the following line

# iface eth0 inet dhcp

insert your static TCP/IP parameter.

allow-hotplug eth0
iface eth0 inet static
address 192.168.2.150
netmask 255.255.255.0
gateway 192.168.2.1

On Debian 8 Jessie also add the route to the eibnet mulicast address (in debian wheezy this is set by the init script) and set the interface eth0 from “allow-hotplug” to “auto” so it will not be handled by systemd, to activate the old style debian network config.

auto eth0
iface eth0 inet static
address 192.168.2.150
netmask 255.255.255.0
gateway 192.168.2.1
post-up route add -net 224.0.23.12 netmask 255.255.255.255 eth0
pre-down route del -net 224.0.23.12 netmask 255.255.255.255 eth0

adjust address, subnetmask and gateway. Open /etc/resolv.conf to set a DNS Server. In home environments this is usually the DSL Router.

pi@raspberry~: $ sudo vi /etc/resolv.conf


nameserver 192.168.2.1

Reboot your device and login again. I preferred a remote login over ssh from my workstation.
I wrote a script install_eibd.sh which compiles and installs the eibd daemon. You can download it below. The script needs an active internet connection. Check the connection

Network configuration for Debian 8 Jessie
pi@raspberry~: $ sudo su -
root@raspberry:~#

Create new file /etc/systemd/network/eth0.network. Name is not importend, just the prefix network.

[Match]
# You can also use wildcards. Maybe you want enable dhcp
# an all eth* NICs
Name=eth0
[Network]
#DHCP=v4
# static IP
# 192.168.100.2 netmask 255.255.255.0
Address=192.168.100.2/24
Gateway=192.168.100.1
DNS=192.168.100.1
# Route for Multicast Address EIB/KNX
[Route]
Destination=224.0.23.12/32

Disable the old way to configure the network, enable systemd based network configuration, enable systemd generated resolve.conf (DNS resolution) and disable dhcpcd.

root@raspberry:~# mv /etc/network/interfaces /etc/network/interfaces.save
root@raspberry:~# systemctl enable systemd-networkd.service
root@raspberry:~# systemctl enable systemd-resolved.service
root@raspberry:~# systemctl disable dhcpcd.service

Set an link from the system wide resolve.conf to systemd

root@raspberry:~# mv /etc/resolv.conf /etc/resolv.conf.save
root@raspberry:~# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

Reboot to get the config active

root@raspberry:~# reboot
Check the connection.
pi@raspberry~: $  ping -c 2 www.heise.de
PING www.heise.de (193.99.144.85) 56(84) bytes of data
64 bytes from 193.99.144.85: icmp_req=1 ttl=128 time=8.551 ms
64 bytes from 193.99.144.85: icmp_req=2 ttl=128 time=9.680 ms

--- 193.99.144.85 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.551/0.615/0.680/0.069 ms

Note: Some rasbian version has a bug that the permissions for /bin/ping were not set correctly. The following error occurs: “ping: icmp open socket: Operation not permitted”. The setuid on /bin/ping is missing, because only root can open sockets.

pi@raspberry~: $ sudo chmod u+s /bin/ping

Installing eibd
The script must be run as root because some files are copied and modified in locations where only root have the appropriate permissions.

What the script does:

  • Check for root permissions
  • Download and compile pthsem
  • Download bcusdk, but compile eibd only
  • installing eibd binaries to /usr/local/bin
  • create a init script /etc/init.d/eibd
  • Add a user eibd with group membership dialout (to access serial device /dev/ttyAMA0)
  • Disable bootmessages on serial interface /dev/ttyAMA0
  • Disable console on serial interface /dev/ttyAMA0
  • Disable console on serial interface /dev/ttyAMA0
  • On Raspberry Pi 3 it disable the bluetooth module because its uses ttyAMA0 by default

On a Raspberry Pi 3 it is strongly recommended to update to the latest Kernel to addressing some issues with the serial device ttyAMA0

pi@raspberry~: $ sudo su
root@raspberry~: # rpi-update
root@raspberry~: # reboot

Start a root shell, get the script.

pi@raspberry~: $ sudo su
root@raspberry~: #
root@raspberry~: # wget http://michlstechblog.info/blog/download/shell_scripts/install_eibd.sh

The highlighted eibd features are enabled. Alter the script if you need additional features.
–enable-ft12         enable FT1.2 backend
–enable-pei16        enable BCU1 kernel driver backend
–enable-tpuart       enable TPUART kernel driver backend (deprecated)
–enable-pei16s       enable BCU1 user driver backend (very experimental)
–enable-tpuarts      enable TPUART user driver backend
–enable-eibnetip     enable EIBnet/IP routing backend
–enable-eibnetiptunnel       enable EIBnet/IP tunneling backend
–enable-usb                  enable USB backend
–enable-eibnetipserver       enable EIBnet/IP server frontend
–enable-groupcache           enable Group Cache (default: yes)
–enable-java         build java client library

Start the script. This should be run about 20 minutes. Do not execute update-rc.d on debian jessie.

root@raspberry~: # chmod +x ./install_eibd.sh
root@raspberry~: # ./install_eibd.sh && update-rc.d eibd defaults

After the script has finished. eibd, vbusmonitor2, groupwrite and some other stuff should be installed at /usr/local/bin, the init script eibd in /etc/init.d and the startup links in /etc/rc3.d must exists. At the end of the script a warning message “insserv: warning: script ‘mathkernel’ missing LSB tags and overrides” is shown. This can be ignored.

root@raspberry~: # ls -l /usr/local/bin
.....
-rwxr-xr-x 1 root staff 471140 Feb 18 22:14 eibd
-rwxr-xr-x 1 root staff  10788 Feb 18 22:14 vbusmonitor2
.....
root@raspberry~: # ls -l /etc/init.d/eibd
-rwxr--r-- 1 root root 2142 Feb Feb 18 22:14 /etc/init.d/eibd

root@raspberry~: # ls -l /etc/rc3.d/*eibd
lrwxrwxrwx 1 root root 14 Feb 18 22:14 /etc/rc3.d/S18eibd -> ../init.d/eibd

Reboot your device

root@raspberry~: # reboot

The eibd options and features are defined at variable EIBD_OPTIONS in file /etc/init.d/eibd. Currently are defined:

  • EIB Busaddress of the daemon 1.1.128
  • EIBnet/IP server
  • EIBnet/IP Routing
  • EIBnet/IP Tunneling
  • Answer discovery and description requests
  • Listen on UNIX domain socket /tmp/eib
  • Listen on TCP port, default 6720

This gets a detail list of command line parameter

root@raspberry~: # eibd -?

After the reboot and if your Raspberry KNX Board is connected the eibd should running

root@raspberry~: # ps ax|grep eibd
2996 ?        Ss     0:00 /usr/local/bin/eibd -d -D -T -R -S -i -u --eibaddr=1.1.128 tpuarts:/dev/ttyAMA0

If the process is running. Check if you see EIB packets on wire.

pi@raspberry~: # vbusmonitor1 ip:localhost
LPDU: BC 11 17 00 03 C1 00 81 06 :L_Data low from 1.1.23 to 0/0/3 hops: 04 T_DATA_XXX_REQ A_GroupValue_Write (small) 01 LPDU: CC :ACK
LPDU: BC 11 17 00 03 81 00 81 46 :L_Data low from 1.1.23 to 0/0/3 hops: 00 T_DATA_XXX_REQ A_GroupValue_Write (small) 01 LPDU: CC :ACK

Thats it. Comments are welcome!

I’ve writted another post if you want to use Raspberry Pi and eibd with a KNX USB Interface.

Update 09.06.2016: I’ve added the first release of a script to compile and install knxd. knxd is a fork of eibd. Any comments are welcome. Configfile is /etc/default/knxd, Socket /tmp/knx. See this EIB/KNX Router with knxd

Enjoy

Michael

Raspberry Pi KNX Board Schematic and PCB
Raspberry-eibd.zip
Version: 1.0

This the Raspberry Pi KNX Board Schematic and PCB for the Eagle PCB Software

Author:Michael Albert
Category:Electronic
Date:February 21, 2014
51.4 KiB
2119 Downloads
Details...
Script to compile and install eibd on debian jessie
install_eibd_systemd.sh
Version: 1.2.0

This scripts gets all sources, compiles and installs the eibd daemon.

Author:Michael
Category:Electronic
License:GNU General Public License
Date:October 22, 2015
7.7 KiB
2631 Downloads
Details...

This scripts gets all sources, compiles and installs the eibd daemon.

Author:Michael
Category:Shell scripts
Date:February 16, 2015
6.2 KiB
5373 Downloads
Details...