A Dreamer's Lair

Run mosquitto in a docker container on the PI

Since I want to migrate all domotica software to my raspberry PI (or perhaps PI’s) it is time to say good bye to my windows mosquitto instance running on my current windows domotica server. Of course I will use docker to run mosquitto also.

I searched the web a bit, and perhaps I didn’t search well enough, but I couldn’t find an up-to-date repository for a mosquitto image that will run on the Raspberry PI. The ones I found, were all a year or more old and for example based on debian jessie whereas debian stretch is the standard now.

So, based on a existing docker file I found on the web, I created a new mosquitto docker image for the Raspberry PI. I have uploaded it to my repository so it can be used by myself, and perhaps others who have looked for one too ūüôā

The image can be found here.

As I mentioned in my previous post I already have a mount to my NAS in which I want to store my domoticz data. The mount on the PI is

/home/pi/dockerdata

On this mount I created the necessary sub folders for mosquitto. For mosquitto to work a basic config file should be put in the config folder. As a bare minimum it should have the following contents.

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /mosquitto/data

log_dest file /mosquitto/log/mosquitto.log

The mosquitto image can be installed as follows. I have added the –reatart option so the container is automatically started when for example the PI has been rebooted.

docker run --name=mosquitto \
           --restart unless-stopped \
           -d \
           -e TZ=Europe/Amsterdam \
           -p 1883:1883 \
           -v /home/pi/dockerdata/mosquitto/config:/mosquitto/config \
           -v /home/pi/dockerdata/mosquitto/data:/mosquitto/data \
           -v /home/pi/dockerdata/mosquitto/log:/mosquitto/log \
           dromer1967/arm32v7-mosquitto

And behold, mosquitto is running in docker on the PI.

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

/dev/ttyUSB-ZStick-GEN2

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 away from Elv MAX! heating

After having used the Elv MAX! heating solution for several years now, I have decided to finally move away from it. It simply is not stable enough for a longer period. Every couple of months the MAX! Cube loses its configuration or part of it. And then I have to pair every thermostat and radiator valve again.

However until recently I couldn’t come up with an affordable alternative to it. Stuff¬† like the Danfoss heating zones is very expensive. There are ZWave valves available but the limitiation with them is that they can only be controlled with a set temperature. And (of course) you don’t want to control a room from the temperature reading from several radiator thermostats but from a central reading on a room thermostat of some sort. But the most important issue with this is, that I have ‘city heating’. The hot water enters my house and flows into the radiators. This hot water flow is regulated with a ZWave switch which turns the flow on or off. For this to work I need to know when to turn on the boiler switch. If one would do this using the reported temperatures I think its level of control is not fine grained enough.

Fortunately there seems to be a new player on the market: the¬†EUROtronic Spirit Z-Wave Plus. It’s an affordable ZWAVE radiator thermostat which has the extra feature that you can choose to report and control the valve opening. With this option I can now see how far the radiator valves have been opened. And when one of them reaches the threshold (at for example 25% opening) I can actuate the boiler switch to let the city heating water flow into the house.

Since I am migrating to a ZWave Z-Stick solution anyway I might also start an experiment with one (or a few) of these newer radiator thermostats to see how this performs.

This is also important since I am having an airco/Heat pump installed into the living room. The plan is to let both the city heating and the heat pump work together to get a comfortable temperature in the living room.