Please see this NEW article for a quicker and better setup! Armbian has been updated hugely and the setup is now much much quicker.
OLD ARTICLE BELOW
Ive recently installed OpenHAB 2.2 on a MeCool M8S Pro W box, with Armbian OS (Ubuntu for ARM processors) and managed to record all my steps so thought Id make it into a Tutorial, from start to finish.
The limitations at this time of running that OS on an MeCool M8S Pro W is that the Sound, Bluetooth and Wireless don’t work. This is because there aren’t driver files currently available for that unit, however, its possible there will be in future (keep an eye on the Armbian forums TV boxes - Armbian Community Forums) or other TV boxes may fully work, so you would need to do your research on that forum (For example, I think the standard M8S Pro does all work with WiFI, Bluetooth etc).
I will be installing an OpenHAB system to control/manage/connect to:
- A Playstation 4.
- A Logitech Harmony Hub.
- Sonoff Devices (with Tasmota Firmware GitHub - arendst/Tasmota: Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at )
- To have a page in the Sitemap for reporting on the performance of the MeCool box.
- To connect to a SMB network share for OpenHAB backups etc.
Hardware you will need:
- MeCool M8S Pro W (or box of your choice…after researching which ones work).
- A Cat 5 LAN cable to plug it into your Router/Switch/Network port.
- A micro SD card (16GB or larger recommended. I bought this one SDSQUAR-032G-GN6MA)
- A way to plug that SD card into your Windows computer to image the Armbian OS onto it.
I chose the MeCool box, because it has an Amlogic ARM processor (which is supported by Armbian). These MeCool boxes WILL boot as standard off a USB memory stick or SD card, without having to change any settings on the box, and it has 4 processor cores and 2GB of RAM, which I figured would be enough grunt for what I wanted to do with OpenHAB (more than a raspberry pi, but about the same cost), but you may want a more powerful box. Mine is using about 6% of processor on average, 5GB of the SD card and about 700MB of the RAM.
In my case I downloaded:
- Armbain from here https://yadi.sk/d/pHxaRAs-tZiei (Armbian_5.37_S9xxx_Ubuntu_xenial_3.14.29_mate_20171226.img.xz)
- Win32DiskImager from here Win32 Disk Imager download | SourceForge.net
Steps to get Armbian Installed (from a Windows PC):
- Download the above files.
- Unzip/Extract with Armbain image file (Use WinRAR or 7Zip).
- Install Win32DiskImager.
- Insert your micro SD card into your PC.
- Run Win32DiskImager as an Administrator.
- In Win32DiskImager, click the folder Icon and point it at your extracted Image file.
- Check the Device field is pointing at your SD card you just inserted and click the Write button.
- Wait about 5 minutes while the SD card is imaged.
- When the SD card is imaged, close Win32DiskImager and go open the SD card partition called BOOT.
- In here you will find a couple of folders, and specifically in the one called dtb, you will find about 20 files. These files are effectively a driver file to load the correct drivers for your TV Box. They are labelled things like gxl_p212_2g.dtb. You need to copy the file that matches your hardware the best to the root of the *BOOT drive on the SD card and rename it to dtb.img. The dtb.img file is the one loaded when booting Armbian to correctly load up the drivers. As my MeCool has 2GB of RAM, I used the 2g file. You may need to try multiple files from the dtb folder to find which works best, or research on the internet or Armbian forums.
- When you have setup your dtb.img file as per step 10, put the SD card into your MeCool box’s SD card slot, plug in a monitor, network cable to your switch/router, keyboard and mouse and then the power.
- Your Armbian box should now boot and will prompt you at a text command prompt to type in the Username and Password. root and 1234. After this is done, it will ask you once again to type in the root password 1234 and create a new user.
- To keep things simple for the OpenHAB setup and to match the standard OpenHAB configuration, create a user called openhab (lower case) with a password of habopen (lowercase). For the “Name” you can call it openhab, ignore the other questions, leaving them blank and when asked if this is correct, say Y and press enter.
- The box will now reboot and you will arrive at a grey login screen, asking you for the password of openhab.
- Before logging in, at the top right of the screen, you will see a page icon with a spanner on it. Click on that and choose the interface of Mate. (I had options of Kodi and Mate). If you DON’T do this, mine didn’t log in to an interface.
- If all has gone correctly, you should now be at a Ubuntu desktop.
From here, I wanted to get my box configured to do a couple of things:
- Have a text editor.
- Connect to SMB shares and have a permanat mapping to the share.
- Install a MQTT broker for OpenHAB.
- Install OpenHAB.
- Setup RDP connections from Windows for remote control.
- Setup other base requirements for OpenHAB to be able to operate on Armbian (it doesn’t install everything a standard Ubuntu seems to)
Here are my steps to get a basic OpenHAB setup working:
- At the top the screen click System > Preferences > Hardware > Keyboards > Layout. Now add the correct keyboard layout for your keyboard and remove the English US (if you aren’t in the USA). Close that window.
- As the box is using DHCP and you will want it on a fixed IP address, the simplest method for this will be to add a static entry in your router to hand out a fixed IP address, so that your devices on your network that use MQTT are always connecting to the same IP. I would suggest doing this now and rebooting your Armbian box. System > Shutdown > Reboot.
- When your system has rebooted, log in again to the desktop.
- At the top of the screen click Applications > System Tools > Mate Terminal which will open a terminal window. In here you can literally copy/paste out the commands on this guide into the Mate Terminal. Some of the commands will need Y pressing to approve the command running (an on screen prompt will appear). Also, the first time you run a sudo command in THIS window, you will be asked for the password of openhab, which, as we set earlier was habopen.
- All the following commands will happen in the Mate Terminal unless specified. Copy/Paste from this guide.
Update the repositories
sudo apt-get update
Install SMB client and Samba for connecting to network shares:
sudo apt-get install smbclient
sudo apt-get install samba samba-common-bin
sudo apt-get install cifs-utils
(OPTIONAL) Remove VNC or any existing setup
sudo apt-get remove xrdp vnc4server tightvncserver
A bit more setting up repositories
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0x219BD9C9
sudo apt-add-repository 'deb http://repos.azulsystems.com/ubuntu stable main'
wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add –
sudo 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
sudo apt-get update
Install Java
sudo apt-get install zulu-embedded-8
(OPTIONAL) Install XRDP and TighVNC for RDP access
sudo apt-get install tightvncserver xrdp
Install Zip capability
sudo apt-get install zip
Install Genie text file editor and also Gedit (for simple text editing)
sudo apt-get install geany
sudo apt install gedit
Check the OpenHAB account has certain permissions (it should already have them)
sudo adduser openhab dialout
sudo adduser openhab tty
sudo adduser openhab audio
Install XFCE Terminal (required for the Armbian config utility)
sudo apt-get install xfce4-terminal
Install mosquito MQTT Broker
sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update
sudo apt-get mosquitto
Install OpenHAB and confirm its set to auto start
sudo apt-get install openhab2
sudo apt-get install openhab2-addons
sudo systemctl start openhab2.service
sudo systemctl status openhab2.service
sudo systemctl daemon-reload
sudo systemctl enable openhab2.service
Ensure that the openhab account is used for accessing network shares and that account has permission to access the network shares we will create on the OpenHAB server for accessing your configuration files.
sudo smbpasswd -a openhab
sudo chown -hR openhab:openhab /etc/openhab2 /var/lib/openhab2
sudo systemctl restart smbd
- At this point we will need to text edit some files. The files will need root (administrator) permission to edit them, so you will need to **sudo geany ** so that it has permission to save the files. You need to close geany after editing the files, to be able to use your Mate terminal window again.
sudo geany
- In Geany File > Open > Select “File System” > /etc/samba/smb.conf. At the bottom of the file you want need to add the following to create network share on your OpenHAB server that you can access across the network:
[openHAB2-userdata]
comment=openHAB2 userdata
path=/var/lib/openhab2
browseable=Yes
writeable=Yes
only guest=no
public=no
create mask=0777
directory mask=0777
[openHAB2-conf]
comment=openHAB2 site configuration
path=/etc/openhab2
browseable=Yes
writeable=Yes
only guest=no
public=no
create mask=0777
directory mask=0777
Save your file.
- Some SMB Windows shares need to use a different format to send logon permissions, such as my network share. To do this in Geany File > Open > Select “File System” > /etc/samba/smb.conf. Add the following JUST BELOW [global] and save the file.
client use spnego = no
- (OPTIONAL) I wanted to map a permanent link to my NAS network share, so that I could easily perform backups to it. On my OpenHAB Server, my NAS network share mount point (or mapped drive letter if youre a windows user) will be in /media folder and called openhabbackup.
sudo mkdir /media/openhabbackup
gedit ~/.smbcredentials
In Gedit, Enter your NAS network share username and password to access the share in the file, save it and close Gedit:
username=openhab
password=habopen
- (OPTIONAL) Now we will set the permissions on that file to keep your login details secure:
chmod 600 ~/.smbcredentials
- (OPTIONAL) And we need to setup the mapping. My NAS SMB share is on a device called dsl-ac68u-4700 and the share on that device is called openhabbackup. So to do this we need to edit a file called fstab with root permissions.
sudo gedit
File > Open > /etc/fstab and add the following line, then save the file and close Gedit.
//dsl-ac68u-4700/openhabbackup /media/openhabbackup cifs credentials=/home/openhab/.smbcredentials,iocharset=utf8,sec=ntlm 0 0
- We also need to add a few permissions for the openhab account to be able to sudo commands from within the OpenHAB services (in my case anyway, as I wanted to create an manual backup button in my sitemap within OpenHAB). To do this, type the following:
sudo visudo -f /etc/sudoers.d/010_pi-nopasswd
and then we want to add the following to the file:
openhab ALL=(ALL) NOPASSWD: /usr/share/openhab2/runtime/bin/backup
Then save the file (Ctrl+O) and remove the *.tmp off the end of the filename, Y to overwrite and Ctrl+X to exit.
- (OPTIONAL) You can now backup your OpenHAB configuration manually with a command like:
sudo -u openhab sudo /usr/share/openhab2/runtime/bin/backup /media/openhabbackup/mybackup.zip
and if you want to actually create a manual backup button in the sitemap, you do need to have manually run the above command once.
- Finally, we need UDEV to work correctly:
sudo mkdir /lib/linux-arm
sudo apt-get install libudev1:armhf
sudo ln -s /lib/arm-linux-gnueabihf/ /lib/linux-arm
sudo ln -s /lib/linux-arm/libudev.so.1 /lib/linux-arm/libudev.so
And we need to edit the Openahb2 configuration file, so that JAVA is fully working:
(ADDING THIS DOESNT APPEAR TO BE NEEDED NOW AND CRASHES MY BOOT… SO YOU MAY WISH TO CHECK JAVA WORKS WITHOUT THIS CHANGE… JUMP TO STEP 15)
sudo gedit
File > Open > /etc/default/openhab2
Replace EXTRA_JAVA_OPTS=“”
With EXTRA_JAVA_OPTS=“-Djna.library.path=/lib/arm-linux-gnueabihf/”
Save the file and exit Gedit.
-
I wanted to rename my boxes network name to OpenHAB. To do this, on the Ubuntu desktop click System > Preferences > Hardware > Armbian Config which will ask you for your password habopenopen a blue screen interface. In here BE CAREFUL*, but select Personal > Hostname and change the hostname to your liking. Click Ok and exit back out of this app press the escape button. You will need to restart the system for the name to take effect.
-
(OPTIONAL) Finally, for me, I wanted to install PS4-Waker for later use.
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt install npm
sudo npm i ps4-waker –g
setup instructions from there can be found on the PS4-Waker github site, but you must perform initial setup as the openhab account.
You should now have a working OpenHAB2 Server on an Android TV box, with a blank config, ready for you to create your rules/sitemap/items etc.
You should be able to connect to it on http://ipaddress:8080 or http://name:8080 in my case, as I renamed my server to openhab http://openhab:8080
From there, you can go to PaperUI and start adding bindings/devices/items etc and follow the main tutorials on this site. https://docs.openhab.org/configuration/index.html
Obviously you may wish to further configure security on things such as mosquitto etc, but this guide will have you at a base working condition.
P.S. If you RDP to the box, on the 1st attempt it may say error connecting. This is a issue with XRDP needing a delay setting in its config file, but I cannot remember the setting atm. As such, if you re-type in your password, it will log in the 2nd time.
I hope someone finds this helpful (and that Ive not made any spelling mistakes)
Thanks