Crate aranet_core

Source
Expand description

Core BLE library for Aranet environmental sensors.

This crate provides low-level Bluetooth Low Energy (BLE) communication with Aranet sensors including the Aranet4, Aranet2, AranetRn+ (Radon), and Aranet Radiation devices.

§Features

  • Device discovery: Scan for nearby Aranet devices via BLE
  • Current readings: CO₂, temperature, pressure, humidity, radon, radiation
  • Historical data: Download measurement history with timestamps
  • Device settings: Read/write measurement interval, Bluetooth range
  • Auto-reconnection: Configurable backoff and retry logic
  • Real-time streaming: Subscribe to sensor value changes
  • Multi-device support: Manage multiple sensors simultaneously

§Supported Devices

DeviceSensors
Aranet4CO₂, Temperature, Pressure, Humidity
Aranet2Temperature, Humidity
AranetRn+Radon (Bq/m³), Temperature, Pressure, Humidity
Aranet RadiationDose Rate (µSv/h), Total Dose (mSv)

§Platform Differences

Device identification varies by platform due to differences in BLE implementations:

  • macOS: Devices are identified by a UUID assigned by CoreBluetooth. This UUID is stable for a given device on a given Mac, but differs between Macs. The UUID is not the same as the device’s MAC address.

  • Linux/Windows: Devices are identified by their Bluetooth MAC address (e.g., AA:BB:CC:DD:EE:FF). This is consistent across machines.

When storing device identifiers for reconnection, be aware that:

  • On macOS, the UUID may change if Bluetooth is reset or the device is unpaired
  • Cross-platform applications should store both the device name and identifier
  • The Device::address() method returns the appropriate identifier for the platform

§Quick Start

use aranet_core::{Device, scan};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Scan for devices
    let devices = scan::scan_for_devices().await?;
    println!("Found {} devices", devices.len());

    // Connect to a device
    let device = Device::connect("Aranet4 12345").await?;

    // Read current values
    let reading = device.read_current().await?;
    println!("CO2: {} ppm", reading.co2);

    // Read device info
    let info = device.read_device_info().await?;
    println!("Serial: {}", info.serial);

    Ok(())
}

Re-exports§

pub use device::Device;
pub use error::ConnectionFailureReason;
pub use error::DeviceNotFoundReason;
pub use error::Error;
pub use error::Result;
pub use history::HistoryInfo;
pub use history::HistoryOptions;
pub use history::HistoryParam;
pub use readings::ExtendedReading;
pub use scan::DiscoveredDevice;
pub use scan::FindProgress;
pub use scan::ProgressCallback;
pub use scan::ScanOptions;
pub use scan::find_device_with_progress;
pub use scan::scan_with_retry;
pub use settings::BluetoothRange;
pub use settings::CalibrationData;
pub use settings::DeviceSettings;
pub use settings::MeasurementInterval;
pub use traits::AranetDevice;
pub use advertisement::AdvertisementData;
pub use advertisement::parse_advertisement;
pub use advertisement::parse_advertisement_with_name;
pub use commands::HISTORY_V1_REQUEST;
pub use commands::HISTORY_V2_REQUEST;
pub use commands::SET_BLUETOOTH_RANGE;
pub use commands::SET_INTERVAL;
pub use commands::SET_SMART_HOME;
pub use events::DeviceEvent;
pub use events::EventReceiver;
pub use events::EventSender;
pub use guard::DeviceGuard;
pub use guard::SharedDeviceGuard;
pub use manager::DeviceManager;
pub use manager::ManagedDevice;
pub use manager::ManagerConfig;
pub use messages::CachedDevice;
pub use messages::Command;
pub use messages::SensorEvent;
pub use metrics::ConnectionMetrics;
pub use metrics::OperationMetrics;
pub use mock::MockDevice;
pub use mock::MockDeviceBuilder;
pub use reconnect::ReconnectOptions;
pub use reconnect::ReconnectingDevice;
pub use retry::RetryConfig;
pub use retry::with_retry;
pub use streaming::ReadingStream;
pub use streaming::StreamOptions;
pub use streaming::StreamOptionsBuilder;
pub use thresholds::Co2Level;
pub use thresholds::ThresholdConfig;
pub use thresholds::Thresholds;
pub use util::create_identifier;
pub use util::format_peripheral_id;
pub use validation::ReadingValidator;
pub use validation::ValidationResult;
pub use validation::ValidationWarning;

Modules§

advertisement
BLE advertisement data parsing for passive monitoring.
commands
BLE command constants for Aranet devices.
device
Aranet device connection and communication.
error
Error types for aranet-core.
events
Device event system for connection and reading notifications.
guard
Connection guard for automatic disconnect on drop.
history
Historical data download.
manager
Multi-device management.
messages
Message types for UI/worker communication.
metrics
Connection and operation metrics tracking.
mock
Mock device implementation for testing.
readings
Reading current sensor values.
reconnect
Automatic reconnection handling for Aranet devices.
retry
Retry logic for BLE operations.
scan
Device discovery and scanning.
settings
Device settings read/write.
streaming
Real-time streaming of sensor readings via BLE notifications.
thresholds
CO2 level thresholds and categorization.
traits
Trait abstractions for Aranet device operations.
types
Core types for Aranet sensor data.
util
Utility functions for aranet-core.
uuid
Bluetooth UUIDs for Aranet devices.
uuids
Bluetooth UUIDs for Aranet devices.
validation
Data validation and bounds checking for sensor readings.

Structs§

CurrentReading
Current reading from an Aranet sensor.
DeviceInfo
Device information from an Aranet sensor.
HistoryRecord
A historical reading record from an Aranet sensor.

Enums§

DeviceType
Type of Aranet device.
Status
CO2 level status indicator.

Type Aliases§

SharedDevice
Type alias for a shared device reference.