Awesome Open Source
Awesome Open Source


An alternative firmware for the Mijia Xiaomi Desk Lamp Build Status


After finding fvollmers project, it was possible to create this firmware. Thanks for the inspiration and the helpful details like GPIOs and pinouts.


  • This alternative firmware compiles with the Arduino IDE.
  • It provides a webserver and URLs for controlling the light.
  • The rotary knob reacts on single click and toggles between OFF and ON
  • Per default after flashing the firmware WiFi is OFF
  • Per default the lamp has WiFi switched off. Double-clicking the knob twice within two seconds toggles WiFi ON and OFF

Initial upload of firmware

The initial upload requires the following steps:

  1. Open the desk lamp. Three screws are hidden underneath the rubber. Slightly peel away the rubber and unfasten the screws.
  2. Then look for the PCB-A located below the rotary knob, it carries the ESP8266 module. Unfasten the screws of that PCB-A, pull off the knob gently and turn the PCB-A around. To protect the knob, I wrapped some electrical tape around it to prevent scratches and used pliers to pull it upwards, away from the PCB-A.
  3. Solder cables to RX, TX and GPIO0. GND is also required for programming, but depending on your programming cable this signal is easily accessible even when the PCB is put back in place. Soldering to the ESP8266 module will result in fragile connections. Because of that, I decided to provide cable support afterwards by applying hot-melt-glue, otherwise the connections would not last long when handled. A labeled picture certainly helps.
  4. Put back the PCB-A, fasten the screws.
  5. Attach a 3.3V USB to serial adapter cable. Connect cables GND to GND, cables Tx to Rx and cables Rx to Tx. If you want to check correct wiring, power up the lamp and use the serial-monitor for any activity. Most likely it will just print gibberish due to mismatched baudrate, but this is enough to see Rx and Tx should be wired correctly; if there is no activity when powering the lamp try swapping the Rx and Tx lines.
  6. Connect GPIO0 to GND. Keep it pulled low until firmware has uploaded from the Arduino IDE.
  7. Compile the firmware and upload from within the Arduino IDE.
  8. Unconnect GPIO0 from GND, power-cycle the lamp and it should dim-up. The serial monitor should inform you about the startup (115200, 8N1).

Flashing updates via WiFi

Once the firmware has uploaded initially, you can reupload through WiFi using the BASH script (assuming the desk-lamp got the IP adress

# ./

The stdout-messages should look as follows:

enableUpdates: 1
<META http-equiv="refresh" content="15;URL=/">Update Success! Rebooting...

Monitoring log-messages

To monitor the log messages, use the BASH script. It refreshes the log messages every second.


Upload files for the webserver

The internal webserver serves files from device-internal-flash-filesystem. To fill the internal flash-filesystem, the most convenient way is creating a subfolder data in the sketch-folder and upload with the provided BASH-file

Uploading all files from ./data to flash-filesystem:


Upload a single file file to flash-filesystem:

./ myfile 


To send commands to the desk lamp or read the state, the following HTTP-handlers are implemented:

  • Set color to 100% warmwhite:
  • Set color to 100% coldwhite:
  • Set color to 25% coldwhite and 25% warmwhite:
  • Set color to 30% coldwhite and 30% warmwhite:
  • Get color as JSON:
  • Get current state as JSON:
  • Get log messages:
  • Reset / Restart the lamp:
  • Retrieve the config as JSON (does not expose the WiFi credentials):
  • There are more URLs to flash the firmware and upload files for the webserver (namely: unlock, edit, format, update). To prevent unauthorized flashing of (malicious) firmware or webserver files at least a hardcoded password is required. If you worry about this password change it in the sourcedode and notice that HTTP does not encrypt it.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
c-plus-plus (19,020
arduino (769
webapp (279
esp8266 (270
wifi (202
firmware (160
xiaomi (81
led (36
lamp (25