Skip to main content

Python BLE library for using Nordic nRF52 with Connectivity firmware

Project description

Blatann

blåtann: Norwegian word for "blue tooth"

Blatann aims to provide a high-level, object-oriented interface for interacting with Bluetooth Low Energy (BLE) devices through Python. It operates using the Nordic Semiconductor nRF52 through Nordic's pc-ble-driver-py library and the associated Connectivity firmware for the device.

Documentation is available on ReadTheDocs

Install

pip install blatann

Using with macOS brew python

pc-ble-driver-py consists of a shared object which is linked to mac's system python. In order to use it with brew's python install, you'll need to run install_name_tool to modify the .so to point to brew python instead of system python.

Note: This is the case with any custom-installed python on mac (like anaconda), brew is the most popular and what has been tested

An example shell script to do so can be found here

Supported Devices/Software

This library has been tested with the following hardware:

Flashed with specific Connectivity firmware released by Nordic Semiconductor.

When using the nRF52840, it should be flashed using the S132/SoftDevice v5 connectivity images. Both the hex files and DFU packages are distributed with v4.1.4 of pc-ble-driver and is also provided in the pc-ble-driver-py install.

The Nordic devices can be flashed using nRF Connect Desktop App or the nrfutil CLI tool.

Roadmap/Supported BLE Features

As of v0.3.0, the public-facing API of Blatann is stable. There will not likely be any major changes in method/property naming or functionality and all features added will aim to maintain backwards compatibility.

Below lists the supported BLE features and ones that are on the roadmap to implement (eventually)

  • GAP
    • BLE Enable parameters
    • BLE Connection parameters (functional, needs some work)
    • Advertising
    • Data Length Extensions
    • PHY selection
      • Coded PHY not supported, only 1 and 2 Mbps PHYs
    • Scanning
    • Documentation
    • RSSI
    • Transmit Power
    • Advertising channel selection
  • SMP
    • Private resolvable/non-resolvable advertising
    • Encryption/Authentication process
    • MITM/Passcode pairing support
    • Store bonding info
    • Identity resolve
    • Bonding as Peripheral
    • Bonding as Central
    • LESC pairing
    • Documentation
  • GATT
    • Configurable MTU
    • Generic Access service configuration
    • Service Changed characteristic
  • GATT Server
    • Characteristic Reads
    • Characteristic Writes
    • Notifications/Indications
    • Long reads/writes
    • Characteristic User Description/Presentation format
    • CCCD Caching
    • Custom Read/Write authorization (#10)
    • Documentation
  • GATT Client
    • Database Discovery procedure
    • Client reads
    • Client writes
    • Client long writes
    • Notifications/Indications
    • CCCD Caching
    • Service Discovery Caching (#89)
    • Documentation
  • Examples
    • Advertiser/Broadcaster
    • Scanner/Observer
    • Central, Procedural
    • Central, Event Driven
    • Central, Multiple Connections (#77)
    • Peripheral
    • Multi-role
    • Passcode Pairing
    • LESC Numeric Comparison Pairing (glucose peripheral, no central example)
    • Bonding (glucose peripheral, no central example)
  • Bluetooth Services
    • Device Info Service
    • Battery Service
    • Current Time Service
      • Peripheral
      • Central (Partially implemented)
    • Glucose Service
      • Peripheral
      • Central
    • Nordic UART Service
    • More TBD (or on request)
  • License
  • Unit Tests
  • Integration Tests (partial -- below are implemented)
    • Advertising
    • Scanning
    • GATT Writes/Reads
    • GATT throughput testing/benchmarks
    • Pairing/Bonding

The library aims to support both event-driven and procedural program styles. It takes similar paradigms from C#/.NET's event function signatures, where event handlers are passed object sender, EventArgs e parameters. Additionally, all asynchronous function calls return a Waitable object which can be waited on (with timeout) until the event associated with the function call returns.

Examples

There are several example scripts which showcase different functionality of the library under blatann/examples. Examples can be run using python -m blatann.examples [example_filename] [device_comport].

Example usage: python -m blatann.examples scanner COM3

Running Tests

The integrated tests can be ran using the builtin unittest runner and depends on a few environment variables to find the connected Nordic devices.

At a minimum, two nordic devices are required to run the unit tests. These are specified using environment variables:

  • BLATANN_DEV_1 - Serial port of the first Nordic device
  • BLATANN_DEV_2 - Serial port of the second Nordic device

Optionally a third BLATANN_DEV_3 can be specified to run tests which require more than two devices. If this environment variable is not defined, tests which require 3 devices are skipped.

In order to speed up the tests, BLATANN_TEST_QUICK=1 can be defined to skip long-running tests. Note that test cases which are defined as "long-running" is subjective and relative--the test suite will still take awhile to run, but in general test cases which take longer than 20 seconds are skipped.

The tests can also be ran through the makefile using make run-tests.

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

blatann-0.6.0.tar.gz (206.8 kB view details)

Uploaded Source

Built Distribution

blatann-0.6.0-py3-none-any.whl (256.5 kB view details)

Uploaded Python 3

File details

Details for the file blatann-0.6.0.tar.gz.

File metadata

  • Download URL: blatann-0.6.0.tar.gz
  • Upload date:
  • Size: 206.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for blatann-0.6.0.tar.gz
Algorithm Hash digest
SHA256 1db64634e3b069cac502a41e231c19ea66bd8f6d38f72049fb1a63832a1a1954
MD5 7f47b5b08c1c1b5391be24ccd42d4cc4
BLAKE2b-256 6190b603fc89f0c45c8f7d5c9fad150911e51035dc6917f742bbbdca877b102a

See more details on using hashes here.

File details

Details for the file blatann-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: blatann-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 256.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for blatann-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be873e48f229b6bc7ffecf5607b18450e6438ae165cf64f63e8cc10c501c39e7
MD5 7b9b88c2e456c6fbe047dd6d87a8108d
BLAKE2b-256 b7c1a4b782b4199ec410d58da91a9095b661d9e801051b9b17f1dbe472cc1b1d

See more details on using hashes here.

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