Uncategorized

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:

service rsyslog stop
systemctl disable rsyslog

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

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

apt-get update
apt-get upgrade

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)

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

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

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

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

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

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)

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

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

Log in again and change to your home folder:

cd ~

Create a text file with a login name and password:

echo 'username:password' > passwd

Encrypt the file:

mosquitto_passwd -U passwd

Move the file to the mosquitto folder:

mv passwd /etc/mosquitto/

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

nano /etc/mosquitto.conf

Add the following text just after the comments:

password_file /etc/mosquitto/passwd
allow_anonymous false

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.

 

Advertisements

Installing node.js and cncjs on an Orange Pi Zero H2+

Based on instructions found here!
And here!

Armbian is based on Debian/Ubuntu. For cncjs it is recommended to use Nodejs 6.x so start by adding the Nodejs 6.x repository:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

Install Node.js using:

sudo apt-get install nodejs

If installed correctly then “node -v” should display v6.11.3

The only way I managed to get cncjs installed was to run:

sudo npm install --unsafe-perm -g cncjs

To start at boot I added the following to /etc/rc.local before the exit 0:

sudo /usr/lib/node_modules/cncjs/bin/cnc

Yay!

BTSync with Orange Pi

This is a work in progress…

BTSync (now known as Resilio Sync Home) is a fantastic tool for syncing files between devices.  Here’s my diary on installing it onto a little Orange Pi One running Armbian.

First download the Armbian image and copy it to an SD card using Win32 Disk Imager.  Install as recommended setting a root password and sudo user.  Once set up you can use Putty to access the device.

I’ve found it simplest to use windows to prep the USB drive.  Plug it in and use DISKPART – select the partition and use CLEAN.

Once cleaned format the drive NTFS.

Remove the drive and plug it into the Orange Pi.  Ensure it’s working using lsblk:

root@orangepione:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 3.7T 0 disk
├─sda1 8:1 0 128M 0 part
└─sda2 8:2 0 3.7T 0 part
mmcblk0 179:0 0 14.5G 0 disk
└─mmcblk0p1 179:1 0 14.3G 0 part /

With the disk formatted we can mount it. First create a folder in /mnt – I’ll use windrv (since we want to read it ultimately in Windows):

mkdir /mnt/windrv

Then mount it using mount:

mount -t ntfs-3g /dev/sda1 /mnt/windrv

If this was successful we can add it to /etc/rc.local (I was having problems with /etc/fstab – seems the drive may not be ready when fstab loads)

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

mount -t ntfs-3g /dev/sda2 /mnt/windrv

exit 0

Next we can install Samba for sharing folders:

apt-get install samba

This will take a little while. Once installed we need a user for BTSync, create one and give it a password:

