Expand description
Platform-specific Bluetooth configuration and tuning.
This module provides platform-aware defaults for BLE operations, accounting for differences between operating systems and BLE stacks.
§Platform Differences
| Platform | BLE Stack | Device ID Format | Notes |
|---|---|---|---|
| macOS | CoreBluetooth | UUID | Longer scan times needed (ads ~4s apart) |
| Linux | BlueZ | MAC Address | May need longer connection timeouts |
| Windows | WinRT | MAC Address | Generally reliable defaults |
§macOS UUID Behavior
On macOS, CoreBluetooth does not expose Bluetooth MAC addresses. Instead, it assigns a UUID to each discovered device. This has important implications:
§UUID Stability
-
Same Mac, same device: The UUID is stable for a given device on a given Mac. You can reconnect to the same device using the UUID.
-
Different Macs: Each Mac assigns a different UUID to the same physical device. The UUID
A1B2C3D4-...on Mac A will be different from the UUID assigned on Mac B. -
Bluetooth reset: The UUID may change if you reset Bluetooth settings or unpair all devices. This is rare but can happen.
§Cross-Platform Considerations
For applications that need to identify devices across platforms or machines:
-
Use device names: Device names (e.g., “Aranet4 12345”) are consistent across platforms and machines. However, names can be changed by users.
-
Use serial numbers: Each device has a unique serial number accessible via
device.read_device_info().serial. This is the most reliable cross-platform ID. -
Use the aliasing system: Create user-friendly aliases (e.g., “Living Room”) that map to the appropriate platform-specific identifier.
§Example: Cross-Platform Device Storage
use aranet_core::platform::{DeviceAlias, AliasStore};
// Create an alias that works across platforms
let alias = DeviceAlias::new("Living Room CO2 Sensor")
.with_serial("123456") // Primary: serial number
.with_name("Aranet4 12345") // Fallback: device name
.with_mac("AA:BB:CC:DD:EE:FF") // Linux/Windows: MAC address
.with_uuid("A1B2C3D4-E5F6-..."); // macOS: CoreBluetooth UUID
// Resolve the alias on the current platform
let identifier = alias.resolve(); // Returns appropriate ID for this platform§Usage
use aranet_core::platform::{PlatformConfig, current_platform};
let config = PlatformConfig::for_current_platform();
let scan_options = ScanOptions::default()
.duration(config.recommended_scan_duration);Structs§
- Alias
Store - An in-memory store for device aliases.
- Device
Alias - A cross-platform device alias that can store multiple identifiers.
- Platform
Config - Platform-specific BLE configuration.
Enums§
- Platform
- Platform identifier.
Functions§
- current_
platform - Get the current platform.
- platform_
config - Get platform-specific configuration for the current platform.