Giter VIP home page Giter VIP logo

magicblue's Introduction

MagicBlue Bulb

MagicBlue - Cheap bluetooth bulbs

Documentation Status

The Magic Bulb is, as far as I know, the cheapest bluetooth RGB light bulb on the market : you can get it for as low as ~8€/9$ on sites like Gearbest. It works pretty good and comes with mobile apps.

Unfortunately I haven't found any API or documentation for it, which is why I started this project.

There are multiple versions of the bulb, some of them may need development to be compatible with this project. If you have a different bulb version you can try to sniff bluetooth communications. Reverse-engineering information and pull requests are more than welcome 😺

Bulb Version
v6 v7 v8 v9 v10
Status ☑️ ☑️ ☑️
☑️ ☑️

Installation

HomeAssistant

If you want to use this project with HomeAssistant you'll need to install magicblue as described below then use the component available here: https://github.com/Betree/homeassistant-magicblue

MagicBlue is not compatible with Windows.

Linux

You must use python 3+ and have a proper Bluetooth 4.0 interface installed on your machine.

  • Prerequisite

    • Debian: sudo apt-get install libglib2.0-dev
    • Fedora: sudo dnf install glib2-devel
  • Install

    sudo pip3 install magicblue

    Library needs elevated permissions to use Bluetooth features. You can either run as root (required for magicblueshell), or give hcitool special capabilities (see this link)

Known errors

  • Bluepy not compiled (very common)

If you get an error like No such file or directory: '/usr/local/lib/python3.4/dist-packages/bluepy/bluepy-helper' or ERROR:magicblue.magicblueshell:Unexpected error with command "ls": Helper exited: this is a known bug in bluepy that sometimes doesn't get compiled when installed from Pypi. You can fix it by compiling the helper yourself : Go to the lib folder (usually /usr/local/lib/python3.5/dist-packages/bluepy-1.1.2-py3.5.egg/bluepy/ but could be different, especially if you're using a virtual env) and run sudo make (make should be enought for a virtual env).

More info: IanHarvey/bluepy#158

  • Other errors

If you run into problems during devices listing or connect, try to follow this procedure to ensure your Bluetooth interface works correctly : How to use manually with Gatttool page

Usage

Python API

Check the API documentation

From shell

Script must be run as root.

You can always specify which bluetooth adapter (default: hci0) you want to use by specifying it with the -a option.

Using the interactive shell

Just launch magicblueshell as root user :

$ sudo magicblueshell
Magic Blue interactive shell v0.3.0
Type "help" for a list of available commands
> help
 ----------------------------
| List of available commands |
 ----------------------------
COMMAND         PARAMETERS                    DETAILS
-------         ----------                    -------
help                                          Show this help
list_devices                                  List Bluetooth LE devices in range
ls              //                            //
list_effects                                  List available effects
connect         mac_address or ID             Connect to light bulb
disconnect                                    Disconnect from current light bulb
set_color       name or hexadecimal value     Change bulb's color
set_warm_light  intensity[0.0-1.0]            Set warm light
set_effect      effect_name speed[1-20]       Set an effect
turn            on|off                        Turn on / off the bulb
read            name|device_info|date_time    Read device_info/datetime from the bulb
exit                                          Exit the script
> ls
Listing Bluetooth LE devices in range for 5 minutes.Press CTRL+C to stop searching.
ID    Name                           Mac address 
--    ----                           ----------- 
1     LEDBLE-1D433903                c7:17:1d:43:39:03
^C

> connect 1
INFO:magicblue.magicblueshell:Connected
> set_color red
> exit
Bye !

Passing command as an option

Script can also be used by command line (for example to include it in custom shell scripts):

usage: magicblueshell [-h] [-l LIST_COMMANDS] [-c COMMAND] [-m MAC_ADDRESS]
                      [-a BLUETOOTH_ADAPTER] [-b BULB_VERSION]

Python tool to control MagicBlue bulbs over Bluetooth

optional arguments:
  -h, --help            show this help message and exit
  -l LIST_COMMANDS, --list_commands LIST_COMMANDS
                        List available commands
  -c COMMAND, --command COMMAND
                        Command to execute
  -m MAC_ADDRESS, --mac_address MAC_ADDRESS
                        Device mac address. Must be set if command given in -c
                        needs you to be connected
  -a BLUETOOTH_ADAPTER, --bluetooth_adapter BLUETOOTH_ADAPTER
                        Bluetooth adapter name as listed by hciconfig
  -b BULB_VERSION, --bulb-version BULB_VERSION
                        Bulb version as displayed in the official app

