getsenic / gatt-python

Bluetooth GATT SDK for Python
MIT License
318 stars 86 forks source link

HID over GATT #42

Closed besi closed 5 years ago

besi commented 5 years ago

I stumbled upon this library and I was able to connect to my Bluetooth LE device. However, since it uses HID over GATT I could currently not go further.

Currently I'm trying to connect my Bluetooth LE Remote to a Raspberrypi only with partial success so far.

Did you intend to, at some point implement the HID over GATT profile. Currently it looks like I'll have to implement the protocol myself and this could be part of gatt-python or by using it as a dependency.

You may let me know if this is at all somehow in the scope of where gatt-python is heading. You may, of course, close this issue, if this is not in the scope or seems to be too off-topic.

ukBaz commented 5 years ago

My assumption is you are using Raspbian based on Debian Stretch which has BlueZ 5.43 in it. Looking at that BlueZ release it suggests it supports HID over GATT (HoG). http://www.bluez.org/release-of-bluez-5-43/ And it seems to have a profile: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/profiles/input/hog.c

From the readme is seems like it is built with HoG by default: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/README#n179

If you use the command-line tool bluetoothctl to scan and connect to the HID does it stay connected? If it stays connected, was there anything new created in /dev/input/*? If there is then I would expect to interact with it using: https://python-evdev.readthedocs.io/en/latest/

Looking at the following presentation on slide 17: https://elinux.org/images/3/32/Doing_Bluetooth_Low_Energy_on_Linux.pdf It does say: Requires uhid support in kernel

besi commented 5 years ago

UHID

I guess this was enabled some time ago. I do have a resource at /dev/uhid:

$ ls -lia /dev/uhid
6687 crw------- 1 root root 10, 239 Feb 18 15:33 /dev/uhid

Bluez

I did update bluez to 5.50:

bluetoothctl -v
# bluetoothctl: 5.50

The Breakthrough

You are right. I do have new entries in dev/input and when I press buttons I see some garbage flying across the screen:

 $ cat /dev/input/event1
??j\݀??j\݀??j\݀??j\.??j\.??j\.??j\Ē??j\Ē??j\Ē??j\????j\????j\????j\?2 ??j\?2??j\?2??j\?? ??j\????j\????j\P?
 ??j\P?
??j\P?
??j\!?
       ??j\!?
             ??j\!?
                   ??j\0 ??j\0??j\0??j\3t
 ??j\3t
??j\3t
??j\?] ??j\?]??j\?]??j\?? ??j\????j\????j\6H"??j\6H??j\6H??j\?"??j\???j\???j\?"??j\???j\???j\?a"??j\?a??j\?a??j\?O
"??j\?O
??j\?O
??j\??
      "??j\??
             ??j\??
                   ??j\??   "??j\?? ??j\??  ??j\??
                                                      "??j\??
                                                             ??j\??

Where to go next

I will have to figure out how to prevent the auto-disconnect of my remote after approx 60 seconds. I will try out the python-evdev, but so far this looks very promising.

Thank you very much @ukBaz for your fast response and your helpful remarks. Incredible!

besi commented 5 years ago

FYI: Even after the remote disconnects in bluetoothctl i still see data flying around in /dev/input/event1. So the connection is no longer an issue.

besi commented 5 years ago

@ukBaz: If you like you may post your answer to my Stackoverflow question and I will happily accept it. Otherwise I will answer it myself and gratefully quote your comments.

BTW: The evdev module worked like a charm right from the beginning and I now get all the nice KEY_POWER, KEY_PREVIOUSSONG, KEY_UP events from the remote. Again a big thank you. You basically saved me from reverse engineering the HID over GATT ;-)

ukBaz commented 5 years ago

Thanks @besi for letting me know how this is working out for you. Glad to have helped.

I am not on stackoverflow so please can you post a response to your questions on there.

Out of curiosity, is the remote control readily available to purchase? Do you have a link?

besi commented 5 years ago

I did update the post. Thanks again for your help on this.

I found the remote in a shrift shop and it comes with the TV offer of the main swiss carrier. I did find out though (by looking at GATT packages) that the manufacturer is https://www.ruwido.com.

You could get a used remote for approx 20$ in Switzerland. I could help you there.

besi commented 5 years ago

I now got several of these BT Remotes. I would be glad to mail you one or two. Just send me your international mailing address via hello (a) b-labs.ch.

besi commented 4 years ago

@ukBaz My offer is still standing

I now got several of these BT Remotes. I would be glad to mail you one or two. Just send me your international mailing address via hello (a) b-labs.ch. See https://vimeo.com/341196060