MrLeehs Blog

Recent Posts

Dockerize a Flask app with NGINX reverse proxy using Docker-Compose

This tutorial will show how to properly dockerize a web application written in Flask. I will use Docker-Compose to create two containers.

Blinking LEDs with Coroutines

I just made my first steps with the uasyncio module in Micropython and I'm impressed. Here is a small example how to use coroutines for letting all 3 LEDs on the Pyboard v1.1 blink with different intervals. The resulting code is unexpectedly short but also readable.

Project documentation templates for mkdocs with Cookiecutter

I will show how to create a mkdocs template with Cookiecutter that you can use everytime you create a new project documentation. We will also use the still new pipenv virtual environment and package manager to automatically install the needed Markdown plugins.

How to setup a dockerized Redis server on a Raspberry Pi

For an upcoming project I want to use microservices on my Raspberry Pi. This means multiple process will take care of individual tasks. To coordinate these processes they need to communicate with each other. A great way to implement this is using a Redis server. Redis is an open source (BSD licensed), in-memory data structure store and can be used as a database, cache and message broker. Since version 4.0 Redis supports ARM processors and gets tested against the Raspberry Pi.

How to use a Raspberry Pi to monitor your Wireless Traffic

Lately I visited my first Chaos Computer Congress (34C3) which was a really great event. I learned a lot about security and data privacy there. The result was that after the first day I found myself banning Amazon Echo from my living room. During the following days my suspicion towards smart home devices grew more and more. So I decided that it was time to find out which of my devices enjoy talking home and are sending data about me to the cloud. As all my smart home devices are connected via wifi I decided to monitor the wireless traffic of suspicious devices. A Raspberry Pi 3 which I had in spare should provide a wireless access point and bridge it to the ethernet port that goes straight to the router. This way the device under surveillance can talk home unaffected. But I can now monitor the traffic with a network monitoring tool like Wireshark.

Consistent image uploads with Flask-Admin, Flask-Uploads and automatic filename-hashing

Flask-Admin is a Flask extension that solves the boring problem of building an admin interface on top of an existing data model. With little effort, it lets you manage the data of your web application through a user-friendly interface. To make your data a little more interesting it is often useful to provide some images that can be integrated in slideshows, articles or even as an exchangeable logo of your application. While image uploads are indeed a very common task for web applications I found myself pondering frequently on how to realize a consistent integration in the Flask-Admin modelview system. Especially I wanted a solution that allowed me to upload images regardless of their filename and also handle duplicates graciously without breaking the association of my database entry to the referenced imagefile. So this article is about how to achieve consistent image file storage implemented in Flask-Admin by using the Flask-Uploads extension to automatically generate UUIDs as filenames and link them to a database entry.

Temperature measuring via 1-Wire

One of the first IoT use cases that comes in ones mind ist measuring the temperature of your environment. An easy and cost-efficient way is to use an 1-Wire bus sensor like the DS18S20. You can get this sensor for around 2,15€ and it is really easy to implement in your µC as there are a bunch of libraries for the 1-Wire protocol. So the first thing to do is put the sensor in a bread board and connect it to your WiPy2 breakout board. The pin assignment is simple. Connect Pin1 of the sensor to GND, Pin2 to G10 and Pin3 to 3.3V. That' s it.

WiPy2 Micropython - Getting started

Lately I proudly got hold of a WiPy2.0 board and this post is about how I got started with it, established a connection to my Wifi and made the WiPy to connect automatically on boot.

Remote GUI for Beaglebone Black with PyQt5 and X11 Forwarding

Lately I found a Beaglebone Black in my stock and had the idea to use it for some kind of fermentation control with a graphical user interface (GUI). For testing purposes I first wanted to run a small GUI on the Beaglebone via remote control (SSH). SSH has this great -X switch that enables X11 Forwarding. So I wanted to use this from my Mac to remote control the Qt GUI on my Beaglebone. Here is how I did it.

Create a desktop application with Flask, PyQt5 and cx_freeze

