No project description provided
Project description
bleep
A BLE abstraction layer for Python inspired by bleat. Currently only supports Linux, with experimental support for Mac OS X.
Current Support
- Discovering devices
- Reading advertising data
- Connecting to devices
- Discovering services, characteristics and descriptors
- Read from characteristics
Installation
Linux
First, install my fork of pygattlib and its dependencies:
sudo apt-get install libboost-python-dev libboost-thread-dev libbluetooth-dev libglib2.0-dev python-dev
You should also make sure that your version of libbluetooth is at least 4.101:
apt-cache policy libbluetooth-dev | grep Installed
Then, clone the repository, and install the python package.
git clone https://github.com/matthewelse/pygattlib.git
cd pygattlib
sudo python setup.py install
This will build the dynamic library, and install the python package.
You can then install bleep easily:
sudo pip install bleep
If you want to develop bleep, instead of the last line, run:
sudo python setup.py develop
This will cause any changes you make to bleep to be reflected when you import the library.
NOTE: You may need to run all BLE code with
sudo
, even when using the Python interactive shell.
Mac OS X
Installation on Mac OS X is very simple:
brew install boost-python
git clone https://github.com/matthewelse/bleep.git
cd bleep
sudo python setup.py install
Likewise, if you would like to develop bleep, run this instead of the last line:
sudo python setup.py develop
Examples
tree.py
You can run tree.py to see all of the services, characteristics and descriptors attached to a device with a specific mac address. In order to find the device's mac address, you could use hcitool lescan
, or use BLEDevice.discoverDevices()
.
usage: tree.py [-h] mac
Usage
Include bleep
>>> from bleep import BLEDevice
Scan for devices
>>> devices = BLEDevice.discoverDevices()
>>> devices
[Device Name: (5A:79:8E:91:83:1C), Device Name: (C1:20:68:1B:00:26), Device Name: BLE Keyboard (C9:E8:56:3B:4D:B1), Device Name: (4C:25:F5:C2:E6:61), Device Name: (60:03:08:B2:47:F1), Device Name: (C1:62:3A:1D:00:14)]
This will return a list of Device objects, however you won't be connected to any of them, so pick one you like, and connect to it:
>>> device = devices[2]
>>> device.connect()
You can then access the device's services:
>>> device.services
[Generic Access, Generic Attribute, Device Information, Battery Service, Human Interface Device]
each service's characteristics
>>> service = device.services[4]
>>> service
Human Interface Device
>>> service.characteristics
[HID Information, Report Map, Protocol Mode, HID Control Point, Report, Report]
and each characteristic's descriptors
>>> char = service.characteristics[4]
>>> char
Report
>>> char.descriptors
[Client Characteristic Configuration, Report Reference]
Useful Functionality
BLEDevice.discoverDevices
supports parameters which allow you to specify which BLE device to connect to (ignored on OSes other than Linux), how long to sample for, as well as a function which returns a boolean value, allowing you to cherry-pick your devices.
def discoverDevices(device='hci0', timeout=5, filter=lambda x: True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for bleep-0.5-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 251e735297954358ba62c1415c50b2fd68e97ad3a80ac7fac7ecdc342afeaa6e |
|
MD5 | 07a613a4a7670b899f1cc0da4c80af9d |
|
BLAKE2b-256 | 4c84ce8395eeb6c5fcf21321d3f3e44870ce21d456fb92ed1c37618748f4e1aa |
Hashes for bleep-0.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d26b1263fb6d96f5180953938627ad7057445a8623043d748586b1c8c40696a |
|
MD5 | 1dfb77af74cd0751612aa3f04591ea20 |
|
BLAKE2b-256 | 0656e8cb8ce4a3299e9d03396375606101df865ea07918f049145ac9a01c29b0 |
Hashes for bleep-0.5-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 544787106fcfe9954e6bf18e0dca906dbb47d35446ea6f5d859ff74d7a612d9c |
|
MD5 | 0badca27d84254ca31608fa111ace373 |
|
BLAKE2b-256 | cd35aa6d9a21c5bc3d046175418ad4fdf19bc5e90efb4571f5feb24f99f835ad |
Hashes for bleep-0.5-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c83ad6ca3122019212ecd419d42d8ea32c2854b0007881151ad54d4e1c3a584 |
|
MD5 | 2435e20140ab39cf0cc089897e609c1c |
|
BLAKE2b-256 | 48aa2a48b8c0d4ada372774bc5e2c9ac19c4ef25fef604ab4b0ea852d43b5ea5 |
Hashes for bleep-0.5-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bde1ee3c2b8267fe3faf13bba2318ed7f3a7377d3ac02c45dff43064a07b5ebd |
|
MD5 | d49cd4fe4ec85bc89b36f58b2fcdb460 |
|
BLAKE2b-256 | 44c7c4330302530998118364c566c8f6d5ff9d6a6842158579618cc047a9d858 |
Hashes for bleep-0.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 295dfc3a03304efdaf338b3b2249499840a258bd5114e0022488ab50377ffbca |
|
MD5 | 12305eace2713f7521629800a7a7dad2 |
|
BLAKE2b-256 | ba16e9483c4a0f204fd83010e5182197f9ec3ed533ddca46fba07a5bb5185541 |
Hashes for bleep-0.5-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de2cd0cf90dd740c86093760384df8c433d003f2cf9c9f173f30e7d9ea85cdb7 |
|
MD5 | 28d38d0732ba0109fc1fbd5510950ad0 |
|
BLAKE2b-256 | c62cff1d232741433231ef832b749747fb69f21dd33a528e95c8c6c9dd140a4d |
Hashes for bleep-0.5-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fcd4b2194532de548bff268c66502e5ba55dc6a4856372cd76b28e9b706cdf2 |
|
MD5 | aa1fd641a74c0ca5b98b58790357a206 |
|
BLAKE2b-256 | 0d75697e696287dc3b245b9d7134538e35ed7272f9c1204df8b9daaa7eb6328e |
Hashes for bleep-0.5-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da14721f3035c14d8732d75880df367cf3a10604cd232cf172a13d557e4d3380 |
|
MD5 | c8d5cb2c58d22308e0144d21a0aa095a |
|
BLAKE2b-256 | 252cf8d1bef09511c11d8b13cb00754b3c22ace3a1a70982377a656f1cd2a591 |