Better Programming

Advice for programmers.

Follow publication

Member-only story

How To Build a FastApi Server to Control a Raspberry Pi

Simon Hawe
Better Programming
Published in
9 min readOct 31, 2019

Taken from https://www.heise.de/ratgeber/Docker-auf-dem-Raspberry-Pi-einrichten-4269052.html

Recently, a friend of mine asked me if I can help him build a graphical user interface that allows him to easily control a couple of valves using a Raspberry Pi. Apart from that, he also wanted to log a couple of things in a database.

My answer was:

“Sounds great! Let’s build a small web server that serves a webpage as the GUI and, together with a MongoDB database, runs in a Docker-compose environment on your Raspberry Pi.”

Here, I want to show you what I have done to get all the bold points working on the Raspberry Pi (Rpi). I assume you already know what Docker and Docker Compose are. If not, take your time and read up on Docker and Docker Compose.

Are you done with that? Let’s get started.

Setting Up Docker and Docker Compose

First of all, why Docker and Docker Compose?

For me, as soon as I build an application that relies on dependencies being installed on the target machine, I use Docker. This avoids potential headaches and eventually avoids “But it runs on my machine” issues.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Simon Hawe
Simon Hawe

Written by Simon Hawe

Tech and programming enthusiast working at Joyn mainly focusing on data sciene, machine learning, data engineering, and python coding.

Write a response

Hi Simon! This was an awesome tutorial!
However, a few of the dependencies are out of date. I started having a few issues with installing poetry and particularly with cryptography. I just wanted to give a heads up for anyone working on this. Later…

Thank you for this great tutorial.
I am getting an error when running
$docker-compose up
I am using a RaspberryPi4B with Raspbian installed. Any guidance on this error? Thank you in advance.
This is the original error that I get, and the Dockerfile used: