Version 2 - OpenHAB + OpenHABIAN on an Android TV box running Armbian (Setting it up)

Contents of this post:

  • Intro
  • Hardware you will need
  • Setting it up (Steps 1-19 get Armbian installed/working)
  • OpenHABian OR OpenHab choice
  • OpenHAB manual installation (Steps 20-23)
  • Congratulations - If you reach here you will have a working Armbian/OpenHAB server.
  • A word about JAVA and OpenHAB.
  • Optional Changes (Samba network shares, OpenHab backup, PS4 Waker)
  • Booting off SD/USB problems.
  • uEnv.ini and extlinux.conf (Required for booting Armbian on other TV Boxes)

Please note, below this post, I have linked to another post on the Armbian forum, which covers other topics relating to Armbian, boot problems, boot configuration problems, installing to emmc/NAND if your system supports it, what to do if you brick your device, making backup images etc.

Intro

I had written a previous article just over 1 year ago and things have moved on and its now far simpler/more efficient to do this… between 20 to 40 minutes depending on your speed. To get a basic working OpenHAB server, you only need to follow this guide steps 1 to 23 for manual setup..

This setup is for a MeCool M8S PRO w (4x cores, 2GB ram) which retails for around ÂŁ21 delivered or maybe $30. This box has worked great for me over the last year, however I am about to upgrade to a Beelink GT1 Mini (will add a further reply at the bottom of this document) as this unit will be faster, 4GB RAM, will support installing the OS to the on-board emmc ram and the WiFi/Bluetooth will work. (not that the MeCool box isnt cutting it, I just fancied something new to play with. The MeCool mostly runs about 10% CPU and about 600MB of its RAM with OpenHAB). EDIT - There are 2 version revisions of the M8S Pro w, both look the same, one will install to emmc/NAND ok and the other doesnt (from what I can tell). I dont know how you tell which one is which as Ive only got the 1 box.

To be clear, on the MeCool M8S PRO w, you have to plug it in via a network cable and run the OS off an SD card or USB stick. The Bluetooth and WiFi dont (at this moment) work. So, if that is a limitation for you, either keep an eye on the Armbian forum looking for later OS builds that may work, or on there you can also find other Android TV boxes that will work.

To answer a previous question about OpenHABIAN and can you use that on this setup… Yes most of it will configure up and work on this build now (I dont think log viewer works). Complete steps 1 to 19 if you want to use OpenHABIAN (or all 24 steps if you want the manual way)

Hardware you will need:

  • MeCool M8S Pro W (or box of your choice…after researching which ones work).
  • A Windows PC/Laptop.
  • A micro SD card OR USB memory sick (16GB or larger recommended)
  • A way to plug that SD card into your Windows computer to image the Armbian OS onto it.
  • A Cat 5 LAN cable to plug it into your Router/Switch/Network port.

NOTE: It looks like you will only see the option to install Armbian to eMMc memory, within Armbian Config, if you are running from an SD Card, NOT a USB stick. (As mentioned, you cannot do this with this MeCool M8S PRO w anyway, but you can with other boxes like the Beelink GT1 Mini I am getting).

1

As an additional note, if you want to UPS protect your device from power outages etc, most of these Android TV boxes (and I assume maybe Pi’s but Ive never tested so research that before you try it) support being powered from the USB ports (and the main power socket simultaneously too if you like). The RAVPOWER RP-PB078 is a battery pack for charging USB devices like phones etc. Its special trick, is that it is like an online UPS style device, meaning it can be both charging and powering your device at the same time. So, if the power cuts out, it will keep powering your device through the USB port (or you can buy a USB to 5v adapter cable if you like and use the main power port). I dont know how long for sure, but my rough estimation is this will give you about 5 to 9 hours run-time on the battery pack without any problems, plenty for small power outages.

Software/Downloads:

Setting it up

Steps to image your SD Card/USB stick from a Windows PC:

  1. Download the above files.
  2. Unzip/Extract with Armbain image file (Use WinRAR or 7Zip).
  3. Install Win32DiskImager .
  4. Insert your micro SD card or USB Stick into your PC.
  5. Run Win32DiskImager as an Administrator.
  6. In Win32DiskImager , click the folder Icon and select your Armbian Image file.
  7. Check the Device field is pointing at your SD card/USB stick you just inserted and click the Write button.
  8. Wait about 5 minutes while the SD card/USB is imaged. (takes about 2 minutes at USB3 speed)

2

The MeCool M8S PRO w and other Amlogic boards should always boot external media first, however there is a simple process I will add at the bottom of this document to show you how to change the boot order if needed. The fix (as far as I know) only works on Amlogic based chipsets 905, 912, 922 etc. If you use a system based on Rockchip or something else, you will need to research the Armbian forums, which I would do ahead of time anyway if you decide to use an alternate TV Box.