So if you want to change the color of bulb with mac address "C7:17:1D:43:39:03", just run :

sudo magicblueshell -c 'set_color red' -m C7:17:1D:43:39:03

Contributing

To contribute to this repo, start with CONTRIBUTING.md then check open issues

The protocol isn't fully retro-engineered but Characteristics list page and How to use manually with Gatttool page should give you enough details to start working on your own implementation if you need to port this for another language / platform. On the research/bluetooth branch you'll also find capture of bluetooth packets exchanged between Android and the bulb (open hci_capture.log with Wireshark).

magicblue's People

Contributors

betree avatar biggestt avatar don41382 avatar mouth4war avatar ronesim avatar stevenlooman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

magicblue's Issues

question: other lights

I'm almost done implementing an other bulb, the functions are of the same but other byte arrays and a little other stuff. For a later pull request, do you prefer a new ....lib.py file so that the repo becomes a more of a python bulbblue package or trying smashing everything into one?

I still have decoding the read response packages and the timer functions.

API Usage

When using magicblue as an API, how can we avoid using the default address type PUBLIC?

Magic Blue Version 10

I have a bulb version 10 and I wasn't able to connect it ("Failed to connect to peripheral f8:1d:78:60:2a:5a, addr type: random"). I have found that addr_type should be public so I added the version 10 in the "if" statement.

17580204_1514292525279968_1326844116_n

[Errno 2] No such file or directory: '/usr/local/lib/python3.4/dist-packages/bluepy/bluepy-helper'

Hi Betree,

I'm having some problems connecting to my bulbs (V8) with the software (the GATT tool works fine)
this is my error....

sudo magicblueshell -c 'set_color red' -m F2:F1:09:E6:DE:78
Traceback (most recent call last):
File "/usr/local/bin/magicblueshell", line 11, in
load_entry_point('magicblue==0.2.2', 'console_scripts', 'magicblueshell')()
File "/usr/local/lib/python3.4/dist-packages/magicblue/magicblueshell.py", line 246, in main
shell.cmd_connect([params.mac_address])
File "/usr/local/lib/python3.4/dist-packages/magicblue/magicblueshell.py", line 133, in cmd_connect
self._magic_blue.connect(self.bluetooth_adapter)
File "/usr/local/lib/python3.4/dist-packages/magicblue/magicbluelib.py", line 49, in connect
bluetooth_adapter_nr)
File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 318, in init
self.connect(deviceAddr, addrType, iface)
File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 353, in connect
self._startHelper()
File "/usr/local/lib/python3.4/dist-packages/bluepy/btle.py", line 210, in _startHelper
universal_newlines=True)
File "/usr/lib/python3.4/subprocess.py", line 859, in init
restore_signals, start_new_session)
File "/usr/lib/python3.4/subprocess.py", line 1457, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.4/dist-packages/bluepy/bluepy-helper'

The original code worked fine this error comes from the latest code (0.2.2), any ideas?

UnboundLocalError: local variable 'addr_type' referenced before assignment

Hi Betree,

I'm having some problems connecting to my bulbs (V8)

pi@raspberrypi:~ $ sudo magicblueshell -c 'set_color red' -m e7:34:44:5d:f7:f3
Traceback (most recent call last):
File "/usr/local/bin/magicblueshell", line 9, in
load_entry_point('magicblue==0.3.0', 'console_scripts', 'magicblueshell')()
File "/usr/local/lib/python3.4/dist-packages/magicblue/magicblueshell.py", line 271, in main
shell.cmd_connect([params.mac_address])
File "/usr/local/lib/python3.4/dist-packages/magicblue/magicblueshell.py", line 144, in cmd_connect
addr_type=addr_type)
UnboundLocalError: local variable 'addr_type' referenced before assignment

Incompatibility with V8

Bulb version 8 seems to be incompatible at the moment.
What we know :

  • It uses a random address type
  • Both handles 0x0b (used in v9) and 0x0c (used in v7) are not responding.

