OpenHAB on a Single Board Computer (SBC)

For this I’m going to use an Asus Tinkerboard – but should be similar for any SBC.

Start by downloading the operating system image.  My preferred is Armbian. and using the mainline Debian distribution (command line – not desktop).

The image will download in a .7z compression so you will need 7-Zip to extract the image.

Next, copy the image to a Micro SD card.  There are many tools to do this and my preferred is Win32 Disk Imager.

First boot will take a while but will show up on your router as “tinkerboard”.  Two tools your are going to need are WinSCP (sftp, scp and ftp client) and Putty (ssh client).

Start putty and log into the IP of the Tinkerboard.  The first time you log in use ‘root’ with the default password ‘1234’ – you will be prompted to change the password and create a new user.  The SBC is now all set to proceed – at this point I like to reboot (enter reboot at the command prompt).

Log into the device again with Putty as ‘root’.  The first thing I like to do is disable logging (many will say this is a bad idea but my belief is that if you don’t the SD card will fill up and your system will stop working).  To do this execute the following two comands:

[sourcecode language=”text”]service rsyslog stop
systemctl disable rsyslog[/sourcecode]

(This can be re-enabled using ‘systemctl enable rsyslog’)

Next update the system using the following two commands (this will take a while):

[sourcecode language=”text”]apt-get update
apt-get upgrade[/sourcecode]

After it finishes reboot and login again with ‘root’.

Next is to set the timezone and hostname (I’m going to use ‘TinkerHAB’).  To do this use ‘armbian-config’ at the command line.  (If it’s not found try running ‘apt-get install armbian-config’ and try again).  When done log out and back in.

Next install Zulu (java engine) using the following commands:  (instructions based on here)

[sourcecode language=”text”]apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv-keys 0x219BD9C9
echo ‘deb http://repos.azulsystems.com/debian stable main’ > /etc/apt/sources.list.d/zulu.list
apt-get update -qq
apt-get install zulu-embedded-8[/sourcecode]

When done confirm it has been installed by entering ‘java -version’.

Next install OpenHAB using the following commands: (instructions based on here)

[sourcecode language=”text”]wget -qO – ‘https://bintray.com/user/downloadSubjectPublicKey?username=openhab’ | sudo apt-key add –
apt-get install apt-transport-https
echo ‘deb https://dl.bintray.com/openhab/apt-repo2 stable main’ | sudo tee /etc/apt/sources.list.d/openhab2.list
apt-get update
apt-get install openhab2
apt-get install openhab2-addons
systemctl daemon-reload
systemctl enable openhab2.service
systemctl start openhab2.service[/sourcecode]

If all worked you should be able to log in to OpenHAB in your browser:

  • http://192.168.x.x:8080

Congrats!

Here is a good time to shut down and make a backup of the SD Card with Win32DiskImager.

Now on to MQTT (Mosquitto).  Enter the following command: (instructions based on here)

[sourcecode language=”text”]wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
apt-key add mosquitto-repo.gpg.key
echo ‘deb http://repo.mosquitto.org/debian stretch main’ > /etc/apt/sources.list.d/mosquitto.list
apt-get update
apt-get install mosquitto mosquitto-clients[/sourcecode]

Next we will add a username and password to Mosquitto. (instructions based on here)

Log in again and change to your home folder:

[sourcecode language=”text”]cd ~[/sourcecode]

Create a text file with a login name and password:

[sourcecode language=”text”]echo ‘username:password’ > passwd[/sourcecode]

Encrypt the file:

[sourcecode language=”text”]mosquitto_passwd -U passwd[/sourcecode]

Move the file to the mosquitto folder:

[sourcecode language=”text”]mv passwd /etc/mosquitto/[/sourcecode]

Using nano (or whatever editor you like) edit ‘mosquitto.conf’ file in ‘/etc/mosquitto’

[sourcecode language=”text”]nano /etc/mosquitto.conf[/sourcecode]

Add the following text just after the comments:

[sourcecode language=”text”]password_file /etc/mosquitto/passwd
allow_anonymous false[/sourcecode]

That’s pretty much it for the setup – anything more will be configuration.  This would be another good point to shutdown and backup the SD Card.

 

Leave a Reply

Your email address will not be published. Required fields are marked *