Local ESP32 MQTT Broker

MQTT (Message Queuing Telemetry Transport) is a messaging protocol developed for IoT (Internet of Things) applications. It enables efficient data exchange between devices, even when bandwidth, energy, or computing power are limited.


MQTT uses the publish/subscribe model. A central MQTT broker mediates all messages:


A publisher sends a message with a specific topic, which can be understood here as a path.


Subscribers who have subscribed to this topic then receive the message.

Senders and recipients – publishers and subscribers – are completely decoupled, do not need to know each other, and do not need to be online at the same time.

MQTT is therefore a lean communication protocol for the reliable, simple, and flexible exchange of messages between devices – locally or via the Internet.

MQTT brokers are the central hub for communication via MQTT and can be located in the cloud or on an external server. This allows data to be sent and received from anywhere via the Internet – ideal for distributed IoT systems.


Local communication directly in the LAN/WLAN prevents delays caused by routing via external servers and is perfect for time-critical applications. Added to this is the security aspect, as data remains in the local network and full control over access (encryption (TLS), user rights, etc.) is maintained.

Cloud brokers can fail or stop providing services. A local broker continues to run stably as long as the system is switched on.


Therefore, there are many good reasons for using a local network with a local MQTT broker if requirements allow you to do without the Internet.

MQTT (Message Queuing Telemetry Transport) ist ein für IoT-Anwendungen (Internet of Things) entwickeltes Nachrichtenprotokoll. Es ermöglicht den effizienten Datenaustausch zwischen Geräten, auch wenn Bandbreite, Energie oder Rechenleistung begrenzt sind.

MQTT verwendet das Publish/Subscribe-Modell. Ein zentraler MQTT-Broker vermittelt alle Nachrichten:

Ein Publisher sendet eine Nachricht mit einem bestimmten Topic, welcher hier als Pfad verstanden werden kann.

Subscriber, die diesen Topic abonniert haben, erhalten dann die Nachricht

Sender und Empfänger – Publisher und Subscriber – sind komplett entkoppelt, müssen sich nicht kennen oder gleichzeitig online sein.

Also ist MQTT ein schlankes Kommunikationsprotokoll für das zuverlässige, einfache und flexible Austauschen von Nachrichten zwischen Geräten – lokal oder übers Internet.

MQTT-Broker sind die zentrale Schaltstelle bei der Kommunikation über MQTT und können sich in der Cloud oder auf einem externen Server befinden. Dadurch können Daten von überall über das Internet gesendet und empfangen werden – ideal für verteilte IoT-Systeme.

Lokale Kommunikation direkt im LAN/WLAN verhindert Verzögerungen durch das Routing über externe Server und ist perfekt für zeitkritische Anwendungen. Hinzu kommt der Sicherheitsaspekt, wenn Daten im lokalen Netzwerk bleiben und die volle Kontrolle über den Zugriff (Verschlüsselung (TLS), Benutzerrechte etc.) gegeben ist.

Cloud-Broker können ausfallen oder Dienste einstellen. Ein lokaler Broker läuft stabil weiter, solange das System eingeschaltet ist.

Es spricht also einiges für ein lokales Netzwerk mit einem lokalen MQTT-Broker, wenn es die Anforderungen erlauben, auf das Internet zu verzichten.


An MQTT broker on a Raspberry Pi, for example, can serve as a local MQTT broker. There are numerous installation instructions for this, e.g., at https://www.elektronik-kompendium.de/sites/raspberry-pi/2709041.htm.

Josef Bernhardt has shown that an ESP32 can already serve as an MQTT broker and has provided the necessary software. In the repository https://github.com/ckuehnel/ESP32-MQTT-Broker, you will find the relevant software, which can be installed on the ESP32 via the Arduino IDE.

An ESP32 MQTT broker can be installed on different hardware. The following images show an ESP32 DevKit as an example of a module and an XIAO W5500 Ethernet adapter as an example of a simple complete device.

Ein MQTT-Broker auf einem Raspberry Pi z.B. kann als lokaler MQTT-Broker dienen. Hierzu gibt es zahlreiche Installationsanleitungen, wie z.B. unter https://www.elektronik-kompendium.de/sites/raspberry-pi/2709041.htm.