(See #7)

Add support for functions (strobe, colors crossfade...etc)

The MagicBlue app has a tab for a number of special functions, such as a strobe and a given color crossfade. Fortunelaty, these keep repeating after started. Unfortunately, the bulb only recognizes a static set, so we can't use this to crossfade specific colors.

To set one of these cycles, you can craft a handle as following:

[bb] - RUN PRESET PROGRAM. A code that tells the bulb to start a program
[..] - PROGRAM TYPE. A 2 digit hex that tells what program to run. See the list below
[..] - SPEED. A 2 digit hex from 01 and up that sets the speed for the program
[44] - Uncertain, seems static. Can be changed but does not change bulb reaction
[0x] - Uncertain, first digit is static. Can be changed but does not change bulb reaction
[xxxxxx] - Uncertain, seems random, could be a time stamp. Can be changed but does not change bulb reaction.

A sample: char-write-req 0x000c BB2603440A150722 will run a program that fades the bulb from off to red and back again.

Some PROGRAM TYPEs:

25: Seven color cross fade
26: Red gradual change
27: Green gradual change
28: Blue gradual change
29: Yellow gradual change
2a: Cyan gradual change
2b: Purple gradual change
2c: White gradual change
2d: Red, Green cross fade
2e: Red blue cross fade
2f: Green blue cross fade
30: Seven color stobe flash
31: Red strobe flash
32: Green strobe flash
33: Blue strobe flash
34: Yellow strobe flash
35: Cyan strobe flash
36: Purple strobe flash
37: White strobe flash
38: Seven color jumping change

SPEED

01 - fastest
20 - very slow (and goes slower still)

Cannot connect from shell

Hello,
I can use the shell app to connect to my lightbulb by listing the BLE devices and using connect 1 (or whatever idx) and the issueing set_color and the rest of command successfully. However, I cannot use the one liner to connect directly to a device and run a command.
The error it get is (I replaced the actual MAC addres for MAC_ADD):

pi@raspberrypi:~ $ sudo magicblueshell -m [MAC_ADD] -c 'set_color red'

Traceback (most recent call last):
File "/usr/local/bin/magicblueshell", line 11, in
sys.exit(main())
File "/usr/local/lib/python3.5/dist-packages/magicblue/magicblueshell.py", line 335, in main
shell.cmd_connect([params.mac_address])
File "/usr/local/lib/python3.5/dist-packages/magicblue/magicblueshell.py", line 173, in cmd_connect
magic_blue.connect(self.bluetooth_adapter)
File "/usr/local/lib/python3.5/dist-packages/magicblue/magicbluelib.py", line 139, in connect
bluetooth_adapter_nr)
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 353, in init
self._connect(deviceAddr, addrType, iface)
File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 402, in _connect
"Failed to connect to peripheral %s, addr type: %s" % (addr, addrType))
bluepy.btle.BTLEException: Failed to connect to peripheral [MAC_ADD], addr type: random

Any clue to make this work properly?? Thank you!

MagicBlue interactive shell enhancement with python-prompt-toolkit

Though the interactive shell is not the central part of this project, it's still useful for debugging or to quickly send commands.

Using python-prompt-toolkit could make it easier to use with features like auto-completion and commands history without putting too much effort into it.

Any contribution on this subject would be appreciated, maybe some of you don't want to see too many dependencies in this app ? Also if you have any experience using python-prompt-toolkit or a similar library feedbacks are welcome.

Off-topic
Developing this feature could be a good introduction to later create an interactive shell to control HomeAssistant from the terminal.

Version 6 compatibility

Why version 6 is not compatible?
I try to connect to it with gattool, but it doesn't connect:

sudo gatttool -t random -b EA:9C:0F:A6:A0:22 -I
[EA:9C:0F:A6:A0:22][LE]> connect
Attempting to connect to EA:9C:0F:A6:A0:22

Does it have an incompatibility with gattool library or something else?

Can't install magicblue!

I get this error when I try to install magicblue and I use python 3 and trying to install it on a Linux Mint:

~ $ sudo pip install git+https://github.com/Betree/pyMagicBlue.git
The directory '/home/user/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/user/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting git+https://github.com/Betree/pyMagicBlue.git
Cloning https://github.com/Betree/pyMagicBlue.git to /tmp/pip-9ISemw-build
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-9ISemw-build/setup.py", line 2, in
from magicblue import version
File "magicblue/init.py", line 8, in
from magicblue.magicbluelib import MagicBlue
File "magicblue/magicbluelib.py", line 12, in
import bluepy.btle
ImportError: No module named bluepy.btle

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-9ISemw-build/

Add support for time schedules

The (Android) app allows you to set schedules. Making the library (more) complete, it would be a nice to have. Low priority though!

