Preview Image

MQTT LED Controller: A Python Web GUI for Your IoT Devices

Control ESP32 LED strips with Python, NiceGUI and MQTT: architecture, corrected Docker ports, configuration and troubleshooting.

MQTT LED Controller: A Python Web GUI for Your IoT Devices

A color picker is more useful than a terminal when you just want to change the lighting. My MQTT LED Controller UI gives my ESP32 LED strip client a browser-based control panel for switching LEDs and choosing colors.

The interface uses Python and NiceGUI. A Paho MQTT client handles messages between the application and the broker; the ESP32 receives commands and publishes its state back.

How the pieces fit together

1
Browser ↔ Python / NiceGUI ↔ MQTT broker ↔ ESP32 ↔ LED strip

The UI and the ESP32 must use the same broker, compatible topics, and the message format expected by the firmware. This is a companion application for my controller, rather than a universal MQTT dashboard.

  • On/off and color controls for the selected device.
  • State updates over MQTT, so the interface can react to device reports.
  • A device list for managing more than one controller.
  • Docker Compose setup including a Mosquitto broker.

Before you start

You need Git, Docker with Compose for the container route, and a controller running compatible firmware. The repository also includes dummy devices for UI testing; seeing a device in the list does not by itself prove that real hardware is connected.

These instructions reflect the repository checked in November 2026. It pins older application dependencies. Review the configuration and credentials before deploying it beyond a trusted development network.

Option 1: Docker Compose

1
2
git clone https://github.com/GitSoks/mqtt-led-controller-ui.git
cd mqtt-led-controller-ui

Before starting, review mqtt_led_controller_ui/settings.py and the broker configuration under mosquitto_mqtt_broker/config/. Replace the example credentials on both sides and configure your ESP32 to connect to the broker host.

1
2
3
docker compose up --build -d
docker compose ps
docker compose logs --tail=50 led_controller_ui mosquitto_mqtt_broker

The checked-in Compose file publishes the web interface on port 80, so open http://localhost/ on the Docker host, or http://<server-ip>/ from another machine. It publishes MQTT on port 1883. The GUI’s internal broker hostname, mqtt_broker, is for container-to-container communication; your ESP32 needs the server’s reachable IP address or hostname.

If port 80 is already occupied, change the UI service’s published port to 8080, keeping its target port at 80. Then use http://<server-ip>:8080/.

To stop the stack without deleting its named data volume:

1
docker compose down

Option 2: Local Python environment

Use Python 3.10 or newer and an existing MQTT broker. Create an isolated environment from the repository root:

1
2
3
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt

On Windows, activate it with .venv\Scripts\activate instead. Edit mqtt_led_controller_ui/settings.py before launching:

Setting What to change
BROKER_ADRESS Broker hostname or IP; the spelling is intentional and matches the source
BROKER_PORT Broker port, normally 1883 for plain MQTT
BROKER_USERNAME, BROKER_PASSWORD Credentials accepted by your broker
ADD_DUMMY_TEST_DEVICES Set to False when testing real device discovery
ENABLE_PERFORMANCE_TEST_BUTTON Set to False if you do not need the test control

The source currently calls ui.run(..., port=80). For a local development session, change that value in mqtt_led_controller_ui/main.py to 8080 so an ordinary user can bind the port, then run:

1
2
cd mqtt_led_controller_ui
python main.py

Starting from this directory also lets the application’s relative media paths resolve correctly. Open http://localhost:8080/ after making the port change.

Verify a complete round trip

  1. Check that the broker accepts both the UI and ESP32 connections.
  2. Disable dummy devices and confirm your actual controller appears.
  3. Toggle the selected device, then choose a color.
  4. Confirm the physical LEDs change and the device’s reported state returns to the UI.

If the page loads but nothing happens, inspect the container logs first. A wrong broker address, mismatched credentials, or incompatible firmware topics can leave the web interface working while device control fails.

Source code

The GitHub repository contains the application, Compose file, and broker configuration. For the setup details above, see the actual settings, entry point, and Compose configuration.

This post is licensed under CC BY-NC-SA 4.0 Deed by the author.