Not too long ago I purchased a Mostly Printed CNC from V1Engineering. I’ve been taking my time putting it together (and still have some cleaning up to do) but I finally got it to a usable state a couple weeks ago. It’s awesome to be able to watch it move completely on its own and make sounds resembling alien space crafts for the 1980’s Galaga arcade game. It’s even more awesome to think about all the different projects it will be useful for.

It didn’t take much for the recommended Repetier-Host software to become an inconvenience since it required hooking a laptop up to the CNC for every run. I know, first world problems. Luckily, there is also a Repetier-Server version available that can manage multiple machines, allow access through a jpgage, and run on a Raspberry Pi. Even though there is a RPI image for Repetier-Server, I used this as a chance to check out the BalenaOS for setting up and managing IoT devices.

Balena OS is a lightweight embedded OS designed for running docker containers. Your program can be setup to run inside of its own container where it will be isolated from other containers and the main OS. Each container running on the system can be updated without having to worry about it affecting the other containers. They’ve also streamlined the process of pushing an updated container to devices through their BalenaCloud platform. This makes updating as simple as pushing changes to your git repository.

Creating a docker image

The first thing we will need to do is create a Dockerfile which downloads, installs, and runs the Repetier-Server software.

1
2
3
4
5
6
7
8
9
FROM ubuntu:18.04

EXPOSE 3344

RUN groupadd -r intserial &&    groupadd -r ugpio

RUN apt-get update &&    apt-get install -y wget &&    wget http://download.repetier.com/files/server/debian-armhf/Repetier-Server-0.90.7-Linux.deb &&    dpkg -i Repetier-Server-0.90.7-Linux.deb

ENTRYPOINT [ "bash", "-c", "service RepetierServer start && tail -f /dev/null" ]

Let’s take a look at each section to better understand everything going on.

1
FROM ubuntu:18.04

We start with an ubuntu base image. Balena makes a Raspian base image but I ran in to dbus issues when trying to use it. If I was setting this up to run on production devices, I would definitely look into an ARM specific base image closer.

1
EXPOSE 3344

Repetier-Server is accessed through port 3344. This allows requests to the host on port 3344 to be directed to the container to be handled.

1
2
RUN groupadd -r intserial && \
    groupadd -r ugpio

Repetier-Server adds itself to a number of different user groups when it is installing. Most are available by default but these two must be created.

1
2
3
4
RUN apt-get update && \
   apt-get install -y wget && \
   wget http://download.repetier.com/files/server/debian-armhf/Repetier-Server-0.90.7-Linux.deb && \
   dpkg -i Repetier-Server-0.90.7-Linux.deb

These are the commands to actually download and install Repetier-Server. There will be a couple errors output while executing these commands.

1
2
3
4
5
/var/lib/dpkg/info/repetier-server.postinst: line 12: /etc/sudoers.d/repetierserver-RepetierInstaller: No such file or directory

* Starting Repetier-Server rsd
  start-stop-daemon: unable to alter nice level by -20 (Operation not permitted)
     ...fail!

The build process will pause right after these are output which looks like it has failed. Be patient and it will continue after a few seconds. Neither of these errors seemed like an issue within a docker container so I didn’t spend the time fixing them for now. The first is Repetier-Server giving itself higher privileges which aren’t really needed in a docker container. The second is the process giving itself higher priority when it’s pretty much the only process running already.

1
ENTRYPOINT [ "bash", "-c", "service RepetierServer start && tail -f /dev/null" ]

The last command tells the container to start the Repetier-Server process and then do nothing. I didn’t like adding the tail -f /dev/null but the container would constantly restart otherwise and this seems to be a common fix.

Getting your device image

The Balena team has done a great job of documenting how to use the Balena tools. I recommended looking over their getting started page for a quick overview and as an extra debugging resource.

I chose to us the resin-cli and work locally. It’s a good place to start and gain an understanding of what’s going on before starting to use the BalenaCloud platform. The resin-cli can be installed using the following command.

1
npm install --global --production --unsafe-perm resin-cli

We will need to download the base image for the Raspberry Pi 3 from the Balena image page.

Once downloaded, unzip the image and use the resin-cli to configure the image. Configuring the image is mainly adding your wifi information but there is an advanced section for setting the device’s name and persistent logging as well.

1
resin local configure <path to unzipped img>

Flashing your image

Next insert your micro sd card into your pc and run the resin command to flash the img. This process will wipe out any information currently on the sd card. Read the prompts carefully rather than just pressing enter. The resin cli will try to select the correct device but any time you’re writing over a drive you should double check things.

1
resin local flash <path to configured img>

There is one last step before removing the sd card. You will need to look at the partitions that were created while flashing the sd card. One will be called “resin-boot” that has a “config.txt” file one it. Mount this partition within your OS, open “config.txt”, and make sure you find the following 2 lines.

1
2
enable_uart=1
dtoverlay=pi3-disable-bt

Booting your device

These will enable the serial port on the RPI3. You can now eject the sd card from your computer and put the sd card in the rpi. You will want to wait ~30 seconds to allow the rpi to boot and configure itself. You can then scan for the device on your local network.

1
resin local scan

You will want to make note of either the host name or the ip of your device. You can use either of these values to remotely connect to your device.

In order to place your docker image on to your device, you will need to navigate to the directory containing your Dockerfile. You can push the Dockerfile to the device using the command.

1
resin local push <device ip or hostname> --source .

The device will now go through the process of building the docker image and launching a container.

Finishing up

Once the container finishes building, you can now navigate to the Repetier Server jpgage running on the device. Open a web browser and enter your device’s hostname or ip with :3344 at the end. You should be navigated to the Repetier Server jpgage for your device.

The last step is to connect your CNC or 3d Printer and plug it in to one of your RPI3’s USB slots. Once connected, Repetier Server has a pretty straight forward way of connecting a new machine. The one field to watch for is the port name for your USB serial connection. For my particular device it used /dev/ttyACM0 but this may very.

That’s it for running Repetier Server in a docker container with Balena OS. For me this setup is mostly experimental but I will be working switching over to a Raspberry Pi Zero W and connecting it to BalenaCloud for easy updates.

Here’s a short video doing a dry run of the CNC through the Repetier Server web page.

CNC dry run

Happy hacking everyone.