A Dreamer's Lair

Setting up a fresh Raspberry PI 3 with Docker

I already mentioned in a previous post that I am moving away from several of my existing systems to replace them with new, and hopefully more reliable, solutions.

Not too long ago I started out experimenting with Docker containers on my Synology NAS and I must say that this has turned out quite well. Because of this I am planning to use Docker for all my new domotica where possible.

I intend to use a Raspberry PI 3 as a docker host. In the future I could even include Docker Swarm to make my domotica available 24/7 even when some hardware fails.

Setting up a PI 3 for Docker is already described in several posts on the great wide internet. Below I will describe the method I used including the links for that. No need to reinvent the wheel now is there!

Prepare SD/USB

The first step in setting up the PI is to prepare both a micro SD card and a USB thumb drive. I want to use the USB drive as my main memory device on the PI because it is less vulnerable then a micro SD card. But to be able to use a USB drive one first has to start with a micro SD card.

So from the Raspberry site itself I downloaded the lastest Raspbian Stretch Lite. The Lite version of course since I don’t want to use the GUI.

So download the image from here.

For writing the downloaded image to the SD card and USB drive Raspberry suggests Etcher which works just fine. See here.

I follow the instructions and now have both a micro SD card and a USB drive with Raspbian Stretch Lite on them.

On both the images I added an empty file called ssh so ssh is enabled by default when booting.

Boot and program USB mode

Next step is to connect the PI to the desired peripherals of choice (display, ethernet, keyboard, mouse etc).

Then insert the micro SD card and turn the power on (insert micro USB power cable).

We now want to program the USB mode on the PI. How to do this can be found here. So program the USB mode, reboot the PI and check if USB mode has been enabled.

When you have confirmed that USB mode is active, we can power off the Raspberry with the following command

sudo poweroff

Boot from USB, initial setup

Next step is to boot from the USB drive. So remove the micro SD card from the PI and attach the prepared USB drive. Again power on the PI and wait for it to have booted.

The first thing after we have logged in, is to change the password for the user pi. You can do this with the command passwd. Make sure it’s a strong password!

Next we want to make sure the PI has all the latest updates:

sudo apt-get update
sudo apt-get upgrade

Next we start the configuration tool using the command sudo raspi-config. With this configuration we need to change the folllowing stuff:

  • Hostname -> choose an appropiate one (for example DOM-PI01 for domotica PI number 1)
  • Wi-fi -> Enter your SSID and passphrase to enable Wi-fi. I want this enabled so I don’t need to have the PI connected with an UTP-cable.
  • Localisation options -> Change the timezone, keyboard layout and Wi-fi country to what’s applicable.
  • Advanced options -> Choose the smallest possible memory split of 16MB to free up as much RAM as possible. This because we don’t use a GUI anyway.

Quit the tool and let the PI reboot.

Next step is to make the IP-address for the WLAN static (make sure you reserve it on your router!) so the PI can be accessed wirelessly through a fixed IP-address.

Enter the following command to open the dhcp config

sudo nano /etc/dhcpcd.conf

Add the following lines to the config

interface wlan0
static ip_address=<your-static-ip>/24
static routers=<ip-to-your-gateway>
static domain_name_servers=<ip-to-your-dns-server>

(if you want you can do this for the LAN too. Simply use ‘interface eth0’)

Press Ctrl-X then Y to save the file and exit nano.

We now reboot one more time and again log in to the PI. Now verify with ifconfig that the WLAN0 is using the correct assigned IP-address.

Since I am now done with the initial setup, I power off my PI (sudo poweroff) and then remove the power cable.
Now I can remove the keyboard, mouse and monitor since they are no longer necessary.

When you have done this power up the PI by connecting the micro USB cable and let it boot. To access it you can use any SSH client. I use the free tool Bitvise SSH Client.

Setup watch dog and monitor tools

To monitor the PI so it for example automatically reboots when it hangs you can use watchdos and monitor tools. The DomoticZ site shows some nice options for this.

I installed the watchdog and Monit.

Add the Aeon Labs Z-Stick

Since I am planning to use the Aeon Labs Z-Stick (gen2 in my case) I insert the device into the PI. Since there are several reports of issues with such hardware after rebooting, I create a symbolic link again with useful help of Domoticz.

I opened the configuration with

sudo nano /etc/udev/rules.d/99-usb-serial.rules

and since I use a gen-2 Z-Stick I added the following line to it

SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="ttyUSB-ZStick-GEN2"

I can now access my Z-Stick hardware using the device


regardless of the physical USB port it is attached to.

Mount a folder from my Synology NAS

To be able to more conveniently see data files which the docker containers use, I have created a shared folder on my NAS called dockerdata. To use this on the PI I have to mount an NFS volume on it.

