Lese-Ansicht

MQTT-Broker Mosquitto als Docker Container installieren

Ein MQTT-Broker ist die Schnittstelle zwischen vielen IoT-Sensoren und Geräten, die Sensordaten auswerten oder Aktoren steuern. Das MQTT-Protokoll ist offen und sehr weit verbreitet. Es findet in der Industrie Anwendungen, ist aber auch in Smart Homes ist MQTT weit verbreitet.
MQTT ist ein sehr schlankes und schnelles Protokoll. Es wird in Anwendungen mit niedriger Bandbreite gerne angewendet.

MQTT funktioniert, grob gesagt, folgendermaßen: IoT-Geräte können Nachrichten versenden, die von anderen IoT-Geräten empfangen werden. Die Vermittlungsstelle ist ein sogenannter MQTT-Broker. Dieser empfängt die Nachrichten von den Clients. Gleichzeitig können diese Nachrichten von anderen Clients abonniert werden. Die Nachrichten werden in sog. Topics eingestuft, die hierarchisch angeordnet sind, z.B. Wohnzimmer/Klima/Luftfeuchtigkeit.

Home Assistant, oder ein anderer Client, kann diesen Topic abonnieren und den Nachrichteninhalt („Payload„) auswerten (z.B. 65%).

Home Assistant OS vs. Home Assistant Container

In Home Assistant OS und Supervisor gibt es ein Addon, das einen MQTT-Broker installiert. Das ist sehr einfach, komfortabel und funktioniert wohl recht zurverlässig. In den Installationsarten Home Assistant Container und Core gibt es diese Möglichkeit nicht. Hier muss man manuell einen MQTT-Broker aufsetzen.

In diesem Artikel beschäftige ich mich damit, wie man den MQTT-Brocker Mosquitto über Docker installiert. Anschließend zeige ich, wie man die Konfigurationsdatei gestaltet und eine Verbindung zu Home Assistant herstellt. Das Ergebnis ist dann ungefähr so, als hätte man das Addon installiert. Los gehts!

Schritt für Schritt: MQTT-Broker Mosquitto mit Docker installieren

Als MQTT-Broker verwende ich die weit verbreitete Software Mosquitto von Eclipse. Dieser wird auch von Home Assistant bevorzugt und ist derjenige Broker, den das Addon installieren würde.
Für diese Anleitung wird vorausgesetzt, dass Docker bereits installiert ist und eine SSH-Verbindung zum Server hergestellt werden kann.

Schritt 1: Zunächst erstellen wir ein paar Ordner, die wir später benötigen. Mosquitto wird später so konfiguriert, dass in diese Ordner alle wichtigen Dateien abgelegt werden. Dadurch kann man auf dem Filesystem des Servers Mosquitto konfigurieren und beobachten.

$ mkdir mosquitto
$ mkdir mosquitto/config 
$ mkdir mosquitto/data 
$ mkdir mosquitto/log

Schritt 2: Nun wird die Konfigurationsdatei für Mosquitto erstellt. Über diese Datei kann man das Verhalten von Mosquitto steuern.

$ nano config/mosquitto.conf
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
log_dest stdout
password_file /mosquitto/config/mosquitto.passwd
allow_anonymous false
listener 1883

Schritt 3: Mit dem folgenden Befehl lädt man sich das aktuelle Image von Eclipse Mosquitto auf den Server.

$ docker pull eclipse-mosquitto

Schritt 4: Mit dem folgenden Befehl wird der Docker-Container gestartet. Das ist der Schlüsselmoment, jetzt muss alles klappen.

$ docker run -it -p 1883:1883 -p 9001:9001 --name mosquitto -v /home/pi/mosquitto/config:/mosquitto/config -v /home/pi/mosquitto/data:/mosquitto/data -v /home/pi/mosquitto/log:/mosquitto/log eclipse-mosquitt

Die Flags bedeuten hierbei folgendes:

  • -p 1883:1883 Der genannte Port ist die Standardeinstellung für MQTT. Alles was auf diesen Port am Server ankommt, wird in den Mosquitto-Container geleitet.
  • -p 9001:9001 Über diesen Port laufen die Websocket-Anwendungen. Falls das nicht benötigt wird, kann man das weg lassen
  • name mosquitto Über diesen kurzen Namen können wir den Docker-Container steuern
  • -v <filesystem-Pfad>:<Container-Pfad> Die in Schritt 1 erstellten Ordner werden in den Container eingebunden

Wer lieber Docker Compose verwendet, trägt diesen Eintrag in seine *.yaml ein:

