Xiaomi Desk LED Lamp with a FOSS firmware

I needed a lamp on my table. I needed some backlight when I am working on my computer, and I needed a strong worklight when I am soldering and working on electronics. I found Xiaomi LED wifi lamp in my home town, of all the places. And, actually, that was the cheapest place I was able to find it anywhere, including the Internet.

I brought it home, and it was great. It looked great, it lit up the workplace evenly, and it was easy to control. As it was supposed to be able to be controllable from the wifi I set out to try that.

That was a pretty shitty experience. First I was not able to install the application from the app store and I had to side load it. Then the pairing did not work, than it started working but stopped again afterwards.

The wifi controlability was not really needed so at first I just ignored it.

After that I stumbled upon Torxgewinde’s github repo. He has made a FOSS firmware that basically replicates the functionality of the original firmware, but with the wifi functionality being done through http get requests.

So, after a couple of minutes of deliberating, the lamp was taken apart and I had wires soldered to the pcb. I was getting gibberish from the serial port, but that was ok. Default ESP8266 speed is something nonstandard.

Torxgewinde used arduino to build the project so that was what I installed. There were a couple libraries that the project depended on so I installed that also. I’ve built the project, uploaded the built code to the board (without backing up the original firmware), and nothing worked. Well I was getting something from the serial port, so something was alive, but that was it. Actually later I figured out the output I was getting was from the bootloader.

This was the first time I was working with the ESP8266, and it took me about a half a day to figure out that I should be using a bit of an older toolchain, and everything started working.

Afterwards I made some changes to the code. I’ve upgraded the ArduinoJson library to the 6.11 version. That was a major version upgrade and there were some interface changes, so It also took some code upgrades. I’ve upgraded the other libs, but it did not need any changes.

After that I’ve implemented some upgrades. I’ve added different ways of setting the light color and intensity.

And there was an interesting problem that was solved with input validation. You set the color hue and intensity by inputting the ratio of the warm and cold white, and the global intensity. There was a way to set the output of both channels (warm and cold leds) to be at full output, but when you did that, it pulled to much current from the power supply and it would reset the lamp.

With this project, there was another first that I had. All of the changes I did, I made pull requests and they were applied to the original repo. It was a pretty good feeling!