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)
Release files for bleep 0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bleep-0.5.tar.gz | 25.2 kB | Details |
Built distributions (wheels)
Total release size: 18.0 MB
Release files / bleep-0.5.tar.gz
| Download URL | bleep-0.5.tar.gz |
|---|---|
| Size | 25.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4cd42d6da52b13a844d59f7595652156691098f4486b45778b1e2284e6b4f31c
|
|
BLAKE2b-256 checksum How to use checksums |
7d869bed7e9ccc929105fe3006be70b4a6a47a1a0895488d491bc36fb5fccda3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / bleep-0.5-cp37-abi3-win_amd64.whl
| Download URL | bleep-0.5-cp37-abi3-win_amd64.whl |
|---|---|
| Size | 600.4 kB |
| Tags | CPython 3.7 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
251e735297954358ba62c1415c50b2fd68e97ad3a80ac7fac7ecdc342afeaa6e
|
|
BLAKE2b-256 checksum How to use checksums |
4c84ce8395eeb6c5fcf21321d3f3e44870ce21d456fb92ed1c37618748f4e1aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / bleep-0.5-cp37-abi3-win32.whl
| Download URL | bleep-0.5-cp37-abi3-win32.whl |
|---|---|
| Size | 529.3 kB |
| Tags | CPython 3.7 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
f8400fbe71d279c635e1d65db00fdd5da1283cfa1cceac6a8af54d3f80a77eb9
|
|
BLAKE2b-256 checksum How to use checksums |
a29a5fea9f71a8ee7d3ec997cffd14899accc35b1a121be2ea2d6d429293b4ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / bleep-0.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | bleep-0.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 2.4 MB |
| Tags | CPython 3.7 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0d26b1263fb6d96f5180953938627ad7057445a8623043d748586b1c8c40696a
|
|
BLAKE2b-256 checksum How to use checksums |
0656e8cb8ce4a3299e9d03396375606101df865ea07918f049145ac9a01c29b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / bleep-0.5-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | bleep-0.5-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 2.8 MB |
| Tags | CPython 3.7 Linux glibc 2.17+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
544787106fcfe9954e6bf18e0dca906dbb47d35446ea6f5d859ff74d7a612d9c
|
|
BLAKE2b-256 checksum How to use checksums |
cd35aa6d9a21c5bc3d046175418ad4fdf19bc5e90efb4571f5feb24f99f835ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / bleep-0.5-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | bleep-0.5-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 2.6 MB |
| Tags | CPython 3.7 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
1c83ad6ca3122019212ecd419d42d8ea32c2854b0007881151ad54d4e1c3a584
|
|
BLAKE2b-256 checksum How to use checksums |
48aa2a48b8c0d4ada372774bc5e2c9ac19c4ef25fef604ab4b0ea852d43b5ea5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / bleep-0.5-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | bleep-0.5-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 2.3 MB |
| Tags | CPython 3.7 Linux glibc 2.17+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
bde1ee3c2b8267fe3faf13bba2318ed7f3a7377d3ac02c45dff43064a07b5ebd
|
|
BLAKE2b-256 checksum How to use checksums |
44c7c4330302530998118364c566c8f6d5ff9d6a6842158579618cc047a9d858
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / bleep-0.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | bleep-0.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 2.4 MB |
| Tags | CPython 3.7 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
295dfc3a03304efdaf338b3b2249499840a258bd5114e0022488ab50377ffbca
|
|
BLAKE2b-256 checksum How to use checksums |
ba16e9483c4a0f204fd83010e5182197f9ec3ed533ddca46fba07a5bb5185541
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / bleep-0.5-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
| Download URL | bleep-0.5-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.7 Linux glibc 2.12+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
de2cd0cf90dd740c86093760384df8c433d003f2cf9c9f173f30e7d9ea85cdb7
|
|
BLAKE2b-256 checksum How to use checksums |
c62cff1d232741433231ef832b749747fb69f21dd33a528e95c8c6c9dd140a4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / bleep-0.5-cp37-abi3-macosx_11_0_arm64.whl
| Download URL | bleep-0.5-cp37-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 869.7 kB |
| Tags | CPython 3.7 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4fcd4b2194532de548bff268c66502e5ba55dc6a4856372cd76b28e9b706cdf2
|
|
BLAKE2b-256 checksum How to use checksums |
0d75697e696287dc3b245b9d7134538e35ed7272f9c1204df8b9daaa7eb6328e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / bleep-0.5-cp37-abi3-macosx_10_7_x86_64.whl
| Download URL | bleep-0.5-cp37-abi3-macosx_10_7_x86_64.whl |
|---|---|
| Size | 907.0 kB |
| Tags | CPython 3.7 abi3 macOS 10.7+ x86-64 |
|
SHA-256 checksum How to use checksums |
da14721f3035c14d8732d75880df367cf3a10604cd232cf172a13d557e4d3380
|
|
BLAKE2b-256 checksum How to use checksums |
252cf8d1bef09511c11d8b13cb00754b3c22ace3a1a70982377a656f1cd2a591
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|