services:
    eclipse-mosquitto:
        stdin_open: true
        tty: true
        ports:
            - 1883:1883
            - 9001:9001
        restart: unless-stopped
        container_name: mosquitto
        volumes:
            - /home/pi/mosquitto/config:/mosquitto/config
            - /home/pi/mosquitto/data:/mosquitto/data
            - /home/pi/mosquitto/log:/mosquitto/log
        image: eclipse-mosquitto

Schritt 5: Checken, ob der Container ordnungsgemäß läuft. In der folgenden Liste sollte eine Zeile mit dem Mosquitto-Docker auftauchen. Dieser sollte außerdem „up“ sein. Falls nicht, nochmal versuchen den Container zu starten und kontrollieren, ob er läuft.

$ docker container ls -a
CONTAINER ID   IMAGE          COMMAND   CREATED        STATUS        PORTS    NAMES
xxxxxxxxx   eclipse-mosquitto "/init"   3 minutes ago   Up 2 minutes  [...]   mosquitto

Schritt 6: Sehr gut, der Container läuft. Es wird dringend empfohlen, den MQTT-Broker so abzusichern, dass nur angemeldete User darauf zugreifen können. Das ist ja schon in Schritt 2 in die Konfigurationsdatei geschrieben worden. Mit dem folgenden Befehl melden wir uns in der Shell innerhalb des Containers an und erstellen einen Benutzer. In diesem Beispiel mosquitto. Im Anschluss an diesen Befehl wird man zweimal gebeten, das Passwort für den User festzulegen. Ist das geschafft, läuft der MQTT-Broker auf dem Server. Herzlichen Glückwunsch!

$ docker exec -it sh // öffnet die Shell innerhalb des Dockers
mosquitto_passwd -c /mosquitto/config/mosquitto.passwd mosquitto

Optional Schritt 7: Den MQTT-Broker bindet man in Home Assistant ein, indem man auf EinstellungenGeräte und Dienste+ Integration hinzufügen klickt. Im Suchfenster nach „MQTT“ suchen und die Zugangsdaten eingeben.
Die Server-Adresse findet man übrigens am schnellsten über ifconfig heraus.

The post MQTT-Broker Mosquitto als Docker Container installieren first appeared on bejonet - Linux | Smart Home | Technik.

  •  

Bastelspaß mit Jean - Die ersten Schritte mit dem Raspberry Pi Pico und vielen Sensoren

💾

Heute testet Jean den Raspberry Pi Pico W aus und hat ein ganzes Bastelset für unzählige Stunden an die Hand bekommen. Packen wir es gemeinsam aus und versuchen, die erste Herausforderung zu meistern.
Wenn Du das Video unterstützen willst, dann gib bitte eine Bewertung ab, und schreibe einen Kommentar. Vielen Dank!


Terminal Befehle:
-------------------------------------

sudo apt install thonny


Links:
-------------------------------------

Raspberry Pi Pico Advanced Kit: https://www.elecrow.com/raspberry-pi-pico-advanced-kit-with-pico-board-32-modules-and-32-detailed-projects-lessons.html (Unbezahlte Werbung)
Linux-Guides Merch*: https://linux-guides.myspreadshop.de/
Professioneller Linux Support*: https://www.linuxguides.de/linux-support/
Linux-Arbeitsplatz für KMU & Einzelpersonen*: https://www.linuxguides.de/linux-arbeitsplatz/
Linux Mint Kurs für Anwender*: https://www.linuxguides.de/kurs-linux-mint-fur-anwender/
Offizielle Webseite: https://www.linuxguides.de
Forum: https://forum.linuxguides.de/
Unterstützen: http://unterstuetzen.linuxguides.de
Mastodon: https://mastodon.social/@LinuxGuides
X: https://twitter.com/LinuxGuides
Instagram: https://www.instagram.com/linuxguides/
Kontakt: https://www.linuxguides.de/kontakt/

Haftungsausschluss:
-------------------------------------
Das Video dient lediglich zu Informationszwecken. Wir übernehmen keinerlei Haftung für in diesem Video gezeigte und / oder erklärte Handlungen. Es entsteht in keinem Moment Anspruch auf Schadensersatz oder ähnliches.

*) Werbung
  •  

Mozilla veröffentlicht Firefox Klar 122 für Apple iOS

Firefox Klar ist ein spezialisierter Privatsphäre-Browser von Mozilla. Mit Firefox Klar 122 für Apple iOS steht nun ein Update bereit.

Download Mozilla Firefox Klar für Apple iOS

Die Neuerungen von Firefox Klar 122 für Apple iOS

Mozilla hat Firefox Klar 122 (internationaler Name: Firefox Focus 122) für Apple iOS veröffentlicht. Die neue Version steht im Apple App Store zum Download bereit.

