Control your Bluetooth bulb through WiFi

Control your Bluetooth bulb through WiFi

Hi there, I am back with another interesting hack that you can apply at your home. You all love to party right? And with the increasing prices at the pubs, we have no option left but to party at home. Home parties are great. Lots of booze at cheap rate πŸ™‚ . To make home parties even greater I bought a Bluetooth smart bulb that could be controlled from my phone. As time passed I realized my so called smart bulb wasn’t smart enough. It kept on loosing connection. And whenever I tried to show off to my friends, my smart bulb refused to work. Something had to be done. I didn’t want to ruin my party (Yes I throw awesome home parties. You should visit my place sometime :p )

So I put on my thinking hat and finally figured out a solution: WiFi bulbs. With WiFi, the connection is much more reliable and easily accessible. Kids buy WiFi bulbs, legends make one πŸ˜€ This blog post is about how I controlled my Bluetooth Bulb over network through WiFi.

Modern Bluetooth Bulbs communicate with mobile using Bluetooth Low Energy (BLE) Protocol. So any device capable of communicating with BLE can talk to my bulb. Most of the laptops now ships with those specifications. And I had an old spare laptop that would just do that job. I just needed to figure out the syntax of communication so that I can send those packets from my laptop to light.

To do that I needed to intercept Bluetooth traffic from my device to bulb. That was tricky. Luckily android has a developer options through which you can dump Bluetooth packets in your device. To enable that option go to developer options, toggle “Enable Bluetooth HCI Snoop log”. Once you enable the option, connect your phone to the bulb and switch on the light once and then turn it off. This is needed because you need to dump the packets that are responsible for turning the light on and off. ( Later you can go deeper and work on changing the colors )
So till now this everything was sorted. I just needed to pull the log and analyze the dump. Apparently pulling the log file from device was a pain in the brain πŸ˜€ You have to install ADB (Android Debug Bridge), and search the file as because there is no specific location where the log file is generated. It varies from device to device.

But then I found a neat solution through which you can easily pull the files. Go to developer options. Take a bug report (Interactive Report). It generates a zip file that can be shared. Get that zip file and Voila! your log file will be there in that zip file (FS/data/misc/bluetooth/logs). Thank me later.

Now to understand in which format data is communicated and at what address, there is a handy application called NRF connect that breaks down every characteristics of BLE communication. Note down the address at which data is being written.

To analyze the log, open wireshark and load the log file. Those who have already done TCP/IP packets analysis, its a piece of cake for you. You just need to filter source mac and destination mac and check for write requests to the bulb at the specific address which you noted from NRF connect app. Note down the values that are being written.

So from the screenshot, the address is 0x002b and value is 0f0a0d000000000005000013ffff.

Information gathering part is done. Now time for some action. Boot up your Linux system. Turn your Bluetooth interface up by :

hciconfig hci0 up

Check your interface name by executing hciconfig. It is generally hci0. Scan for BLE devices by :

hcitool lescan

Don’t forget to turn the light on or else it won’t show up in the list. Note the MAC address of light. For BLE shell, execute :

gattool -I

Connect to the bulb by executing connect <mac address of bulb>. Now for the interesting part. Execute the following command in BLE shell:

char-write-req 0x002b 0f0a0d000000000005000013ffff

The syntax is char-write-req <address> <value>

Put the value for on and off accordingly. And you have successfully communicated with your light from a laptop.

You might be wondering, where did we loose the word WiFi in such a mess of BLUETOOTHs πŸ˜€ Haha… well as a web developer, I always try to figure out some web interface solutions for a problem. This one was no exception. If you can control a light from a terminal then you can as well control that from a web page. Just open port 80, host the files and bingo! you have a network access to your light in a locally accessible IP. I won’t get into details on how to set up a web page as it will make this post longer. I am attaching a screenshot of the page.

Wait! Where did YouTube come from? So while working with the light I also set up a WiFi speaker system with the help of YouTube TV. So that you don’t have to take the pain of plugging in that aux cable.

To Set up YouTube TV open youtube.com/tv in your laptop

1. Go to settings
2. Select pair with code and get a code. (If you are in home network, you don’t need a code)
3. Once you get a code open YouTube in your app and in the settings put that code.

Now you can play anything from your phone that will get streamed in your laptop. Plug a speaker with your laptop and you are good to go. Also you can plug in a projector with the laptop as per your requirement and stream YouTube videos all from your mobile to a projector.

The following diagram will make the design clear

You can now control light, music and video at the same time from your phone, no strings attached πŸ˜€ pretty cool huh!

You can take things further from here like mapping your local machine to a public IP so that you will be able to control your light from anywhere in the world. Also you could change the color of the light recognizing the beats of the music. The possibilities are only limited by your imagination πŸ™‚

For demonstration, you are always welcome to my place πŸ™‚

That’s all for today. Thanks for reading.

You may also like

Downloading your TV shows as soon as they are Aired

Downloading your TV shows as soon as they are Aired

So, the latest episode of your favourite TV Show has been Aired and the first thing you will be doing...

Bypass YouTube age restriction

Bypass YouTube age restriction

While browsingΒ YouTube, you might come across some videos that are inappropriate for some users and you can view them by...

Assign a static IP to your Android device.

Assign a static IP to your Android device.

When you are connected to a network, the router assigns an IP to your device. This is generally dynamic and...

Building a smart music system from scratch !

Building a smart music system from scratch !

Ever wondered if there could be a system that starts playing soothing music when you reach home after a hectic...

Back to Top