In recent months I really came to like Flask as a framework for creating websites and web applications. The usage of Jinja2 templates, HTML5 and Javascript to create good-looking and responsive user interfaces along with the Python language in the backend comes by naturally and on some point I asked myself why not to use Flask to create Desktop applications. The idea to use web technology for creating desktop applications is quite old and for other programming languages there exist some nice frameworks (e.g. Githubs Electron). However for Python there are not so many players around. So I decided to use the PyQt5 WebView widget. I have some experience with PyQt5 so this approach seemed the most natural to me. I wanted the application to become a stand alone executable. So I used cx_freeze here.

A Python Script for fast changes of network config on Windows

I wanted to be able to switch fast between different network configurations on my Windows development PC without using any kind of 3rd party software. So I had a quick look on Stackoverflow and found the beautiful wmi package. Windows Management Instrumentation (WMI) is Microsoft’s implementation of Web-Based Enterprise Management (WBEM), an industry initiative to provide a Common Information Model (CIM) for pretty much any information about a computer system. And the wmi package is a Python wrapper for it on top of pywin32.

Modal Forms with Flask

Modal dialogs are quite common in GUI programming. They help to focus the users attention on the task at hand but still outline the context of the given or needed information by keeping the parent object visible in the background. As I have been doing a lot of classic GUI programming with PyQt I like to use modal dialogs and it feels natural for me to use them as well in Flask Web Applications. Bootstrap provides a great and simple way to create a modal dialog which is just what we want. However things get a bit more complicated when it comes to dealing with forms in modals. It took me a while to figure out a solution I am comfy with and I want to describe my solution in the following.

How to create a Flask application container with Docker

A while ago I wrote a post about how to serve a Flask application on a webserver. Today I want to write about how to achieve this by using a docker container. Using a container for deploying web applications has the main advantage of shipping an isolated environment in a Black Box to its destination. So you don' t depend on the server operating system or the configuration. You don' t have to worry about the right version of Python being installed and so on. Also the whole shipping mechanism via Docker Hub works great. So let' s get moving.

Setting up a Debian VM with Vagrant on Windows

As a developer I endeavor to keep a consistent working environment on all of my computers. Meaning editing with VIM, version-controlling with GIT and using all the cool POSIX tools directly from the Terminal to do whatever. At home I use Mac OS X and for servers I use Debian. So working with the terminal is basically the same for both systems.

Image Uploads in Flask-Admin

In my last post Checking out: Flask-Admin extension I gave a short introduction to the Flask-Admin extension. I also built a small example to show how easy it is to get a basic admin interface for your data. But how does Flask-Admin work if we have more advanced requirements? For example what if we want to provide an image for each user? In this case we will have to expand our recent example by an Image model.

Flask-Admin Extension

In my recent projects I often ran into the important but boring task of building admin interfaces on top of data models. It is important because using an admin interface it is the preferred way to edit, add and delete information. It is boring because it basically means you have to create two interfaces dealing with exactly the same data: the layout of the website that is shown to public and the interface for data administration. Flask-Admin is an addon for the Flask microframework that takes care of the boring part. With little effort, it lets you manage your web service’s data through a user-friendly interface.

Accessing a Flask application in a subdirectory

Lately I wanted to test a new application before deployment and wanted to make it accessible via a subdirectory of my blog url. It doesn't sound like a great deal but I had some difficulties to accomplish it. To make my life easier in future and to help others facing the same challenge I wrote this Howto.

Flask Webserver Deployment part 4 - Nginx Proxy Server

This is the final part of my tutorial on Flask Server Deployment. In the last section we configured our Gunicorn WSGI server and controlled it via Supervisor. In this section we will place our WSGI server behind a Proxy server.

Flask Webserver Deployment part 3 - Gunicorn WSGI Server

This is Part 3 of my tutorial for Flask Webserver Deployment. In the last section we prepared our server for serving a Flask application. We created a small Flask test application and finally started up the Flask development server. In this part we will use a more production ready server called Gunicorn to run the application.

Flask Webserver Deployment part 1 - Host Provider

Hello World again. This is my second post and I'm going to write about the steps it took me to get my Flask Application deployed to a Webserver.

Flask Webserver Deployment part 2 - Development Server

This is Part 2 of my tutorial for Flask Webserver Deployment. In the last section we acquired our own personal Linux server. Now we want to get connected to it and run our first Flask Test Application.