Keep current color when changing brightness

The color is set to white when bulb.turn_on(BRIGHTNESS) is called. And the brightness is set to 100% when calling bulb.set_color([R, G, B]).

I haven't looked into the MagicBlue's BLE characteristic, so I'm not sure if this is easy to accomplish.

Some question

Betree, do these leds make a "mesh-network" so that they communicated peer-to-peer between the leds and then to the controller? Or do they all just simply connect to a controller? Do they have a separate bridge or no?

How much range do you get out of them?

Multiple bulbs setup

This question is often asked, how many bulbs can we handle at the same time ? There's no theoretical limit in this library, but maybe in bluepy ?

Any feedback on the subject would be welcome. I've personally ordered two more bulbs so I'll be able to check that in a few weeks.

Installation Issue

Hi there,

First of all thanks for all the hard work and I am sorry to come here to bother you with some probably very basic questions! I want to have my Raspberry control my Magic Blue bulbs (with a vocal assistant) and so far I have only managed to control the bulbs manually with Gatttool. I am not really experienced to say the least but you got to start somewhere I guess.

During the installation I am facing the following error message:

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-Dp955h-build/

I have looked the error up and tried pretty much everything mentioned on StackOverflow.

EDIT: Managed to install, I was missing BluePy... BUT now I have another issue

ubuntu@ubuntu:~$ sudo magicblueshell
Magic Blue interactive shell v0.2.2
Type "help" for a list of available commands
help
ERROR:magicblue.magicblueshell:Unexpected error with command "": '_Helper' object has no attribute 'strip'

Ok, nevermind I had to type all commands with quotes "[COMMAND]" (i.e "help" / "set_warm_light 1.0" ect)

Thank you and sorry for the utter waste of time 😄

Tkinter GUI

it's a very very simple prototype (in fact, i declare the use of my bulb's mac in the first declaration) but i think the use of Tkinter could be very useful to implement!

from tkinter import *
from magicblue import MagicBlue

#CHANGE THE BULB MAC HERE
bulb_mac_address = 'F8:1D:78:60:8E:0F'
bulb = MagicBlue(bulb_mac_address, 10) # Replace 9 by whatever your version is (default: 7)
bulb.connect()

def switch():
	global first
	if first:
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
		inf=bulb.get_device_info()
	if inf["on"]:
		bulb.turn_off()
	else:
		bulb.turn_on()
	
def change_red(re):
	global first
	if first:
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
	color=map(int,(r.get(),g.get(),b.get()))
	bulb.set_color(color)

def change_green(gr):
	global first
	if first:
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
	color=map(int,(r.get(),g.get(),b.get()))
	bulb.set_color(color)

def change_blue(bl):
	global first
	if first:
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
	color=map(int,(r.get(),g.get(),b.get()))
	bulb.set_color(color)
	
def change_bright(br):
	global first
	if first:
		first = False
		return
	try:
		inf=bulb.get_device_info()
	except:
		bulb.connect()
	bulb.set_warm_light(bright.get()/255.0)	
	
	
	
w = Tk()	
	
#Models

r=IntVar()
g=IntVar()
b=IntVar()
bright=IntVar()

#First Check
inf=bulb.get_device_info()
r.set(inf["r"])
g.set(inf["g"])
b.set(inf["b"])
bright.set(inf["brightness"])
first=True

#Power Button

switch=Button(w,text="On / Off",command=switch)
switch.pack()

#First Frame

color_frame=Frame(w)
color_frame.pack()

#RGB

rgb_frame=Frame(color_frame,bd=10)
rgb_frame.grid(row=0,column=0)

red=Scale(rgb_frame, variable = r,orient=HORIZONTAL,to = 255, command = change_red, resolution = 5)
Label(rgb_frame,text="Red").pack()
red.pack()

green=Scale(rgb_frame, variable = g,orient=HORIZONTAL,to = 255, command = change_green, resolution = 5)
Label(rgb_frame,text="Green").pack()
green.pack()

blue=Scale(rgb_frame, variable = b , orient = HORIZONTAL , to = 255, command = change_blue, resolution = 5)
Label(rgb_frame,text="Blue").pack()
blue.pack()

#Bright

bright_frame=Frame(color_frame,bd=10)
bright_frame.grid(row=0,column=1)

bright=Scale(bright_frame, variable = bright , orient = VERTICAL ,from_ = 255, to = 0	, command = change_bright, resolution = -5)
Label(bright_frame,text="Brightness").pack()
bright.pack()