Bei Firefox Klar 122 für Apple iOS handelt es sich um ein Wartungs-Update, welches ausschließlich Verbesserungen unter der Haube bringt.

Der Beitrag Mozilla veröffentlicht Firefox Klar 122 für Apple iOS erschien zuerst auf soeren-hentzschel.at.

  •  

Linux Desktop wie Windows oder macOS – so passe ich Gnome und Cinnamon an

Viele von euch haben mich oft gefragt, wie ich meine Desktops anpasse, wenn sie meine Anpassungen in den Videos sehen. Aus diesem Grund präsentiere ich heute ein etwas anderes Format, in dem ich euch zeige, wie ich meine Desktops gestalte. Kurze Zusammenfassung der Ausgangslage: Dies ist eine Fortsetzung meines Beitrags von 2020 über die Anpassung...

Der Beitrag Linux Desktop wie Windows oder macOS – so passe ich Gnome und Cinnamon an erschien zuerst auf MichlFranken.

  •  

Valves Proton Version 8.0-5

Proton von Valve ist in der Version 8.05 erschienen. Proton ist eine auf Wine basierende quelloffene Software, mit dem es möglich ist, Spiele, die normalerweise nur unter Windows gespielt werden können, auch unter Linux zu spielen.

  •  

Brave Leo – KI-Browserassistent nun mit Mixtral per Standard

Die Desktop-Version von Brave wurde auf Version 1.62 aktualisiert. Ab sofort benutzt der Browser Mixtral 8x7B als Standard-Language Model (LLM) im eigenen KI-Browserassistenten Leo. Mixtral 8x7B ist ein Open-Source-LLM, das von Mistral AI im vergangenen Dezember veröffentlicht wurde. Es ist schnell und dank der hohen Leistung hat es sich schnell verbreitet. Ferner haben die Entwickler die Benutzerfreundlichkeit von Leo verbessert, indem sie das Onboarding, die Kontextsteuerung, die Formatierung von Eingaben und Antworten und die allgemeine Benutzeroberfläche verbessert haben. Mixtral ab […]

Der Beitrag Brave Leo – KI-Browserassistent nun mit Mixtral per Standard ist von bitblokes.de.

  •  

LibreOffice Getting Started Guide 7.6 ist verfügbar

Der Getting Started Guide von LibreOffice wurde aktualisiert. Ab sofort gibt es Version 7.6. In der neuesten Versionen werden auch Funktionen behandelt, die für LibreOffice 7.6 spezifisch sind. Das Handbuch richtet sich an alle, die einen Schnellstart mit LibreOffice 7.6 benötigen. Im Buch werden Writer (Textverarbeitung), Calc (Tabellenkalkulation), Impress (Präsentationen), Draw (Vektorzeichnungen), Math (Gleichungseditor) und Base (Datenbank) vorgestellt. Du kannst den Leitfaden von der Dokumentations-Website sowie aus dem Bücherregal herunterladen. Du kannst den Getting Started Guide 7.6 als PDF oder […]

Der Beitrag LibreOffice Getting Started Guide 7.6 ist verfügbar ist von bitblokes.de.

  •  

Meet Jannes and Aaron, YH4F 2023 participants

Meet Jannes and Aaron, YH4F 2023 participants

Find out more about the Youth Hacking 4 Freedom participants of the 2023 edition. We are starting this series talking with Jannes and Aaron: both worked on projects related to school education, and it is particularly interesting to see how these two projects approached different aspects with a similar spirit.

Aaron and Jannes are two German students, from North Westphalia and near Hamburg, respectively. They are 18 and 19 years old, and during Youth Hacking 4 Freedom 2023 they created School Hub and Nanoly+Shigoto, two projects that they intend to continue to develop.

School Hub is an unified platform for school information both for students and teachers. It seeks to help the average student to use data more quickly, while being an alternative to similar proprietary apps. Nanoly and Shigoto are designed to have a more efficient and tailored environment for managing homework and study material. In this interview, we will learn more about them!

FSFE: Hi to Aaron and Jannes! Before diving into the details, can you introduce yourselves?

Aaron: I’m Aaron. I’m 18 years old and I come from North Westphalia, in Germany. I’ve been interested in computers from a very early age and it’s currently what I do as a hobby. It’s my passion.

Jannes: My name is Jannes. I’m from Germany and I live near Hamburg. I’m currently 19 years old and I’m in the 13th grade, so this is my last year of school. I like programming. I also do sports: I like cycling a lot, and I practice Aikido in my free time.

FSFE: Could you introduce us to the project you developed for YH4F 2023?

Aaron: My project is called “School Hub”, it aims to be a unified platform for school information, both for students and teachers.

