An alternative firmware for the Mijia Xiaomi Desk Lamp
An alternative firmware for the Mijia Xiaomi Desk Lamp
After finding fvollmers project, it was possible to create this firmware. Thanks for the inspiration and the helpful details like GPIOs and pinouts.
The initial upload requires the following steps:
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.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.Once the firmware has uploaded initially, you can reupload through WiFi using the BASH script (assuming the desk-lamp got the IP adress 192.168.2.99):
# ./flash.sh 192.168.2.99
The stdout-messages should look as follows:
./flash.sh 192.168.2.99
enableUpdates: 1
<META http-equiv="refresh" content="15;URL=/">Update Success! Rebooting...
To monitor the log messages, use the log.sh
BASH script. It refreshes the log messages every second.
./log.sh 192.168.22.99
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 upload.sh
.
Uploading all files from ./data
to flash-filesystem:
./upload_files.sh 192.168.2.99
Upload a single file file to flash-filesystem:
./upload_files.sh 192.168.2.99 myfile
To send commands to the desk lamp or read the state, the following HTTP-handlers are implemented:
http://192.168.2.99/color?ratio=1.0&brightness=1.0
http://192.168.2.99/color?ratio=0.0&brightness=1.0
http://192.168.2.99/color?ratio=0.5&brightness=0.5
http://192.168.5.18/split?cold=0.3&warm=0.3
http://192.168.2.99/color
http://192.168.2.99/all
http://192.168.2.99/log
http://192.168.2.99/reset
http://192.168.2.99/config.json
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.