Installing OpenHAB on a Beaglebone Black
This post is about installing the OpenHAB home automation software onto the BeagleBone Black. The idea is to collect data from the AirVantage cloud and make automation decisions based on that data
For BeagleBone Black development, i found the homepage of Derek Molloy (http://derekmolloy.ie/) to be extremely helpful, most of the below setup-steps can be found there. However, that page refers to Angstrom distribution, whereas I installed Debian (see @fvan post in this challenge for more info about installation). So this post details the procedure for installing OpenHAB on Debian
1. Installing the Java JRE
Since the Oracle JRE is reported to perform much better than the OpenJVM implementation, I decided to use the first option. JRE can be downloaded here:
http://download.oracle.com/otn/java/ejdk/8-b132/ejdk-8-fcs-b132-linux-arm-sflt-03_mar_2014.tar.gz
I copied this to /home/debian and extracted the file:
# mkdir /usr/java
# cd /usr/java
# tar xfvz /home/debian/ ejdk-8-fcs-b132-linux-arm-sflt-03_mar_2014.tar.gz
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/ejdk1.8.0/linux_arm_sflt/jre/bin
# export JAVA_HOME=/usr/java/ejdk1.8.0/linux_arm_sflt/jre
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. Just copy the OpenHAB folder into /home/debian/openhab.
I made some changes to start.sh, in particular I created an environment variable
JAVA=/usr/java/ejdk1.8.0/linux_arm_sflt/jre/bin/java
and replaced "java" with this variable in the invocation of the runtime
$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 -Dorg.quartz.properties=./etc/quartz.properties -Dequinox.ds.block_timeout=240000 -Dequinox.scr.waitTimeOnBlock=60000 -Dfelix.fileinstall.active.level=4 -Djava.awt.headless=true -jar $cp $* -console
OpenHAB will now run (when configured properly) when the start.sh script is invoked. As I want OpenHAB to start automatically after a reboot, some additional work have to be done:
3. NTP Support
Next thing was installing the NTP support for the beaglebone. As the systems RTC is not battery buffered, he date and time information will be lost upon each power cycle. I worked around this by syncing the time via NTP upon each startup
NOTE: I experienced some problems with the led_aging script, so I temporarily removed it
# mv /etc/init.d/led_aging.sh /etc/init.d/_led_aging.sh
First the NTP package has to be installed:
# sudo apt-get update
# sudo apt-get install ntp
Then /etc/ntp config file needs to be changed, basically to use the local NTP servers from the ntp.org timeserver pool.
# 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.it.pool.ntp.org
server 1.it.pool.ntp.org
server 2.it.pool.ntp.org
server 3.it.pool.ntp.org
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/Rome /etc/localtime
Upon next reboot, the date and time should be correct.
4. Autostart OpenHAB
To automatically start OpenHAB when BeagleBone boots, let's create a file openhab in /etc/init.d
#sudo nano /etc/init.d/openhab
Add the following content
#!/bin/sh
### BEGIN INIT INFO
# Provides: openhab
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start OpenHAB at boot time
# Description: Start OpenHAB at boot time
### END INIT INFO
USER=debian
HOME=/home/debian
export USER HOME
case "$1" in
start)
echo "Starting OpenHAB"
$HOME/openhab/start.sh
;;
stop)
echo "Stopping OpenHAB"
killall java
;;
*)
echo "Usage: openhab {start|stop}"
exit 1
;;
esac
exit 0
and save the file.
Now grant execution permissions to the file
# cd /etc/init.d
# chmod 755 openhab
Now let's create a link to the script file in rc5.d (this directory includes all the scripts that are executed when system enters run level 5, which is the default runlevel)
# ln -s /etc/init.d/openhab /etc/init.d/rc5.d/S18openhab
Finally, let's update the service entries
# updaterc.d /etc/init.d/openhab defaults
If you get an error, try
# updaterc.d openhab defaults
5. Setting up a Samba
To make the copy of configuration files easier, Samba can be a valuable approach. Install the SMB server via apt-get:
# sudo apt-get install samba
# smbpasswd
Edit the Samba config file:
# sudo nano /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:
[openhab]
comment = OpenHAB
path = /home/debian/openhab
public = yes
writable = yes
printable = no
write list = root
That's all... I am now ready to get data out from the cloud by means of MQTT
Top Comments