How to control a MagicBlue LED bulb with Linux

If you want to control your LED bulbs throught bluetooth, I recommend MagicBlue LED bulbs. Does not have an official API, but exists an unofficial on https://github.com/Betree/magicblue

First, I installed an old version of magicblue (gattlib based), but I'm going to tell you the steps if you need to solve it for a similar app.

sudo apt-get install python3-pip 
sudo pip3 install setuptools bluepy
git clone https://github.com/Betree/magicblue.git
cd magicblue
sudo python3.5 setup.py install 
sudo magicblueshell

ImportError: No module named 'gattlib'
pip3 install gattlib
/usr/bin/ld: cannot find -lboost_python-py34
    collect2: error: ld returned 1 exit status
    error: command 'x86_64-linux-gnu-g++' failed with exit status 1

pip3 download gattlib
tar xvzf ./gattlib-0.20150805.tar.gz
cd gattlib-0.20150805/
sed -ie 's/boost_python-py34/boost_python-py35/' setup.py
pip3 install .

sudo magicblueshell
list_devices

Name         Mac address 
----         ----------- 
LEDBLE-7C2789EE c4:bd:7c:27:89:ee

For the new version (bluepy based) these are the issues:

FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.5/dist-packages/bluepy-1.0.5-py3.5.egg/bluepy/bluepy-helper'

git clone https://github.com/IanHarvey/bluepy.git
cd bluepy
sudo python setup.py install 

If you run list_devices again, maybe you will get the following errror:

ERROR:magicblue.magicblueshell:Unexpected error with command "list_devices": [Errno 2] No such file or directory: '/usr/local/lib/python3.5/dist-packages/bluepy-1.0.5-py3.5.egg/bluepy/bluepy-helper'

To fix it, do the following steps to compile bluepy-helper:

cd "/usr/local/lib/python3.5/dist-packages/bluepy-1.0.5-py3.5.egg/bluepy/"    
sudo make

Now, execute again and search magicblue devices:

sudo magicblueshell
list_devices

Name         Mac address 
----         ----------- 
LEDBLE-7C2789EE c4:bd:7c:27:89:ee

If you like, you can do it in an easier way:

sudo pip3 install git+https://github.com/Betree/pyMagicBlue.git

Now, to change the color of your Magicblue LED bulb, just run it:

sudo magicblueshell -c 'set_color blue' -m c4:bd:7c:27:89:ee




Enjoy it!

Comments

Popular posts from this blog

How to fix Android when developer options are not available for this user

from: can't read /var/mail/ in Python scripts

Fix "Set scan parameters failed: Input/output error" on Ubuntu 16.04