BLEZ - Asynchronous Bluetooth Low Energy on Linux for Rust

Overview

BLEZ - Asynchronous Bluetooth Low Energy on Linux for Rust

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. Asynchronous support is dependent by Tokio.

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.

The following features are provided:

  • Bluetooth adapters
    • enumeration
    • configuration of power, discoverability, name, etc.
    • hot-plug support through change events stream
  • Bluetooth devices
    • discovery
    • querying of address, name, class, signal strength (RSSI), etc.
    • Bluetooth Low Energy advertisements
    • change events stream
    • connecting and pairing
  • 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-overhead AsyncRead and AsyncWrite 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-overhead AsyncRead and AsyncWrite streams
  • sending Bluetooth Low Energy advertisements

Classic Bluetooth is unsupported except for device discovery.

Requirements

This library has been tested with BlueZ version 5.56. Older versions might work, but be aware that many bugs related to GATT handling exist. Refer to the official changelog for details.

bluetoothd must be running and configured for access over D-Bus. On most distributions this should work out of the box.

For building, D-Bus library headers must be installed. On Debian-based distributions install the package libdbus-1-dev.

Troubleshooting

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.

Examples

Refer to the API documentation and examples folder for examples.

The following example applications are provided.

  • device_monitor: Scans for and monitors Bluetooth devices similar to top.

  • 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.

  • le_advertise: Register Bluetooth LE advertisement.

  • list_adapters: List installed Bluetooth adapters and their properties.

Use cargo run --example to run a particular example application.

You might also like...
A metrics collection application for Linux machines. Created for MSCS 710 Project at Marist College.

Linux-Metrics-Collector A metrics collection application for Linux machines. Created for MSCS 710 Project at Marist College. Development Environment S

A transparent QUIC to SOCKSv5 proxy on Linux, UDP/QUIC verison of moproxy.

quproxy A transparent QUIC to SOCKSv5 proxy on Linux, UDP/QUIC verison of moproxy. 🚧 WORKING IN PROGRESS 🚧 Features: Transparent forward QUIC to ups

Grow Rust is a Growtopia Private Server made in Rust

Grow Rust is a Growtopia Private Server made in Rust

Multiplex server for rust-analyzer, allows multiple LSP clients (editor windows) to share a single rust-analyzer instance per cargo workspace

ra-multiplex   Multiplex server for rust-analyzer, allows multiple LSP clients (editor windows) to share a single rust-analyzer instance per cargo wor

Rust crate for configurable parallel web crawling, designed to crawl for content

url-crawler A configurable parallel web crawler, designed to crawl a website for content. Changelog Docs.rs Example extern crate url_crawler; use std:

Rust crate for scraping URLs from HTML pages

url-scraper Rust crate for scraping URLs from HTML pages. Example extern crate url_scraper; use url_scraper::UrlScraper; fn main() { let director

FTP client for Rust

rust-ftp FTP client for Rust Documentation rust-ftp Installation Usage License Contribution Development environment Installation FTPS support is achie

The gRPC library for Rust built on C Core library and futures

gRPC-rs gRPC-rs is a Rust wrapper of gRPC Core. gRPC is a high performance, open source universal RPC framework that puts mobile and HTTP/2 first. Sta

A library to work with CIDRs in rust

ipnetwork This is a library to work with IPv4 and IPv6 CIDRs in Rust Run Clippy by doing rustup component add clippy cargo clippy Installation This c

Comments
  • How to listen BLE Advertisements?

    How to listen BLE Advertisements?

    Hi, I'd like to know how to listen to BLE Advertisement.

    I'm trying to do something similar to this: https://github.com/Thrilleratplay/GoveeWatcher/blob/master/python/goveeWatcher.py

    Thank you!

    opened by sebest 4
  • Build of BLEZ fails due to

    Build of BLEZ fails due to "No such file or directory"

    On my machine the build of current blez master branch 0.9.4 fails. I'm using latest rust stable (1.52.1).

    It gives me the following error message:

    error: failed to run custom build command for `blez v0.9.4 (/home/sojus/src/meshnet/examples/blez/blez)`
    
    Caused by:
      process didn't exit successfully: `/home/sojus/src/meshnet/examples/blez/target/debug/build/blez-32ba4e3e0de9fdbb/build-script-build` (exit code: 101)
      --- stdout
      cargo:rerun-if-changed=bluetooth-numbers-database/v1/service_uuids.json
    
      --- stderr
      thread 'main' panicked at 'services: Os { code: 2, kind: NotFound, message: "No such file or directory" }', blez/build.rs:213:6
      stack backtrace:
         0: rust_begin_unwind
                   at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panicking.rs:493:5
         1: core::panicking::panic_fmt
                   at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/panicking.rs:92:14
         2: core::option::expect_none_failed
                   at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/option.rs:1329:5
         3: core::result::Result<T,E>::expect
                   at /home/sojus/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:997:23
         4: build_script_build::main
                   at ./build.rs:206:5
         5: core::ops::function::FnOnce::call_once
                   at /home/sojus/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
      note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    warning: build failed, waiting for other jobs to finish...
    error: build failed
    
    opened by MathJud 2
Asynchronous Linux SocketCAN - Broadcast Manager support (BCM) with tokio

tokio-socketcan-bcm The Broadcast Manager protocol provides a command based configuration interface to filter and send (e.g. cyclic) CAN messages in k

Marcel 3 Mar 10, 2022
A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...

Tokio A runtime for writing reliable, asynchronous, and slim applications with the Rust programming language. It is: Fast: Tokio's zero-cost abstracti

Tokio 17.6k Sep 23, 2022
An asynchronous Prometheus exporter for iptables

iptables_exporter An asynchronous Prometheus exporter for iptables iptables_exporter runs iptables-save --counter and scrapes the output to build Prom

Kevin K. 17 Aug 6, 2022
General-purpose asynchronous socket stream.

async-socket This crate implements a general-purpose asynchronous socket. The Socket implements AsyncRead, AsyncWrite, Stream and Clone traits and thu

Kristijan Sedlak 3 Oct 20, 2021
An asynchronous dumb exporter proxy for prometheus. This aggregates all the metrics and exposes as a single scrape endpoint.

A dumb light weight asynchronous exporter proxy This is a dumb lightweight asynchronous exporter proxy that will help to expose multiple application m

Dark streams 3 Aug 1, 2022
Cross-platform, low level networking using the Rust programming language.

libpnet Linux ∪ OS X Build Status: Windows Build Status: Discussion and support: #libpnet on freenode / #rust-networking on irc.mozilla.org / #rust on

null 1.7k Sep 28, 2022
A high performance/low-overhead OpenMetrics library for Rust

* * * EXPERIMENTAL * * * discreet-metrics A high-performance/low-overhead metrics library aiming to conform with OpenMetrics and to satisfy the follow

null 2 Sep 14, 2022
Interactive bind/reverse PTY shell with Windows&Linux support implementation by Rust.

Cliws Lightweight interactive bind/reverse PTY shell with Windows&Linux support implementation by Rust. Features WebSocket Full pty support: VIM, SSH,

b23r0 215 Dec 3, 2021
A BitTorrent V1 engine library for Rust (and currently Linux)

cratetorrent Cratetorrent is a Rust crate implementing the BitTorrent version 1 protocol. It can be used as a library and also provides a simple examp

null 380 Sep 21, 2022
pam-send-slack-message is a program that publishes messages on slack when a linux server is accessed through ssh.

pam-send-slack-message pam-send-slack-message is a program that publishes messages on slack when the linux server is accessed through ssh. Installatio

Iuri Diniz 2 Aug 17, 2022