Transform your Xiaomi light bar into a smart, networked device with REST API
Light bar 2 API is an open-source firmware solution for the Xiaomi Light Bar (MJGJD01YL) that enables complete wireless control via a RESTful API. Built on ESP32 with an NRF24L01 transceiver
![]() |
![]() |
![]() |
![]() |
This project builds upon the excellent reverse engineering work by:
- Prerequisites
- Hardware Setup
- Installation
- Configuration
- API Documentation
- Features
- Technical Details
- Contributing
- License
The project includes a pre-configured devcontainer with everything pre-installed:
- Python 3.12
- ESP-IDF 5.5+
- ESP32 toolchain
- VS Code extensions
- Build tools
Simply clone and open:
git clone https://github.com/Times-Z/light-bar-2-api.git
code light-bar-2-api
# Click "Reopen in Container" when promptedAll dependencies are automatically available inside the container \o/
If you prefer not to use devcontainer, install manually:
| Tool | Version | Purpose |
|---|---|---|
| Python | 3.12+ | Build system dependency |
| ESP-IDF | 5.5+ | ESP32 development framework |
Then configure ESP-IDF following the official guide
| Component | Model | Notes |
|---|---|---|
| Microcontroller | ESP32 (WROOM-32E) | Tested development board |
| Radio module | NRF24L01+PA+LNA | Tested 2.4GHz transceiver |
| Smart light bar | MJGJD01YL | Xiaomi model (no BLE/WiFi) |
Compatibility note: MJGJD02YL is not compatible since this model is already connected
┌─────────────┐ ┌──────────┐
│ NRF24 │───────────────│ ESP32 │
├─────────────┤ ├──────────┤
│ VCC ────────────────────→ 3V3 │
│ GND ────────────────────→ GND │
│ CE ────────────────────→ GPIO 4 │
│ CSN ────────────────────→ GPIO 5 │
│ SCK ────────────────────→ GPIO 18 │
│ MOSI ────────────────────→ GPIO 23 │
│ MISO ────────────────────→ GPIO 19 │
└─────────────┘ └──────────┘
| NRF24 Pin | Function | ESP32 Pin |
|---|---|---|
| VCC | Power | 3V3 |
| GND | Ground | GND |
| CE | Chip Enable | GPIO 4 |
| CSN | Chip Select | GPIO 5 |
| SCK | SPI Clock | GPIO 18 |
| MOSI (M0) | Data Out | GPIO 23 |
| MISO (M1) | Data In | GPIO 19 |
The firmware uses a custom partition scheme optimized for storage and performance:
| Partition | Type | SubType | Offset | Size | Purpose |
|---|---|---|---|---|---|
nvs |
data | nvs | 0x9000 | 512 KB | Configuration & credentials |
factory |
app | factory | 0x90000 | 2048 KB | Main firmware binary |
config |
data | spiffs | 0x290000 | 128 KB | JSON settings files |
www |
data | spiffs | 0x2B0000 | 1344 KB | Web interface assets |
git clone https://github.com/Times-Z/light-bar-2-api.git
cd light-bar-2-apiOption A: Using VS code extension
- Install the ESP-IDF extension in VS Code
- Follow the extension's setup wizard
- Select ESP-IDF v5.5+
Option B: Using devcontainer
No setup needed! The devcontainer handles everything
Create your config file:
cp main/config/default.json main/config/config.jsonEdit main/config/config.json:
{
"wifi_ssid": "Your_WiFi_Network",
"wifi_password": "Your_WiFi_Password",
"api_key": "your_secure_api_key",
"ntp_server": "pool.ntp.org",
"xiaomi_remote_id": "00000000" # <==if you already have it, however a endpoint of the API help you to get it
}Note: This file is used only on first boot. Afterward, configuration persists in NVS
Once the device boots:
- Connect to wifi or access the captive portal
- Open the web dashboard
- Configure settings through the UI
- Changes are saved automatically to NVS
If WiFi credentials are missing or invalid:
- SSID:
Lightbar2api - Password:
$tr0ngWifi - Portal: Auto-opens on compatible devices (iOS/Android), otherwise go to
http://10.0.1.1
idf.py buildidf.py flashidf.py monitorNote: All of this commands can be used at the same time, eg : idf.py build flash monitor
Complete API endpoints are documented in the Swagger/OpenAPI specification.
- REST API with HTTP endpoints
- WiFi Access Point (AP) mode with captive portal
- WiFi Station (STA) mode with auto-connect
- JSON configuration files
- Persistent NVS storage (credentials & settings)
- System uptime tracking
- API key authentication (X-API-Key header)
- NTP time synchronization
- Log streaming via web UI
- Xiaomi remote ID scanning & storage
- Xiaomi power on/off control
- Additional light commands (color, brightness, effects)
- Web interface improvements
The nRF24 module uses whitening to ensure reliable radio communication:
Why is it important?
- Clock recovery: Ensures receiver stays synchronized
- DC balancing: Prevents frequency offset
- Signal quality: Reduces electromagnetic interference
How it works:
- LFSR (Linear Feedback Shift Register) generates pseudo-random bits
- XOR operation scrambles the payload with the random sequence
- Receiver applies the same algorithm with the same seed to recover data
Implementation in this project:
The whitening is applied in nrf24_build_xiaomi_frame as the final step before transmission, scrambling the entire 18-byte frame while maintaining protocol integrity
This project is licensed under the MIT License - see the LICENSE file for details
- Check the Swagger API documentation for endpoint details
- Found a bug? Open an issue
- Have questions? Start a discussion
Made with ❤️
Star us on GitHub if you find this project useful!