w.mainloop()

bulb.disconnect()

it looks like this for now:
image

loss of connection after 10-15 minutes

hi,
I am super grateful for Your work, it made my work sooooo much easier, but:
I wrote script which continuously controls state of a bulb according to outside data.
To do this, it needs to connect to bulb every few minutes, update it's color and disconnect.
Everything works fine for first 10-15 minutes. after that script does not connect to the bulb. sometimes it gives "bluetooth stack (comerr)" error.

Anyone has any idea how to solve this problem?

Issues using magic blue

Hi there

I was able to successfully install magic blue, however when I try to use it on the command line I get the following error -

any idea what the below means and if there is a fix for it? I did install bluepy on pip3 before installing magicblue.

sudo magicblueshell -c 'set_color blue' -m c1:ea:56:7a:35:9d

Traceback (most recent call last):
File "/usr/bin/magicblueshell", line 11, in
load_entry_point('magicblue==0.6.0', 'console_scripts', 'magicblueshell')()
File "/usr/lib/python3.6/site-packages/magicblue/magicblueshell.py", line 335, in main
shell.cmd_connect([params.mac_address])
File "/usr/lib/python3.6/site-packages/magicblue/magicblueshell.py", line 173, in cmd_connect
magic_blue.connect(self.bluetooth_adapter)
File "/usr/lib/python3.6/site-packages/magicblue/magicbluelib.py", line 139, in connect
bluetooth_adapter_nr)
File "/usr/lib/python3.6/site-packages/bluepy/btle.py", line 353, in init
self._connect(deviceAddr, addrType, iface)
File "/usr/lib/python3.6/site-packages/bluepy/btle.py", line 402, in _connect
"Failed to connect to peripheral %s, addr type: %s" % (addr, addrType))
bluepy.btle.BTLEException: Failed to connect to peripheral c1:ea:56:7a:35:9d,random, addr type: random

Install and run magicblue in Raspbian Stretch (kernel version 4.9) - SOLVED!

Install and run magicblue in Raspbian Stretch (kernel version 4.9) - SOLVED!

Hi folks,

Probably some of you have dealt with this issue already, others maybe no. Magicblue was running nice and smooth in the old Raspbian version (Jessie), however if you decided to upgrade your OS and want to install it, you will find some difficulties.

_sudo pip3 install magicblue
Collecting magicblue
  Using cached magicblue-0.5.0.tar.gz
Collecting bluepy==1.1.2 (from magicblue)
  **Could not find a version that satisfies the requirement bluepy==1.1.2 (from magicblue)** (from versions: 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1.0, 1.1.1, 1.1.4)
No matching distribution found for bluepy==1.1.2 (from magicblue)_

Installing bluepy manually it will install the latest version, bluepy==1.1.4, which is not valid neither for installing magicblue!

