Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

BlueR — Official BlueZ Bindings for Rust

License

NotificationsYou must be signed in to change notification settings

bluez/bluer

Repository files navigation

crates.io pagedocs.rs pageBSD-2-Clause license

This library provides the officialRust interface to theLinux Bluetooth protocol stack (BlueZ).Both publishing local and consuming remoteGATT services usingidiomatic Rust code is supported.L2CAP and RFCOMM sockets are presented using an API similar toTokio networking.

The following functionality is provided:

  • Bluetooth adapters
    • enumeration
    • configuration of power, discoverability, name, etc.
    • hot-plug support through change events stream
  • Bluetooth devices
    • discovery with custom filters
    • querying of address, name, class, signal strength (RSSI), etc.
    • Bluetooth Low Energy advertisements
    • change events stream
    • connecting and pairing
    • passive LE advertisement monitoring
  • consumption of remote GATT services
    • GATT service discovery
    • read, write and notify operations on characteristics
    • read and write operations on characteristic descriptors
    • optional use of low-overheadAsyncRead andAsyncWrite streams for notify and write operations
  • publishing local GATT services
    • read, write and notify operations on characteristics
    • read and write operations on characteristic descriptors
    • two programming models supported
      • callback-based interface
      • low-overheadAsyncRead andAsyncWrite streams
  • sending Bluetooth Low Energy advertisements
  • Bluetooth authorization agent
  • efficient event dispatching
    • not affected by D-Bus match rule count
    • O(1) in number of subscriptions
  • L2CAP sockets
    • support for both classic Bluetooth (BR/EDR) and Bluetooth LE
    • stream oriented
    • sequential packet oriented
    • datagram oriented
    • async IO interface withAsyncRead andAsyncWrite support
  • RFCOMM sockets
    • support for classic Bluetooth (BR/EDR)
    • stream oriented
    • async IO interface withAsyncRead andAsyncWrite support
  • Bluetooth Mesh
    • provision and join networks
    • send and receive messages
  • database of assigned numbers
    • manufacturer ids
    • service classes, GATT services, characteristics and descriptors

Currently, some classic Bluetooth (BR/EDR) functionality is missing.However, pull requests and contributions are welcome!

Usage

To use BlueR as a library, run the following command in your project directory:

cargo add -F full bluer

This will add the latest version of BlueR with all features enabled as a dependency to yourCargo.toml.

Crate features

The following crate features are available.

  • bluetoothd: Enables all functions requiring a running Bluetooth daemon.For building, D-Bus library headers, provided bylibdbus-1-dev on Debian, must be installed.
  • id: Enables database of assigned numbers.
  • l2cap: Enables L2CAP sockets.
  • rfcomm: Enables RFCOMM sockets.
  • mesh: Enables Bluetooth mesh functionality.
  • serde: Enables serialization and deserialization of some data types.

To enable all crate features specify thefull crate feature.

Requirements

The minimum support Rust version (MSRV) is 1.75.

This library has been tested withBlueZ 5.60.Older versions might work, but be aware that many bugs related to GATT handling exist.Refer to theofficial changelog for details.

If anybluetoothd 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.

Formesh feature Bluetooth mesh daemon must be running and configured for access over D-Bus.

Configuration

The following options in/etc/bluetooth/main.conf are helpful when working with GATT services.

[GATT]Cache = noChannels = 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.

Building

When cloning this repository make sure to use the following command.Otherwise the build will fail with file not found errors.

git clone --recursive https://github.com/bluez/bluer.git

D-Bus development headers are required for building.

Troubleshooting

The library returns detailed errors received from BlueZ.

Set the Rust log level totrace 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 executingjournalctl -u bluetooth.Check thebluetoothd man page for increasing the log level.

Sometimes deleting the system Bluetooth cache at/var/lib/bluetooth and restartingbluetoothd fixes persistent issues with device connectivity.

Examples

Refer to theAPI documentation andexamples 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.

  • le_passive_scan: LE passive scan & subscribe to updates for discovered peripheral(s).

  • list_adapters: List installed Bluetooth adapters and their properties.

  • mesh_sensor_client: Simple Bluetooth mesh client sending sensor model messages

  • mesh_sensor_server: Simple Bluetooth mesh server receiving sensor model messages

  • mesh_provisioner: Simple Bluetooth mesh provisioner

  • rfcomm_client: Simple RFCOMM socket client that connects to a socket and sends and receives test data.

  • rfcomm_server: Corresponding RFCOMM socket server that echos received data.

Usecargo run --all-features --example <name> to run a particular example application.

Tools

See theBlueR tools crate for tools that build on this library.

History

This project started as a fork ofblurz but has since then become a full rewrite.It was published under the nameblez before it was designated the official Rustinterface to BlueZ and renamed to BlueR.Documentation has been mostly copied from theBlueZ API specification, butalso adapted where it makes sense.


[8]ページ先頭

©2009-2025 Movatter.jp