Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving to pygatt (and back to bluepy again) and further implement bulb-functions/improve communication #20

Merged
merged 9 commits into from
May 7, 2017

Conversation

StevenLooman
Copy link
Collaborator

Following up on #17. Here is a pull request which moves magicblue to pygatt from bluepy, and further implements the protocol.

Unfortunately, I have (yet) seen no way to dynamically figure out the address type to use. The software does try to guess if no version is given, but your mileage may vary. Maybe we can detect it from the bulb-address? Please, let me know the versions and mac addresses of your bulb(s).

Also, scanning for bulbs is now slightly altered. pygatt reports all found devices at once after scanning. bluepy uses a callback which is called during scanning. In the new method of scanning, it might look scanning has stalled. Therefore, I have shortened the scanning-time to 10 seconds.

Please, feel free to provide any feedback. And, of course, do test this on your own bulb(s)! For my V10 bulbs all implemented functions work.

@StevenLooman
Copy link
Collaborator Author

StevenLooman commented Apr 27, 2017

Another note on the changes. No longer are handles used (directly.) It seems that the handles to read from/write to are static but do appear to change with bulb versions. A UUID is used to access the characteristics (0xFFE4 for notifications/reading, 0xFFE9 for writing commands) to retrieve the necessary handles from the bulb.

@StevenLooman
Copy link
Collaborator Author

Please wait before merging. I am having some troubles due to sudo being used from pygatt.

I will explain later.

@Betree
Copy link
Owner

Betree commented Apr 29, 2017

Lot of good changes in here ! I like what you've done with the @connection_required decorator.

I'll start testing this during the week to assist you with this task 👍

The fact we have to be root to access the bluetooth device is very inconvenient. Haven't tried this yet but maybe I could also add a section in README to explain how to make BLE device accessible for non root (as with this link)

@StevenLooman
Copy link
Collaborator Author

StevenLooman commented Apr 30, 2017

And I've moved back to bluepy again... when I was testing the homeassistant-magicblue component I got several password-entry request from sudo.

This can be worked around by creating 5 entries in /etc/sudoers giving a specific user the ability to run 5 commands passwordless. But this feels like a hurdle compared to running a single command to set capabilities for hcitool.

Also, if hcitool has the capabilities, there is no need to run the shell as root/using sudo. I tried to find a library to check capabilities, but couldn't find one. I'll create an issue for this.

Please test this version. I was able to get notifications using bluepy. Turns out pygatt simply sends a special message to subscribe.

After this is merged, I'll create a pull request for homeassistant-magicblue to incorporate the new abilities of this library.

@StevenLooman StevenLooman changed the title Moving to pygatt and further implement bulb-functions/improve communication Moving to pygatt (and back to bluepy again) and further implement bulb-functions/improve communication Apr 30, 2017
@Betree Betree merged commit 6146967 into Betree:master May 7, 2017
@Betree
Copy link
Owner

Betree commented May 7, 2017

Everything run fine with my v7 bulb, thank for this PR 😉

I'll release a new version with these changes

@StevenLooman
Copy link
Collaborator Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants