Light bar 2 API is a firmware solution that makes the Xiaomi Light Bar smart and connected through a RESTful API. Built on ESP32, it provides wireless control capabilities for your Xiaomi Light Bar via HTTP endpoints.
This project is based on the reverse engineering work by Lamperez and Benallen.
Thanks for your works!
Before setting up the project, ensure you have the following installed:
- Python 3 + pip
- VS Code with the following extensions:
- ESP-IDF framework 5.5
- Optional: Docker/docker-compose for running the devcontainer to avoid installing esp-idf on host
- ESP32 microcontroller
- NRF24L01 module transceiver
- Mi Computer Monitor Light Bar, model MJGJD01YL (without BLE/WiFi), the MJGJD02YL will not work
| nRF24 | ESP32 |
|---|---|
| VCC | 3V3 |
| GND | GND |
| CE | Pin 4 |
| CSN | Pin 5 |
| SCK | Pin 18 |
| MOSI (MO) | Pin 23 |
| MISO (M1) | Pin 19 |
The project uses a custom partition table tailored for persistent storage, application firmware, and static assets.
| Name | Type | SubType | Offset | Size | Size (KB) | Description |
|---|---|---|---|---|---|---|
nvs |
data | nvs | 0x9000 | 0x80000 | 512 KB | Non-volatile storage (NVS) |
factory |
app | factory | 0x90000 | 0x200000 | 2048 KB | Main application binary |
config |
data | spiffs | 0x290000 | 0x20000 | 128 KB | SPIFFS for JSON configuration files |
www |
data | spiffs | 0x2B0000 | 0x150000 | 1344 KB | SPIFFS for static assets (HTML, CSS) |
git clone https://github.com/Times-Z/light-bar-2-api.git
cd light-bar-2-api- Open VS Code and install the ESP-IDF extension
- Follow the setup instructions to configure the ESP32 environment
Configure the json with your SSID, password, api keys etc...
cp main/config/default.json main/config/config.jsonidf.py build
idf.py flash- Power on the ESP32
- The device will create an access point
Lightbar2apiwith password$tr0ngWifito configure the Wi-Fi network (default behavior if the application is not properly configured viaconfig.jsonor the wifi configured insn't available) - Use the serial monitor for debugging:
idf.py monitor- Embedded web server with HTTP endpoints
- Wi-Fi station (STA) mode support with auto-connect from
config.json - Captive portal for Wi-Fi access point (AP) mode
- JSON-based configuration file (
config.json) for boot-time settings - NVS-based persistent storage for credentials (fallback & persistence)
- Uptime tracking (seconds to days format)
- Lightweight JSON API for system status and configuration
- NTP sync (default => build date)
- X-API-Key based header protection for needed endpoint
- Scan and get the Xiaomi remote ID
- Show ESP32 logs from web UI
- Store the Xiaomi remote ID in the NVS storage
- [] Send commands to the bar
This project is licensed under the MIT License.
Contributions are welcome! Feel free to submit a pull request or open an issue for discussion.
Happy Coding! 😊