root@orangepione:/dev# adduser btsync
Adding user `btsync' ...
Adding new group `btsync' (1001) ...
Adding new user `btsync' (1001) with group `btsync' ...
Creating home directory `/home/btsync' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for btsync
Enter the new value, or press ENTER for the default
        Full Name []: btsync user
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] y

Create a folder to share in /mnt/windrv – I’ll use Video:

mkdir /mnt/windrv/Video

With the drive mounted and Samba installed we can now add a share to Samba. Edit /etc/samba/smb.conf and add to the bottom of the file:

[Video]
   comment = Video Share
   path = /mnt/windrv/Video
   available = yes
   browsable = yes
   guest ok = yes
   read only = yes
   write list = btsync
   create mask = 0755

This will create a share with guest read only and write access to btsync. Reload the Samba service:

service smbd restart

And then test in Windows in a file explorer to \\192.168.xxx.xxx\Video.

Now we need to install Resilio Sync. First add the repository to the list:
(info here: https://help.resilio.com/hc/en-us/articles/206178924-Installing-Sync-package-on-Linux)

vi /etc/apt/sources.list
deb http://linux-packages.resilio.com/resilio-sync/deb resilio-sync non-free
~

Slightly different for arm64:

deb [arch=armhf] http://linux-packages.resilio.com/resilio-sync/deb resilio-sync non-free

Then add the Resilio key so we can install packages – change to the tmp folder first as the key is not necessary once done:

cd /tmp
wget https://linux-packages.resilio.com/resilio-sync/key.asc
apt-key add key.asc

Install Resilio Sync:

apt update
apt install resilio-sync

Slightly different install for Arm64:

dpkg --add-architecture armhf
apt update
apt install resilio-sync libc6:armhf

Start Resilio Sync and set it so it autostarts:

systemctl start resilio-sync
systemctl enable resilio-sync

All should now be working. Check by browsing to http:\\OPSync:8888

Below is some extra stuff for an Orange Pi Zero and enabling the Access Point:

Info found here:
https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/

Below is even more on installing Plex:

Info found here:
https://www.htpcguides.com/install-plex-media-server-on-orange-pi-devices/

Found this for Pine64:
http://jez.me/article/plex-server-on-a-pine64-how-to

sudo su -
apt-get install apt-transport-https
wget -O - https://dev2day.de/pms/dev2day-pms.gpg.key | apt-key add -
echo "deb https://dev2day.de/pms/ jessie main" >/etc/apt/sources.list.d/pms.list
dpkg --add-architecture armhf
apt-get update
apt-get install binutils:armhf
apt-get install --no-install-recommends plexmediaserver-installer

Some stuff about OpenVPN client:
https://askubuntu.com/questions/229800/how-to-auto-start-openvpn-client-on-ubuntu-cli

Copy the *.ovpn and *.txt to /etc/openvpn – the text file is named in auth-user-pass *.txt as:

your_server_user_name
your_server_passowrd
Save and Close
sudo nano OpenVPNConfigFile.ovpn

Rename the ‘.ovpn’ to ‘.conf’

sudo nano /etc/default/openvpn

Uncomment AUTOSTART=”all”
sudo service openvpn start

Oh, and add ‘keepalive 10 120’ or similar to the configuration file.

Final note: From time to time you may get a certificate error to fix the public key will need to be updated…

wget -qO - https://linux-packages.resilio.com/resilio-sync/key.asc | sudo apt-key add -

Creating an OctoPrint Atom Server

This is a work in progress – not complete yet…

  1. Optional: Go through the Windows install on the NUC and setup (and updated) the pre-installed Windows 10 Home – once fully updated I created a full disk backup ISO using the Windows tools.  I’ll probably never use this but I think of it as a safety net.
  2. Download the linux distribution.  For this I’m using Ubuntu 16.04 LTS (64 bit) – this was current at the time of writing.  Download the iso to your local disk (ubuntu-16.04.2-server-amd64.iso).
  3. Create a bootable install USB stick.  I’ve tried a number of tools but Rufus 2.15 had the best success.
  4. Boot up the NUC with the USB stick – you may need to head into the bios and select the boot drive.
  5. Install Ubuntu.  There’s many tutorials on how to do this – only ‘additional’ package in installed was SSH.
  6. Reboot and login with your own account.
  7. Enable root and root SSH.  First you need to give the root account a password:
    sudo passwd root

    and then edit the ssh config with ‘vi’:

    sudo vi /etc/ssh/sshd

    find the ‘PermitRootLogin’ line, press ‘Insert’ key to edit, and change it to:

    PermitRootLogin yes

    press ‘Esc’ key to exit edit then ‘:w’ to write and ‘:q’ to exityou can restart the service but I find it just a quick to reboot:

    sudo reboot
  8. Move the NUC to where you want it to go and attach power and ethernet.  At the time of writing I was unable to get WiFi working but this may change in the future.
  9. Download and install WinSCP and Putty.
  10. Optional: I like to set a reservation for the NUC in your DHCP (router) – this way you’ll always have the same IP for the NUC.
  11. Start WinSCP and login as root, also start Putty and login as root.


  12. From time to time you’ll need to update Ubuntu – we’ll do it now:
    apt-get update

    and

    apt-get upgrade

    Note that you don’t need sudo since you’re logged in as root.

The ‘Computer Room’

Here’s the home man cave.   Lars is running an i5, beside him is a spare first gen i7, and I’m sporting an i7-6700.

My desk is the hobby shop with shelves of electronic parts, a bench power supply, soldering station and a number of meters – hoping for an oscilloscope in the near future.

Currently have three 3D printers all web enabled on OctoPrint (which was set up on an Atom X5-Z8350 NUC)

Have a few projects underway.  There’s a toster oven re-flow soldering oven, a single board BT Sync device and a new Hypercube printer (making improvements from the first).