Dienstag, 19. November 2013

Installing OpenHAB on a Beaglebone Black

Just a few notes on how i installed the OpenHAB home automation software onto the beaglebone black single board computer.

For beaglebone black development, i found the homepage of Derek Molloy (http://derekmolloy.ie/) to be extremely helpful, most of the below setup-steps are found there. 

1. Installing the Java JRE

The Oracle JRE is reported to perform much better then the OpenJVM implementation,
so i chose to use that as java runtime. It can be downloaded here:


As i am using the original Ångström distribution, i took ejre-7u45-fcs-b15-linux-arm-vfp-sflt-client_headless-26_sep_2013.tgz

I copied this to /usr/java and extracted the file:
# mkdir /usr/java
# cd /usr/java
# tar xfvz ejre-7u45-fcs-b15-linux-arm-vfp-sflt-client_headless-26_sep_2013.tgz

The bin-folder can be added to the search-path by adding it to the PATH environment variable and i also exported the JAVA_PATH variable:
# export PATH=$PATH:/usr/java/jdk1.7.0_45/bin/
# export JAVA_HOME=/usr/java/jdk1.7.0_45/
These two lines can be added to ~/.profile (the users shell profile file) to have it set automatically upon next login.

2. Installing OpenHAB

The next step was to install OpenHAB. I copied the OpenHAB folder into /home/root/OpenHAB. Currently the OpenHAB process also runs as user root - i will change this in future, but as the system is not exposed to the public internet, it don't think its too critical.

I adapted the OpenHAB start-skript as follows:
# turn off that annoying blue flashing LEDs on the beaglebone black
echo "taking over LEDs"
echo gpio > /sys/class/leds/beaglebone\:green\:usr0/trigger
echo gpio > /sys/class/leds/beaglebone\:green\:usr1/trigger
echo gpio > /sys/class/leds/beaglebone\:green\:usr2/trigger
echo gpio > /sys/class/leds/beaglebone\:green\:usr3/trigger
cd `dirname $0`
# set path to eclipse folder. If local folder, use '.'; otherwise, use /path/to/eclipse/
# set ports for HTTP(S) server
# get path to equinox jar inside $eclipsehome folder
cp=$(find $eclipsehome -name "org.eclipse.equinox.launcher_*.jar" | sort | tail -1);
echo Launching the openHAB runtime...
 /usr/java/jdk1.7.0_45/bin/java -Dosgi.clean=true -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Djetty.port=$HTTP_PORT -Djetty.port.ssl=$HTTPS_PORT -Djetty.home=.
 -Dlogback.configurationFile=configurations/logback.xml -Dfelix.fileinstall.dir=addons -Djava.library.path=lib -Djava.security.auth.login.config=./etc/login.conf -Do
rg.quartz.properties=./etc/quartz.properties -Dequinox.ds.block_timeout=240000 -Dequinox.scr.waitTimeOnBlock=60000 -Djava.awt.headless=true -jar $cp $* -console 5555
The first 4 echo commands are used for taking over control of the four blue User-LEDs on the beaglebone. By default these LEDs are controlled by the kernel and signal current CPU utilization and some other info. The flashing LEDs started to annoy me, so i turned them off.

OpenHAB will now run (when configured properly) when the start.sh skript is called. As i wanted the system to start automatically in a proper way after a reboot, some additional work had to be done:

3. NTP Support

Next thing was installing the NTP support for the beaglebone. As the systems RTC is not battery buffered,  the date and time information will be lost upon each power cycle. I worked around this by syncing the time via NTP upon each startup:

First i installed the NTP package:
# opkg update
# opkg install ntp
Then i edited the ntp config file, basically to use the local (germany based) NTP servers from the ntp.org timeserver pool. I also added a security rule that limits access to my local network.

# This is the most basic ntp configuration file
# The driftfile must remain in a place specific to this
# machine - it records the machine specific clock error
driftfile /etc/ntp.drift

server 0.de.pool.ntp.org
server 1.de.pool.ntp.org
server 2.de.pool.ntp.org
server 3.de.pool.ntp.org

# Defining a default security setting
restrict mask nomodify notrap
After that, the local timezone needed to be adapted by letting the symlink /etc/localtime point to the right zone-file:
# rm /etc/localtime
# ln -s /usr/share/zoneinfo/Europe/Paris /etc/localtime
After this, it is necessary to change the config file of the ntpdate service as follows:

Description=Network Time Service (one-shot ntpdate mode)
ExecStart=/usr/bin/ntpd -q -g -x
ExecStart=/sbin/hwclock --systohc
The setting ExecStart needs to be changed as shown above. The first ExecStart line is changed, the second is newly added. The second one syncs the hardware clock to the system time after the NTP sync was performed.

Next is to enable the NTP daemon, so that it is run upon system start:
# systemctl enable ntpdate.service 
# systemctl enable ntpd.service
Upon next reboot, the date and time should be correct.

4. Autostart OpenHAB

Next thing i installed was a configuration file for the systemctl service, so that OpenHAB gets started upon every reboot.



Then this service is activated by
# systemctl enable openhab.service
and started by
# systemctl start openhab.service
The current state can be queried this way:
# systemctl status openhab.service
That should give an output like:
openhab.service - OpenHAB
  Loaded: loaded (/lib/systemd/system/openhab.service; enabled)
  Active: active (running) since Sat 2000-01-01 01:00:02 CET; 13 years 10 months ago
Main PID: 127 (start.sh)
  CGroup: name=systemd:/system/openhab.service
  |-127 /bin/sh /home/root/OpenHAB/start.sh
  `-247 /usr/java/jdk1.7.0_45/bin/java -Dosgi.clean=true -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Djetty.port=8080 -Djetty.port.ssl=8443 -...
5. Setting up a Samba share for easy configuration

Install the SMB server via opkg:

         # opkg install samba
         # smbpasswd

Edit the Samba config file:

        # vi /etc/samba/smb.conf

I stepped through the config and configured samba to the local needs, most defaults already fitted. I installed a new share:

   comment = OpenHAB
   path = /home/root/OpenHAB
   public = yes
   writable = yes
   printable = no

   write list = root

Samba can be started using systemctl:

    # systemctl restart openhab.service

6. Setting up a static (non DHCP) IP configuration

I prefer to have static IPs for servers in my network. Here i found a description on how to set up a static config:



  1. I found on my installation I had to 'chmod +x' the start.sh file to get the service to start it correctly.

  2. Hallo Rainer,
    thank you for the installation details. Now there is this version of Java the newest one:

    Have you made any experiences using the IO-Pins of the BBB over OpenHab?

  3. Hey, thanks for pointing to the java update.

    I have not yet tried controlling the GPIOs via OpenHAB, but it should be possible by using the exec binding (and then just echo to the device files) or the GPIO binding. For some IOs, it is necessary to build and load a device tree overlay for proper IO multiplex register configuration.

  4. Have you found OpenHAB runs well on the BBB? I'm thinking of using BBB to control about 40 devices in my house - does it have enough CPU and memory? Any issues with Angstrom?

    Also, It would be great if you could add the above info to https://github.com/openhab/openhab/wiki/Hardware-FAQ.

  5. Hi, it runs okay. Startup takes pretty long (several minutes) but once it is running, rule execution is fast enough for me. I reduces logging to errors only.

    Only thing that is really slow is loading history plots from the RRD archive.