It turns out that my old blog post about making an August lock bridge device was popular https://www.thenoel.org/diy-august-l/

Unfortunately, some folks had problems getting things to run due to a combination of some vague instructions I put up and possibly a lack of experience working with things like nodejs.  So, I thought about making a Docker image that could do most of the nodejs stuff automagically.  It took some time as I had never worked with Docker on a Raspberry Pi before and I didn't know how to make bluetooth work in a container.

Fortunately, balena has all of this worked out already!  The other part of this is getting Docker to work properly on the Raspberry Pi Zero W.  As of this writing, there is a bug that causes a seg fault when running Docker on Raspbian.  There is a workaround if you install a particular version.  Instructions will be below.  First, a note:  You should know how to SSH into your Raspberry Pi Zero and work with Linux.  It is expected that you will run this bridge headless and hidden away somewhere (but close enough to connect via bluetooth to your lock).  The instructions below start with the assumption that you have installed Raspbian Stretch on your zero.

1.  Run these commands to get some required things and things up to date:

sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev

2.  Run these commands to install the particular version of Docker that doesn't crash:

curl -fsSL https://get.docker.com -o get-docker.sh

chmod u+x get-docker.sh

VERSION=18.06.3~ce~3-0~raspbian ./get-docker.sh

Running the Docker Container

To run the Docker container, launch it with environment variables that specify the key, key offset, and port (default is 8080).  An example is below:

sudo docker run --restart always -d \
-e "OFFLINEKEY=ABCD1234" -e "OFFLINEKEYOFFSET=1" -e "PORT=8080" \
-v /run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket \
--privileged --network host leonowski/august-server

Explanation of options:

--restart always -->  tells Docker to always restart this container

-d -->  tells Docker to run the container daemonized

-e --> specifies an environment variable pair.  3 are specified for the key, key offset, and port (if port is not set, 8080 is default).  Obviously, set it these env vars to your particular lock's keys.

-v /run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket --> maps the dbus path to allow bluetooth to work.  :)

--privileged -->  the bluetooth stuff requires privileged container mode to be on

--network host -->  the bluetooth stuff also requires the container to be in network host mode.

One Final Thing

I was building the container on the raspi directly and then I found out you could cross compile on an x86 machine including Docker Hub!  That's why you can pull the image directly from Dockerhub at leonowski/august-server.  Check out the Dockerfile to see how the cross compile works.  It's really simple thanks to the folks at balena.