For different Android TV boxes (other than the MeCool M8S PRO w), you may need to edit the uEnv.ini and extlinux.conf file on the SD card/USB stick, to choose a different DTB file. The DTB files are effectively for choosing what hardware drivers are needed when loading the OS and different Android TV boxes will have different chipsets e.g 905, 905X2, 912, RK3399 etc. I would suggest using Notepad++ for editing this file on a Windows computer, as the file is in UNIX file format, so much easier to read with Notepad++. I will add a short explanation of uEnv.ini and extlinux.conf at the bottom of this document (though they arent needed on the MeCool M8S PRO w.

Installing onto the MeCool M8S PRO w

  1. Place 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.
  2. 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.

If it doesnt boot to Armbian and you have the box I suggest or an Amlogic based chipset, read the note at the bottom of this document.

  1. 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.

  1. The box will now load the GUI, asking you for the password of openhab . Log in and you will now be at the Armbian desktop.

  1. From here, we want to open the Application menu at the top left > Settings > Armbian Config. Type in your password when prompted.

  1. In the config system that opens up, we are going to perform a few tasks pretty quickly. Setup our system keyboard locale, change the name of this computer on the network, setup SAMBA file sharing, setup Microsoft RDP for remote control access to the system and install OpenHAB.

NOTE - On this build of Armbian with this MeCool box, Ive had a situation where it sometimes doesnt like detecting my monitor correctly when it boots, going from the text boot, to the GUI interface, meaning, you can get a black screen. So ensure RDP is enabled on your 1st boot (step 19), then you can always RDP from a windows machine to get to the GUI desktop OR, boot it with no monitor attached and after about 5 minutes, you can plug the monitor in and it usually works… As I say, only on THIS build of Armbian and THIS MeCool.

You can use the keyboard cursor keys, TAB key to move around each screen and Escape will move you back a screen.

  1. With your cursor keys, go down to the Personal menu, select Timezone and choose your region. then back and select Keyboard and select your correct keyboard layout.

  2. Still on the Personal menu select Hostname. This allows you to change the name of the computer to whatever you want to call it on your network. For simplicity, call it OPENHAB (but choose something else if you wish). After this, go back to the main Armbian Config main menu.

6

7

  1. Back at the main menu, select Software and scroll down to RDP - Enable remote desktop from windows and select it. This will allow you to use Remote Desktop (mstsc) to this computer ON your LOCAL network from a Windows computer by connecting to the OpenHAB server’s network name or local network IP address. It will not be internet accessible via RDP unless you create a rule in your router/firewall for port 3389 to point to your OpenHAB server, which, please research security concerns if you want to go down the route of allowing the internet to RDP your server.

8
(Yes, I know my screen grab says disable, I had already installed RDP)


OpenHABian or OpenHAB

If at this stage you wish to use OpenHABian you can do that as an alternative to steps 20, 21, 22 and 23. NOTE - Some of the automated processes may not work due to file paths not being the same as a Pi, however in my tests, the majority of the setup did work fine (logviewer didnt seem to configure correctly).

IMPORTANT whichever you choose, please read the section A word about JAVA and OpenHAB.


Alternatively, keep going as below:

OpenHAB manual installation

  1. Back at the Software menu, select Softy. In the next menu that appears, use the space bar to select SAMBA (if you wish to create shares on your OpenHAB server to access over the network) and also select OpenHAB. Tab over to the OK button and press Enter. This will take a couple of minutes to download/install everything.

You may get a couple of prompts if you install SAMBA.

  • What is your samba username
    Put in the username you are using e.g. openhab

  • What is your samba password
    Put in the username you are using e.g. habopen

  • What is your samba group
    You can leave this blank or if your home network has a workgroup name, put that in.

Once this process has competed, use the Escape key to back out and close Armbian Config.

  1. Back at the main Desktop, select the Applications menu and Terminal Emulator.

  2. In the window that appears, we are going to enter a couple of commands.

At this point in the config, if you are connecting via RDP, you will be able to copy/paste between your windows computer and the Armbian RDP session if you wish. Or you could just open this page on your Armbian Chromium browser.

  1. In the Terminal window, enter the following commands one by one. (You will be prompted for your password).
sudo systemctl enable openhab2.service

sudo apt-get install mosquitto

sudo systemctl start openhab2

IMPORTANT if you are on OpenHAB 2.4 or earlier, please read the section A word about JAVA and OpenHAB.

CONGRATULATIONS

You now have a working OpenHAB server with a Mosquito MQQT server installed.

You can connect to it by going to http://openhab:8080 (or the name you gave your server on port 8080)

From here, you can either follow my further instructions for other tweaks, or look at other guides/documentation for setting things up.


A word about JAVA and OpenHAB.

Armbian will install OpenJava 11. Until OpenHAB 2.5 comes out (so Im told), OpenHAB 2.4 or earlier requires Java version 8 (on any OS platform). Dont use OpenJRE v8, I tried it, which resulted in CPU spikes, double the memory and sluggish response from OpenHAB/My devices. Instead, use Zulu-8-Embedded.

So if you are installing OpenHAB 2.4 or earlier:

  1. Go to the Armbian Applications menu > Settings and open Synaptic Package Manager.
  2. When it opens, hit the search icon and search for openjdk. You want to right click on openjdk-11-jre-headless and Mark for complete removal. and press the apply button.
  3. Close Synaptic Package Manager and at the main Desktop, select the Applications menu and Terminal Emulator.
  4. Run the following commands:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0xB1998361219BD9C9
sudo apt-add-repository 'deb http://repos.azulsystems.com/ubuntu stable main'
sudo apt-get update
sudo apt-get install zulu-embedded-8

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

sudo geany /etc/default/openhab2
  1. In the file, replace:

EXTRA_JAVA_OPTS=“”

With

EXTRA_JAVA_OPTS=“-Djna.library.path=/lib/arm-linux-gnueabihf/”

  1. Save the file and exit Geany.
  2. Reboot your system

OPTIONAL CHANGES


Setting up SAMBA to share your OpenHAB config/User files on your server over the network, so you can edit them on another computer.

  1. At the main Desktop, select the Applications menu and Terminal Emulator. In the Terminal, enter the following commands:
sudo apt-get install cifs-utils

sudo smbpasswd -a openhab

sudo chown -hR openhab:openhab /etc/openhab2 /var/lib/openhab2

sudo systemctl restart smbd

sudo geany /etc/samba/smb.conf
  1. In Geany 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 your shares 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
  1. Save the file.

You will now be able, from another computer on your local network, to browse to your OpenHAB server and see your OpenHAB config and user shares.


Setting up an in OpenHAB button to back your configuration up to a remote network share.

Settings are related to this forum post:

In my case, Im saving a network share called openhabbackup on network device dsl-ac68u-4700. To allow this, you need to grant permission for OpenHAB to run sudo commands and have saved credentials to access the share.

  1. At the main Desktop, select the Applications menu and Terminal Emulator. In the Terminal, enter the following commands:
sudo apt-get install zip

sudo mkdir /media/openhabbackup

sudo geany ~/.smbcredentials

In the file, enter the following and save the file, then close Geany.

username=openhab
password=habopen

We have just created a mount folder called openhabackup on our OpenHAB server and stored the credentials we will use on our network device dsl-ac68u-4700 to log into its share.

  1. To secure the credentials file, run the following in the terminal:
sudo chmod 600 ~/.smbcredentials
  1. Now we need to edit Fstab to store the link between our OpenHAB server directory we just created and the folder thats shared on dsl-ac68u-4700 our network device. In the terminal:
sudo geany /etc/fstab
  1. add the following to the file, save it and close Geany.
//dsl-ac68u-4700/openhabbackup /media/openhabbackup cifs credentials=/home/openhab/.smbcredentials,iocharset=utf8,sec=ntlm,auto,user,vers=1.0 0 0
  1. We now want to grant OpenHAB permission to run the OpenHAB backup routine with sudo commands. In the terminal:
sudo geany /etc/sudoers.d/010_pi-nopasswd
  1. add the following to the file, save it and close Geany.
openhab ALL=(ALL) NOPASSWD: /usr/share/openhab2/runtime/bin/backup

Installing PS4-Waker (For those who want to turn on/off, run apps and control their PS4 via OpenHAB).
This is much simpler than it used to be.

  1. At the main Desktop, select the Applications menu and Terminal Emulator. In the Terminal, enter the following commands:
sudo apt install npm
sudo npm i ps4-waker -g

From here, you will need to setup PS4-Waker in the terminal window you have open, by following GitHub - dhleong/ps4-waker: Wake your PS4 over LAN (with help from the Playstation App)

Once you have configured it, you can then issue commands from within OpenHAB rules.


BOOTING OFF SD/USB PROBLEMS?

If you cant boot an Amlogic based system off external media

  1. Once you have completed steps 1 through to 8, of the initial configuration at the top of this guide. Boot your Amlogic based system into the Android OS that is installed on the box.

  2. When you are booted in to Android, plug in your newly created Armbian SD card or USB stick to the system.

  3. Somewhere in the Android interface, perhaps the applications folder, you will find a program called Update OR Update&Backup. Open this application.

10

  1. It should give you the choice to update OTA (Over the Air) or from a Local File. Select Local and browse to your SD card/USB stick.

  2. You will find a file called aml_autoscript.zip select that and confirm the upgrade.

  3. The system should reboot, most likely twice. After which it may either boot into your Android OS or it may start booting into Armbian. Its also possible it may just do the reboots and then sit at a splash screen for a while. In short, if its not booting an OS within 3 minutes, give it 5 minutes, then pull the power and try rebooting (with your SD card/USB stick in).

  4. If it doesnt work (boot Armbian off your SD card/USB stick), try again.

To explain whats occurring… The file is from here:

https://github.com/150balbes/Amlogic_s905/wiki/s905_multi_boot

What it does, is tell the boot partition of the Android TV box, that it has multi-boot (can boot from any device, internal/external) and sets external devices as being the 1st thing to try booting off.

If youve copied your Armbian to the emmc chip and it wont boot off the internal memory, read up below on uEnv.ini and extlinux.conf… though some boxes just cant/wont boot off emmc


uEnv.ini and extlinux.conf (Not the MeCool M8S PRO w)

When you set up Armbian on a Android TV box, you need to tell Armbian what drivers/setup to use for the chipset in your box. This is done through matching the best DTB file to your TV Box’s hardware. To do this, there are 2 files on the SD card or USB stick you create.

In the root of the BOOT partition, you will find uEnv.ini and in /extlinux directory, you will find extlinux.conf.

Editing the files and picking the right DTB
These files are best edited in Notepad++ on Windows, or some program that happily edits Unix format text files.

Within these files you will specify a DTB file, from the dtb folder on the BOOT partition.. Your TV Box might be a 905x2 chipset, or an 912 etc etc. In short, look at the Armbian forums to find the best one, or just pick one that you think, list it in the uEnv.ini and extlinux.conf, see if the box will boot (try a different DTB file if not) and see if all the hardware works (Try a different DTB file if not, or some boxes its possible to find there is no bluetooth driver or something. Best to research the Armbian forums first to see what boxes people have success with.

What do these 2 files do and why cant I boot off emmc internal ram?
My understanding is that uEnv.ini takes care of the boot information when you are booting off SD card or USB Stick and the extlinux.conf takes care of the boot sequence if you load the OS onto the internal eMMC memory (the internal hard drive ram chip thing).

So long and short… if you boot off external media, transfer the OS to the internal eMMC and you HAVNT updated the extlinux.conf, dont expect it to boot off the internal eMMC, it will just sit at the box’s spashscreen. (though you can boot off an external SD/USB and edit those files).

In short… just update BOTH files to ensure you can boot off external SD card/USB stick and internal emmc (if you copy the OS over).

What should the files look like?

uEnv.ini:

dtb_name=/dtb/meson-g12a-x96-max-rmii.dtb
bootargs=root=LABEL=ROOTFS rootflags=data=writeback rw console=ttyAML0,115200n8 console=tty0 no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0

extlinux.conf

LABEL Armbian
  LINUX /zImage
  INITRD /uInitrd
  FDTDIR /dtb
#  FDT /dtb/meson-gxl-s905x-khadas-vim.dtb
  APPEND root=LABEL=ROOTFS rootflags=data=writeback rw console=ttyAML0,115200n8 console=tty0 no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0

You would be replacing meson-g12a-x96-max-rmii.dtb with the DTB file that matches your box, in BOTH these files.

Also, DONT whatever you do, delete the # out of the extlinux.conf file, its meant to be there!

2 Likes

Scroll up to the top of this page for the setup guide


Ive also written a post on the Armbian forums, which is pretty much most of this guide (without the openhab bits), though I also cover:

Example of setting up a system

  • Example Setup on a MeCool M8S PRO w (Change your DTB file in uEnv.ini and extlinux.conf for other boxes).
  • Hardware you need
  • Software/Downloads
  • Setting it up
  • Steps to image your SD Card/USB stick from a Windows PC
  • Installing onto the MeCool M8S PRO w (Or any other box assuming youve changed the DTB)
  • Congratulations - If you reach here you will have a working Armbian server.

Booting Problems and getting your system to boot

  • Booting off SD/USB problems.
  • uEnv.ini and extlinux.conf (Required for booting Armbian)
  • Editing the files and picking the right DTB.
  • What do these 2 files do and why cant I boot off emmc internal ram?
  • What should the files look like?
  • Installing onto emmc/NAND - The internal hard drive of the TV box.
  • LOST.DIR, System Volume Information and Android folders cause problems booting off eMMC/NAND.

What to do if you brick your device.

  • Ive done something and now my box wont boot/stuck on a splash screen/is a brick what do I do?
  • Getting the system recovered - notes
  • Doing the recovery

Bootable Backups ( can be used to migrate to another TV Box too )

  • Backing up if you are using SD card/USB stick for booting/running Armbian OS
    • You will need the following to do this
    • How to get things setup and do it (create/restore your image)
  • Backing up if you are using emmc/NAND for booting/running Armbian OS
    • You will need the following to do this
    • Option A and Option B
    • How can I tell Ive booted from my Backup SD card?
    • What have we actually just done?
    • What can I do with my imaged SD card?