1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
//! 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
//!
//! | Device | Sensors |
//! |--------|---------|
//! | Aranet4 | CO₂, Temperature, Pressure, Humidity |
//! | Aranet2 | Temperature, Humidity |
//! | AranetRn+ | Radon (Bq/m³), Temperature, Pressure, Humidity |
//! | Aranet Radiation | Dose 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
//!
//! ```no_run
//! 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-export types and uuid modules from aranet-types for backwards compatibility
pub use types;
pub use uuid;
// Core exports
pub use ;
pub use ;
pub use ;
pub use ExtendedReading;
pub use ;
pub use ;
pub use AranetDevice;
/// Type alias for a shared device reference.
///
/// This is the recommended way to share a `Device` across multiple tasks.
/// Since `Device` intentionally does not implement `Clone` (to prevent
/// connection ownership ambiguity), wrapping it in `Arc` is the standard
/// pattern for concurrent access.
///
/// # Choosing the Right Device Type
///
/// This crate provides several device types for different use cases:
///
/// | Type | Use Case | Auto-Reconnect | Thread-Safe |
/// |------|----------|----------------|-------------|
/// | [`Device`] | Single command, short-lived | No | Yes (via Arc) |
/// | [`ReconnectingDevice`] | Long-running apps | Yes | Yes |
/// | [`SharedDevice`] | Sharing Device across tasks | No | Yes |
/// | [`DeviceManager`] | Managing multiple devices | Yes | Yes |
///
/// ## Decision Guide
///
/// ### Use [`Device`] when:
/// - Running a single command (read, history download)
/// - Connection lifetime is short and well-defined
/// - You'll handle reconnection yourself
///
/// ```no_run
/// # async fn example() -> aranet_core::Result<()> {
/// use aranet_core::Device;
/// let device = Device::connect("Aranet4 12345").await?;
/// let reading = device.read_current().await?;
/// device.disconnect().await?;
/// # Ok(())
/// # }
/// ```
///
/// ### Use [`ReconnectingDevice`] when:
/// - Building a long-running application (daemon, service)
/// - You want automatic reconnection on connection loss
/// - Continuous monitoring over extended periods
///
/// ```no_run
/// # async fn example() -> aranet_core::Result<()> {
/// use aranet_core::{AranetDevice, ReconnectingDevice, ReconnectOptions};
/// let options = ReconnectOptions::default();
/// let device = ReconnectingDevice::connect("Aranet4 12345", options).await?;
/// // Will auto-reconnect on connection loss
/// let reading = device.read_current().await?;
/// # Ok(())
/// # }
/// ```
///
/// ### Use [`SharedDevice`] when:
/// - Sharing a single [`Device`] across multiple async tasks
/// - You need concurrent reads but want one connection
///
/// ```no_run
/// # async fn example() -> aranet_core::Result<()> {
/// use aranet_core::{Device, SharedDevice};
/// use std::sync::Arc;
///
/// let device = Device::connect("Aranet4 12345").await?;
/// let shared: SharedDevice = Arc::new(device);
///
/// let shared_clone = Arc::clone(&shared);
/// tokio::spawn(async move {
/// let reading = shared_clone.read_current().await;
/// });
/// # Ok(())
/// # }
/// ```
///
/// ### Use [`DeviceManager`] when:
/// - Managing multiple devices simultaneously
/// - Need centralized connection/disconnection handling
/// - Building a multi-device monitoring application
///
/// ```no_run
/// # async fn example() -> aranet_core::Result<()> {
/// use aranet_core::DeviceManager;
/// let manager = DeviceManager::new();
/// manager.add_device("AA:BB:CC:DD:EE:FF").await?;
/// manager.add_device("11:22:33:44:55:66").await?;
/// // Manager handles connections for all devices
/// # Ok(())
/// # }
/// ```
pub type SharedDevice = Arc;
// New module exports
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
// Re-export from aranet-types
pub use uuid as uuids;
pub use ;