First create the folder locally on the PI

mkdir /home/pi/dockerdata

The open fstab

sudo nano /etc/fstab

and add the following line to it

<ip-of-your-nas>:/volume1/dockerdata /home/pi/dockerdata nfs defaults 0 0

This assumes that you have a shared folder called dockerdata on your NAS.

Mount the volume

sudo mount -a

and check if the folder /home/pi/dockerdata reflects the contents of /volume1/dockerdata.

Install Docker CE

The final step in setting up our PI for docker is to install Docker itself.

You can do this simply by entering

curl -sSL https://get.docker.com | sh

Docker CE will now be installed.

And there you have it. The PI is ready to be used as a Docker Host!

Migrating from Razberry to Aeon Labs Z-Stick (perhaps with Domoticz)

After having used the Razberry on the Raspberry PI for quite some time now, I am growing tired of having to power cycle the PI every month of so because the Razberry stops working. Also the API to the Razberry has changed several times which forces me to change my software as well or to keep working with an older no longer supported API.

So I have decided to move away from the Razberry and use the Aeon Labs Z-Stick (gen-2) on a new PI 3. It seems that the Z-Stick solution is much more stable. If this works the way I hope I perhaps might migrate to a gen-5 Z-Stick as well. But since I already have a Gen-2 let’s use that to start with.

I am thinking about using Domoticz for its integrated Open ZWave library support to control my ZWave network. Since all of my domotica uses MQTT for communication I might use the MQTT possibilities of Domoticz too.

I will do some experimenting on this first before deciding to use Domoticz or perhaps some other Open ZWave implementation. Or even build my own MQTT gateway using the Open ZWave library.

Perhaps I will share some posts on how to get that working or how it turns out to work (or not).

Compile Mono on a Raspberry PI (for hard float support)

You could say I am a .NET man. So the first thing I investigated after deciding to develop software on the Raspberry PI for my Home Automation, was how to develop in .NET on Linux 🙂

Fortunately there is Mono. A multi platform implementation of the Microsoft .NET runtime and C# compiler. Yeah 🙂

However unfortunate, the default Raspbian distribution (I installed Debian Wheezy through the NOOBS image) still ships with the more or less ancient 2.10 version of Mono which doesn’t support the so called hard float operating systems. And guess what… the Raspberry PI uses a coprocessor so it’s hard float alright 🙁

After some searching on the internet I read that I wasn’t the only developer who wanted .NET on the Raspberry 🙂 There were some branches of the main Mono branch (in GitHub) that supported the hard float Raspberry.

I searched the internet some more to find packages which I could use to install this modified version of Mono. To no avail I must confess.

Ah well, why not compile Mono myself then? That turned out to be easier said than done. Most posts concerning making Mono were a bit too steep on my Linux learning curve. Being a Windows man myself, Linux is quite a different cup of tea where almost everything is handled in obscure command line scripts.

But after more searching, and some asking around in forums, I finally compiled together what to do build Mono on the Raspberry PI.

And for those of you, who as I struggle with the same challenge, here is what I did to build the latest Master branch of Mono (as present on Github). I performed this build on a fairly fresh Raspberry PI (with debian wheezy) so it could be that some components are already installed on your Raspberry. Well here comes.

First I needed to install some components:

sudo apt-get install autoconf
sudo apt-get install libtool
sudo apt-get install gettext

Also, because Mono itself is build with Mono (a bit of a paradox..) you need to have some sort of Mono compiler installed. I used monolite-fast for this. So

sudo make get-monolite-latest

Because we are building Mono from the master branch we have to clone this on the PI (to get a local version of it).

sudo git clone https://github.com/mono/mono.git

After this has been done the following command take care of initialisation and building.

cd mono
sudo git submodule init
sudo git submodule update
sudo ./autogen.sh --prefix=/usr/local
sudo make
sudo make install

After the last command has finished, and be advised that the whole build process takes a couple of hours(!) on the small Raspberry PI, the latest master branch of Mono is available on your system.

You can test the version which is now available on your system

mono --version

which should result in something like this

Mono Runtime Engine version 3.2.7 (master/bb44c68 Sat Dec  7 20:08:30 CET 2013)
Copyright (C) 2002-2013 Novell, Inc, Xamarin Inc and Contributors. <a href="http://www.mono-project.com">www.mono-project.com</a>
TLS:           __thread
SIGSEGV:       normal
Notifications: epoll
Architecture:  armel,vfp+hard
Disabled:      none
Misc:          softdebug
LLVM:          supported, not enabled.
GC:            sgen

Now we can finally develop .NET on the Raspberry!