Crates.io | blez |
lib.rs | blez |
version | 0.9.7 |
source | src |
created_at | 2021-05-28 15:45:35.393679 |
updated_at | 2021-07-06 10:55:06.338963 |
description | Renamed to bluer |
homepage | |
repository | https://github.com/surban/blez |
max_upload_size | |
id | 403187 |
size | 543,176 |
BLEZ has been renamed to BlueR and is now the official Rust interface to BlueZ.
Development will continue in the BlueZ organization repository.
Please update your links and crate references.
This library provides an asynchronous, fully featured interface to the Bluetooth Low Energy (BLE) APIs of the official Linux Bluetooth protocol stack (BlueZ) for Rust. Both publishing local and consuming remote GATT services using idiomatic Rust code is supported. L2CAP sockets are presented using an API similar to Tokio networking.
The following functionality is provided:
AsyncRead
and AsyncWrite
streams for notify and write operationsAsyncRead
and AsyncWrite
streamsAsyncRead
and AsyncWrite
supportClassic Bluetooth is unsupported except for device discovery.
This project started as a fork of blurz but has since then become a full rewrite. Documentation has been mostly copied from the BlueZ API specification, but also adapted where it makes sense.
All crate features are enabled by default.
bluetoothd
: Enables all functions requiring a running Bluetooth daemon.
For building, D-Bus library headers, provided by libdbus-1-dev
on Debian, must be installed.l2cap
: Enables L2CAP sockets.
For building, Bluetooth library headers, provided by libbluetooth-dev
on Debian, must be installed.This library has been tested with BlueZ version 5.59 with additional patches from the master branch applied. Older versions might work, but be aware that many bugs related to GATT handling exist. Refer to the official changelog for details.
If any bluetoothd
feature is used the Bluetooth daemon must be running and configured for access over D-Bus.
On most distributions this should work out of the box.
The following options in /etc/bluetooth/main.conf
are helpful.
[GATT]
Cache = no
Channels = 1
This disables the GATT cache to avoid stale data during device discovery.
By only allowing one channel the extended attribute protocol (EATT) is disabled. If EATT is enabled, all GATT commands and notifications are sent over multiple L2CAP channels and can be reordered arbitrarily by lower layers of the protocol stack. This makes sequential data transmission over GATT characteristics more difficult.
The library returns detailed errors received from BlueZ.
Set the Rust log level to trace
to see all D-Bus communications with BlueZ.
In some cases checking the Bluetooth system log might provide further insights.
On Debian-based systems it can be displayed by executing journalctl -u bluetooth
.
Check the bluetoothd
man page for increasing the log level.
Sometimes deleting the system Bluetooth cache at /var/lib/bluetooth
and restarting
bluetoothd
is helpful.
Refer to the API documentation and examples folder for examples.
The following example applications are provided.
discover_devices: Discover Bluetooth devices and print their properties.
gatt_client: Simple GATT client that calls read, write and notify on a characteristic.
gatt_server_cb: Corresponding GATT server implemented using callback programming model.
gatt_server_io: Corresponding GATT server implemented using IO programming model.
gatt_echo_client: Simple GATT client that connects to a server and sends and receives test data.
gatt_echo_server: Corresponding GATT server that echos received data.
l2cap_client: Simple L2CAP socket client that connects to a socket and sends and receives test data.
l2cap_server: Corresponding L2CAP socket server that echos received data.
le_advertise: Register Bluetooth LE advertisement.
list_adapters: List installed Bluetooth adapters and their properties.
Use cargo run --example <name>
to run a particular example application.
See the BLEZ tools crate for tools that build on this library.