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

    This tutorial will show how to properly dockerize a web application written in Flask. I will use Docker-Compose to create two containers. The first one will run the Flask application using the WSGI server gunicorn. The second container will run a nginx reverse proxy. It will serve all static files much faster than the WSGI server could do it. This tutorial assumes you already have installed Docker and Docker-Compose. If not have a look at the installation instructions on Docker and Docker-Compose. Also you should have a running version of Python 3 on your system.

    Read more
  • Micropython: Using Coroutines for blinking LEDs Micropython

    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.

    import pyb
    import uasyncio as asyncio
    async def blink_led(led, interval_s):
        """Let the LED blink in the given interval."""
        while True:
            await asyncio.sleep(interval_s)
    led_red = pyb.LED(1)  # red led on the pyboard
    led_green = pyb.LED(2)  # green led on the pyboard
    led_yellow = pyb.LED(3)  # yellow led on the pyboard
    # get a new event loop
    loop = asyncio.get_event_loop()
    # create new tasks for each led
    loop.call_soon(blink_led(led_red, interval_s=0.5))
    loop.call_soon(blink_led(led_green, interval_s=1))
    loop.call_soon(blink_led(led_yellow, interval_s=2))
    # run all tasks

    For a comprehensive tutorial on Micropython async have a look at https://github.com/peterhinch/micropython-async.

  • Project documentation templates for mkdocs with Cookiecutter Python Markdown


    I am a really great fan of Markdown. This is mainly because it is one of the few Markup languages that produces clear, neat source files during the writing process as well as structured, good-looking websites after rendering. So it is not surprising that I have been using Markdown for project documentation for quite a while now. Normally project documentations tend to consist of more then one document. So there is this static website generator called mkdocs that generates a complete website out of multiple Markdown documents arranged in a directory structure. It can be enhanced by a number of plugins that make it much easier to create a layout of your liking. Gradually I developed a certain project structure with always the same Plugins installed and it showed that I had to do the same steps over and over again for each new project. I figured it would be great to use some kind of template system. Luckily I heard about Cookiecutter which is a command-line utility that creates projects from so-called "cookie cutters" which are basically project templates. Here 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.

    Read more
  • How to setup a dockerized Redis server on a Raspberry Pi Raspberry Pi Docker

    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.

    All microservices on the Raspberry will run as docker containers. Docker provides a method of packaging software to include not only your code, but also other components such as a full file system, system tools, services, and libraries. You can then run the software on multiple machines without a lot of setup. Each microservice is independent and it is very easy to manage or exchange certain services.

    The short tutorial assumes you already have a Raspberry Pi setup with Raspbian.

    Read more
  • How to use a Raspberry Pi to monitor your Wireless Traffic Raspberry Pi Security

    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.

    Read more
  • Consistent image uploads with Flask-Admin, Flask-Uploads and automatic filename-hashing Flask Python

    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.

    Read more
  • WiPy2 Micropython: Temperature measuring via 1-Wire Micropython

    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.


    Read more
  • WiPy2 Micropython: Getting started Micropython

    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.

    Read more
  • Remote GUI for Beaglebone Black with PyQt5 and X11 Forwarding Python Flask PyQt

    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.

    Read more
  • Create a desktop application with Flask, PyQt5 and cx_freeze Python Flask PyQt

    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.

    Read more