#bluetooth #bluez #ble #ots #object-transfer #api-bindings #linux

bluez-async-ots

Bluetooth Object Transfer Service (OTS) Client for bluez-async

4 releases

0.2.0 Nov 27, 2023
0.1.2 Nov 24, 2023
0.1.1 Nov 21, 2023
0.1.0 Oct 16, 2023

#299 in Unix APIs

Download history 6/week @ 2024-02-19 9/week @ 2024-02-26 8/week @ 2024-03-11 64/week @ 2024-04-01

72 downloads per month
Used in ots-client

MIT/Apache

76KB
2K SLoC

Bluetooth OTS client

github crate docs MIT Apache-2.0 CI

This crate implements Bluetooth Object Transfer Service (OTS) client for bluez using bluez-async. Implementation compatible with OTS 1.0 specification.

Usage example

use bluez_async::{BluetoothSession, DeviceId};
use bluez_async_ots::{DirEntries, OtsClient, Result};

#[tokio::main]
async fn main() -> Result<()> {
    // First initiate bluetooth session as usual
    let (_, bs) = BluetoothSession::new().await?;

    // Next discover and connect to get interesting device identifier
    let dev_id: DeviceId = todo!();

    // Create OTS client using session and device id
    // Session will be cloned by client internally
    let ots = OtsClient::new(&bs, &dev_id, &Default::default()).await?;

    // Now you can list objects by reading special object with zero id

    // First we need select required object by identifier
    ots.go_to(0).await?;
    // Follow we can read binary data from current object
    let data = ots.read(0, None).await?;
    // To extract objects info from binary data we have create iterator
    for entry in DirEntries::from(data.as_ref()) {
        println!("{:?}", entry?);
    }

    // Sometimes server hasn't provide special object with objects info
    // In such case alternative way of exploring objects is selecting
    // first (or last) object and iterate over list to last (or first)
    // step by step

    // Select first available object
    ots.first().await?;
    loop {
        // Get all available info about current object
        println!("{:?}", ots.metadata().await?);
        // Try go to the next object
        if !ots.next().await? {
            break;
        }
    }

    Ok(())
}

Dependencies

~10–21MB
~288K SLoC