Josef Bernhardt hat gezeigt, dass bereits ein ESP32 als MQTT-Broker dienen kann und die erforderliche Software bereitgestellt. Im Repository https://github.com/ckuehnel/ESP32-MQTT-Broker finden Sie die betreffenden Software, die über die Arduino IDE auf dem ESP32 installiert werden kann.

Ein ESP32-MQTT-Broker kann auf unterschiedlicher Hardware installiert werden. Die folgenden Bilder zeigen ein ESP32 DevKit als Beispiel für ein Modul und einen XIAO W5500 Ethernet Adapter als Beispiel für ein einfaches Komplettgerät.



ESP32 DevKit
XIAO W5500 Ethernet Adapter

For an ESP32 module equipped with an ESP32 Wrover module, the following configuration of the Arduino IDE can be assumed.

Für ein mit einem ESP32 Wrover Modul ausgestattetes ESP32-Modul ist von der folgenden Konfiguration der Arduino IDE auszugehen.

The following image shows the output of the broker via the console after starting and after connecting to a client.

Das folgende Bild zeigt die Ausgaben des Brokers über die Console nach dem Start und nach Verbindung mit einem Client.

The outputs show the assigned IP address 192.168.1.251 and port 1883 via which you can reach the ESP32 MQTT Broker to query the status.

After activating the MQTT client (on the mobile phone), the client paho4939… is connected and the subscription to the topic test is recognised.

If a message is received with the topic test, it is forwarded to the subscriber(s) and consequently also received again in the MQTT client.


The following screenshots of the status and MQTT client show these activities in equal measure.

Die Ausgaben zeigen die zugewiesene IP-Adresse 192.168.1.251 und Port 1883 über die Sie den ESP32 MQTT Broker erreichen können, um den Status abzufragen.

Nach Aktivierung des MQTT Clients (auf dem Smartphone) wird der Client paho4939… und die Subscription des Topics test erkannt.

Wird eine Nachricht mit dem Topic test empfangen, dann wird diese an den/die Subscriber weitergeleitet und demzufolge auch im MQTT-Client wieder empfangen.

Die folgenden Screenshots von Status und MQTT-Client zeigen diese Aktivitäten gleichermassen.

If implemented on an ESP32 with a display, the convenience of the broker can be extended somewhat. Here is the implementation on an M5StickCPlus2 as an example. The local IP and the relevant port for dialling in, as well as the topic and content of the last message received, can then be output.

Bei einer Implementierung auf einem ESP32 mit Display lässt sich der Komfort des Brokers noch etwas erweitern. Hier ist die Implementierung auf einem M5StickCPlus2 als Beispiel. Es können dann die lokale IP und der betreffende Port für die Einwahl sowie Topic und Content der letzten empfangenen Nachricht ausgegeben werden.

The XIAO W5500 Ethernet Adapter is a compact PoE development board with the XIAO ESP32S3 Plus soldered on. With an integrated, isolated MQ7813T120-based PoE module and TPS563201-based power conversion, this board addresses both the power and network connectivity challenges, ensuring stable and uninterrupted data transmission. This solution provides a reliable and efficient alternative to wireless connections, making it ideal for applications that demand consistent performance.


The ESP32-S3 itself offers an alternative option for Wi-Fi connectivity.

The repository contains implementations of ESP32-based MQTT Brokers for all the mentioned controllers.

Der XIAO W5500 Ethernet Adapter ist ein kompaktes PoE-Entwicklungsboard mit aufgelötetem XIAO ESP32S3 Plus. Mit einem integrierten, isolierten PoE-Modul auf Basis des MQ7813T120 und einem Power Converter auf Basis des TPS563201 löst dieses Board sowohl die Herausforderungen der Stromversorgung als auch der Netzwerkkonnektivität und gewährleistet eine stabile und unterbrechungsfreie Datenübertragung. Diese Lösung bietet eine zuverlässige und effiziente Alternative zu drahtlosen Verbindungen und ist somit ideal für Anwendungen, die eine konstante Leistung erfordern.

Der ESP32-S3 selbst bietet eine alternative Option für die WLAN-Konnektivität.

Das Repository enthält Implementierungen von ESP32-basierten MQTT-Brokern für alle genannten Controller.


2025-08-09/CK

Veröffentlicht von ckuehnel

Mein aktuelles Profil ist unter https://www.linkedin.com/in/ckuehnel zu finden.

Hinterlasse einen Kommentar