School Hub’s “news” section (Neuigkeiten)

Very early in my time trying out Flutter [coding framework], I was incredibly interested and passionate about it. At the same time, the current software my school uses is proprietary and it’s crap. So I asked my school: “Hey, wouldn’t it be cool if our school had a mobile app with these features and resources? I think it would be cool!” The idea was shot down for privacy reasons or because they did’t want to get involved.

That’s what made me think: “I need an app that I can open in the morning and I don’t have to sign in every morning; where I can see instantly for me which lessons are cancelled, substituted or otherwise if something special going on”. Nowadays we use Microsoft Teams, but all the data is communicated through chats: it’s not really stored anywhere properly. So the main point of the app is to take all the data it can collect, and present it in a nice way.

School Hub’s “substitutions” (Vertretungen) section

Jannes: I developed two sibling projects: Nanoly, a file manager focused for school usage, and Shigoto, a to-do list manager. By integrating them, my purpose was to provide students with a dashboard to manage their school work.

I’m working on my laptop most of the time, and I needed some sort of organization, as well as a tool for writing homework. I had very specific needs and use cases in mind, such as opening files with custom key-bindings, touch support, annotating PDFs, and other things. So I started building the UI and then writing the code for it. I learned a lot of new things along the way!

Nanoly’s main page

My main idea was to reduce the number of windows I have open on my screen in order to be more productive. I haven’t quite achieved this, because I decided to develop two parallel projects. But at least both concepts fit very well on one screen, and I don’t need anything else except the application that’s open to edit files, for example.

An example of the Shigoto dashboard

FSFE: Not any kind of project, your projects are Free Software! How did you get in touch with the movement?

Jannes: I first got into free software during the first covid lockdown. A friend convinced me to switch to Linux and invited me into a group chat with people, who all work/study in the IT sector. I joined their video calls and learned a lot from them about Linux, self-hosting, and other great free and open source software. During the same period, I also got into programming, and participated in some competitions. One of the people from the chat group told me about the YH4F competition, where I then learned how to make my own software into Free Software.

Aaron: My family like to joke about being careful to give me a screwdriver, because otherwise I would disassemble all the devices in the house. I have been tinkering with computers since I was little. As I got older, I played around with it. I experimented with programming, trying out different kinds of software. And eventually I wrote one by my own.

At some point I became curious about installing Ubuntu. So I did. Later, I tried several different distributions. I switched off Windows completely. And I appreciate that my operating system doesn’t nag me all the time.

FSFE: You developed your software during YH4F 2023, where you also had the chance to meet other young developers as well as more senior Free Software contributors. How was this experience?

Aaron: One thing I really enjoyed about the competition was the generous amount of time compared to my previous involvement in events or competitions. Most of the time, I have participated in hackathons where I only had a couple of days at most. It is just enough for a really small and light proof of concept. By putting more time and energy into my own project, I was able to make it much better. I also enjoyed the frequent meetings we had, as well as some guest presentations from some prominent people. It’s always nice to see how people do their things, which is something I don’t get to see very often.

Jannes: There was quite a lot I learned! By participating also to the 2022 edition, it was such a long time that I invested into putting both competitions together, three projects in different areas. I learnt a bit about those areas. Just a little bit about the whole context, but a lot for me. I was able to help improve my coding skills. In terms of the competition itself, it was really great. There was a chat room, there were the monthly calls and it was super easy to interact with the other participants, which was very fun. I always felt particularly taken care of by the organizers, because we always had a way of contacting them to get some help if we needed it. The monthly calls were great to stay up to date and keep in touch with the others.

FSFE: The competition has finished, but life goes on. What are the future plans both for your project and for you?

Jannes: First of all, I want to finish school and apply to the University of Hamburg. I hope to be accepted. Between the end of school and the start of the first semester there are about 21 weeks that I have to fill somehow. During this time, I really want to push my personal projects, because I still have a lot of them on my to-do list. I also want to try and get a small job where I can work in a team with others, hopefully coding, or maybe software testing.

Aaron: Once I have a bit more free time and less stress around me, I can definitely see myself working on this project and seeing if I can make it more functional, ideally making it a little companion. Apart from the app, I really hope that I can continue with my studies. At the same time, I hope to be able to continue coding and developing free applications as a hobby, because that’s what I enjoy doing.

FSFE: Thank you Jannes and Aaron. We wish you a great future and a lot of success with your projects!

The new edition of Youth Hacking 4 Freedom has just started its coding period! Participants registration are still open, so you can still take part in the 2024 edition. Check out the YH4F webiste to find out all the details about this competition!

Support FSFE

  •  
❌