This will just be and outline of how I wrote a small program to control a lifx light bulb using nodejs.
The lifx documentation for talking to bulbs over lan is really good. They have some good examples and go over how to send messages and format them. I ran into some trouble with how to deal with endianess but I imagine if I knew a bit about binary it would be straightforward to follow the documentation and building out my own custom packets.
However, luckily someone else has already gone to the trouble doing all that and wrote a library for node!
This was a bit of a pain to start with as I used the discover option first. The idea was that discover would find all the light bulbs on the network that talked with the lifx protocol but I was unable to find any.
I then tried doing the createDevice option which requires the ip address and mac address of the light bulb. I checked through my router and found both of these things and created a device programmatically. This didn't work and I had no idea why. I opened up the udp port 56700 on my server and even used nmap to make sure the port was open on the light bulb.
The light bulb was definitely functional because my iphone was able to communicate to it with the Home app. I thought maybe there was something wrong with my machine so I tried using WSL which also didn't work. Throughout this, I digged into the library itself and could see the messages that were getting sent out and everything looked fine.
I downloaed the python library to see if maybe the node library was just out of date. The python library had a update this year so that was a good sign.
The python code worked! I then printed out the message that get's sent in python and compared it to what the node one was printing and there was just one tiny difference. The mac address in node was off by 1! I double checked my router and it was definitely showing a mac address that was 1 off from the one python was showing.
I looked this up online and found that newer lightbulbs have an issue where their mac address is off by one and its something we need to take care of. This isn't a bug but a feature for partners apparently.
Not sure why but I also found out the mac address is the serial number that is printed on the light bulb and after checking that I found that python was definitely getting the correct mac whereas node was not.
This was probably something that the python library was handling where it would check for the firmware version and then subtract the mac address by 1 to make everything work. The node library was probably not doing this.
For now I simply hardcoded the correct mac address and ip address into my little program to control the lifx light bulb.
Besides this one issue, everything else is working perfectly and was a breeze. Now I have my own little app running that I can use to turn on, turn off or change the color of the light bulb. The home app on my phone is much better and it worked right out of the box but I like that I made my own crummyier version anyway.