This blog post is about the technologies I use for an IoT system in Docker containers: Node-RED, MariaDB, Mosquitto (MQTT broker) and Grafana which builds the backbone of many of my IoT projects.

How is my IoT system set up?

An IoT system, i.e. a complete machine in itself, which is able to measure, send, log, evaluate and ultimately react to various physical variables, needs various components. My ideas are often based on the same components. It starts with digital or analog sensors that are connected to an ESP 8266 microcontroller and are therefore responsible for perception. This can be a temperature sensor (e.g. BME280), a light barrier or a pH measuring chain for measuring the pH values of a liquid. The microcontroller uses the MQTT protocol to pass on the information via a radio network. The program for this is an MQTT broker called Mosquitto, for example. Mosquitto (and the associated (radio) network) correspond roughly to the central nervous system.

Mosquitto as central nervous system

Mosquitto is an open-source MQTT broker that enables reliable, scalable, and secure communication between IoT devices and services. MQTT (Message Queuing Telemetry Transport) is a widely used protocol for transferring IoT data, which was specially developed for use in poorly connected environments.

The information is passed through the nervous system to the brain, where it is processed according to certain logics. NodeRed takes over this task.

The brain

Node-RED is open source software that provides a visual programming interface for building flows. With Node-RED one can easily connect different IoT devices and services to create automation processes. It also allows you to collect, analyze and visualize data generated by various IoT sensors and devices.

Of course it is advantageous if you want to keep some information for later or if you want to remember what it was like at that time. This is where a database comes into play as a long-term memory. And Maria never forgets what you once tell her.

Long-term memory: MariaDB

MariaDB is an open source Relational Database Management System (RDBMS) developed as an alternative to MySQL. It is a powerful, scalable and reliable database that can be used for IoT applications.

A good friend of Maria’s is Grafana. Grafana can display data stored at MariaDB (or other databases) as graphs, charts or numeric values in a browser as a dashboard. So that you always know what’s going on.

Furthermore, NodeRed can also give instructions to muscles or to a microcontroller with a connected actuator via the central nervous system (MQTT). The actuator will often be a relay which then opens or closes the circuit to a motor. A pump can be controlled, a light can be switched on or off, a window can be opened, … .

Overall, Node-RED, MariaDB, Mosquitto, and Grafana are powerful and scalable technologies that together can provide a reliable and scalable IoT solution. Using Docker containers makes them easy to deploy and manage, making it easier to maintain and scale an IoT facility.

And how do you build the basic structure of an IoT system?

In my IoT system, these containers form the backbone and run on a Raspberry PI 4, which is connected to a separate WLAN together with various ESP 8266. Grafana tells me everything I need to know on a small display. With Docker you can put together the individual containers very easily and in a short time.

But since you often need the entire backbone.

Here’s a piece of DNA, or the blueprint:

DNA or Docker Compose

Doker Compose allows you to write a construction plan for one or more containers, which then only have to be rolled out if necessary. In this way, an IoT instance can be ready in a short time.

The DNA of my plant


version: "3.7"

services:
  mqtt:
    image: eclipse-mosquitto
    volumes:
      - /home/pi/docker/mqtt:/etc/mosquitto
    ports:
      - "1883:1883"
      - "9001:9001"
    restart: "unless-stopped"

  nodered:
    image: nodered/node-red
    volumes:
      - /home/pi/docker/nodered/data:/data
    restart: "unless-stopped"
    ports:
      - 1880:1880


  mariaDB:
    image: linuxserver/mariadb
    volumes:
      - /home/pi/docker/mariaDB:/config
    ports:
      - 3306:3306
    restart: "unless-stopped"
    environment:
      - PUID=1000
      - PGID=995
      - MYSQL_ROOT_PASSWORD:"SecretPassword"
      - TZ=Europe/Berlin

  phpmyadmin:
    image: phpmyadmin
    
    restart: "unless-stopped"
    ports:
      - 8080:80
    environment:
      - PMA_ARBITRARY=1


  grafana:
    image: grafana/grafana
    ports:
      - "3000:3000"
    restart: "unless-stopped"

This article represents the first in a series of articles based on the setup outlined above.