I found bluepy==1.1.2 package (https://pypi.python.org/packages/f1/fa/4830ec2ab95baa0201151bf18d5c031d94c520bd05ffdf692573a5261fe3/bluepy-1.1.2.tar.gz).

Check before if you have another version installed:

_$ pip3 show bluepy
Name: bluepy
Version: 1.1.4
Summary: Python module for interfacing with BLE devices through Bluez
Home-page: https://github.com/IanHarvey/bluepy
Author: Ian Harvey
Author-email: [email protected]
License: UNKNOWN
Location: /usr/local/lib/python3.5/dist-packages
Requires:_ 

Uninstall this version and install the version needed:
$ sudo pip3 uninstall bluepy==1.1.4
………..
~/Downloads/bluepy-1.1.2 $ sudo python setup.py install
………..

Check again the bluepy version:

_~/Downloads/bluepy-1.1.2 $ pip3 show bluepy
Name: bluepy
Version: 1.1.2
Summary: Python module for interfacing with BLE devices through Bluez
Home-page: https://github.com/IanHarvey/bluepy
Author: Ian Harvey
Author-email: [email protected]
License: UNKNOWN
Location: /usr/local/lib/python3.5/dist-packages
Requires:_ 

Now you shouldn’t have any problems for installing the magicblue app:

$ _sudo pip3 install magicblue
Collecting magicblue
  Using cached magicblue-0.5.0.tar.gz
Requirement already satisfied: bluepy==1.1.2 in /usr/local/lib/python3.5/dist-packages (from magicblue)
Collecting webcolors (from magicblue)
  Downloading webcolors-1.7.tar.gz
Building wheels for collected packages: magicblue, webcolors
  Running setup.py bdist_wheel for magicblue ... done
  Stored in directory: /root/.cache/pip/wheels/b1/0e/86/32ddc8557ac629da596beedcd947fdc33229ac7533b29ba93b
  Running setup.py bdist_wheel for webcolors ... done
  Stored in directory: /root/.cache/pip/wheels/4a/bb/ba/464319914f0bfb826beb0955bbb29d7188a18368ea226a758d
Successfully built magicblue webcolors
Installing collected packages: webcolors, magicblue
Successfully installed magicblue-0.5.0 webcolors-1.7

$ sudo magicblueshell 
Magic Blue interactive shell v0.5.0
Type "help" for a list of available commands
> list_devices
Listing Bluetooth LE devices in range for 300 seconds. Press CTRL+C to abort searching.
ID    Name                           Mac address 
--    ----                           -----------_ 

I hope this help somebody ;-D

Enhancing magicblue, moving to pygatt from bluepy?

Hi there,

First of all, great work with with magicblue! I was trying to integrate it with HomeAssistant, per your request, but ran into a few problems.

Wanting to know more about this bulb, I started digging a bit more, such as looking at traffic dumps: found on the research-branch and this article.

After learning more about BTLE and playing around with bluepy and pygatt, I am now able to do things, such as read the state of the lamp (color, brightness, on/off, etc.) Also, I think I am able to remove the need to specify the bulb-version (although I am not sure, I only have V10 bulbs.)

The downside is, though, that I was not able to read the state of the bulb using bluepy. I only got it to work with pygatt. The mechanism works by sending a command and then receiving a notification with data. While pygatt nicely handles the notification by calling a provided callback, I see no callbacks being called in bluepy.

I would like to improve magicblue, and using pygatt instead of bluepy would be the first move. Are you willing to merge a pull request which does this? The PR will include other finding/enhancements as well, of course. I will try to keep the existing API in tact/compatible.

magicblueshell crashes after firing the second command on a raspberry pi

After starting magicblueshell, connecting to my Magic Blue Bulb and firing the second command, magiblueshell hangs for a while and stops without any further output.

Hardware / Software
Raspberry PI Model B Revision 2.0 256 MB

pi@raspberrypi:~ $ python --version
Python 3.4.2

pi@raspberrypi:~ $ lsusb
Bus 001 Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)

Execution

pi@raspberrypi:~ $ sudo magicblueshell
Magic Blue interactive shell v0.1
Type "help" to see what you can do
> connect DE:0C:59:91:F3:81
INFO:magicblue.magicblueshell:Connected : True
> set_warm_light 0.1
> set_warm_light 0.5
*** WAITING FOR 5 SECONDS **
pi@raspberrypi:~ $

Do you have any idea why this happens?

Possible differences in bulb versions

This is mentioned in #4 but it seems like it hasn't been solved yet

I had to change the handle for color change to make the library work with my newly bought Magic Blue bulb. I also had issues connecting to the bulb when address type was set to random and therefore changed it to public which made connection work (not sure why, might be an issue within bluepy lib?). Changes can be seen in this commit to my fork. I have tried this on my laptop and a Raspberry Pi, both running Arch Linux.

Here is some gatttool output:

[20:16:03:09:00:A8][LE]> primary
attr handle: 0x0001, end grp handle: 0x0007 uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x0008, end grp handle: 0x0008 uuid: 0000fff0-0000-1000-8000-00805f9b34fb
attr handle: 0x0009, end grp handle: 0x000b uuid: 0000ffe5-0000-1000-8000-00805f9b34fb
attr handle: 0x000c, end grp handle: 0xffff uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
[20:16:03:09:00:A8][LE]> char-write-req 0c000c 56FFFFFF00f0aa
Error: Characteristic Write Request failed: Attribute can't be written
[20:16:03:09:00:A8][LE]> char-write-req 0c000b 56FFFFFF00f0aa
Characteristic value was written successfully

In the official magic blue app my bulb is listed with a description saying "Hardware V9", @Betree @don41382 what is the hardware version reported by your bulbs? I bought mine from http://www.miniinthebox.com/ btw.

Perhaps there is a way to query the bulbs version number or something and make the lib more dynamic in those places. Will look into this when I have some more spare time :)

Also thanks for a nice lib!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.