Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bleep-0.5.tar.gz (25.2 kB view hashes)

Uploaded Source

Built Distributions

bleep-0.5-cp37-abi3-win_amd64.whl (600.4 kB view hashes)

Uploaded CPython 3.7+ Windows x86-64

bleep-0.5-cp37-abi3-win32.whl (529.3 kB view hashes)

Uploaded CPython 3.7+ Windows x86

bleep-0.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

bleep-0.5-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.8 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ s390x

bleep-0.5-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.6 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64le

bleep-0.5-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.3 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARMv7l

bleep-0.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

bleep-0.5-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl (2.5 MB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.12+ i686

bleep-0.5-cp37-abi3-macosx_11_0_arm64.whl (869.7 kB view hashes)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

bleep-0.5-cp37-abi3-macosx_10_7_x86_64.whl (907.0 kB view hashes)

Uploaded CPython 3.7+ macOS 10.7+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page