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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
// Copyright 2019-2026 Apilium Technologies OÜ. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR Commercial
//! # AIngle Minimal - Ultra-Lightweight IoT Node
//!
//! Minimal AIngle node implementation optimized for resource-constrained IoT devices.
//!
//! ## Overview
//!
//! This crate provides a complete AIngle node that runs on devices with **less than 1MB RAM**,
//! making it suitable for ESP32, Arduino, Raspberry Pi Pico, and similar embedded systems.
//!
//! ## Features
//!
//! - **Ultra-light footprint**: Target <512KB RAM, <5MB storage
//! - **Sub-second confirmation**: Configurable publish intervals (default 5s)
//! - **Zero-fee transactions**: No staking or gas fees required
//! - **Mesh networking**: WiFi Direct, BLE, LoRa, Zigbee support
//! - **Battery-aware**: Adaptive power modes (deep sleep, light sleep, active)
//! - **CoAP Protocol**: Lightweight alternative to HTTP for IoT
//! - **DTLS Security**: Encrypted communications with PSK or certificates
//! - **OTA Updates**: Secure over-the-air firmware updates
//! - **Smart Agents**: Optional AI capabilities for edge intelligence
//!
//! ## Quick Start
//!
//! ```rust,ignore
//! use aingle_minimal::{MinimalNode, Config};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create node with IoT-optimized config
//! let config = Config::iot_mode();
//! let mut node = MinimalNode::new(config)?;
//!
//! // Run the node
//! smol::block_on(node.run())?;
//! Ok(())
//! }
//! ```
//!
//! ## Advanced Examples
//!
//! ### Sensor Integration
//!
//! ```rust,ignore
//! use aingle_minimal::{MinimalNode, SensorManager, SensorType, Config};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut node = MinimalNode::new(Config::iot_mode())?;
//! let mut sensors = SensorManager::new();
//!
//! // Add temperature sensor
//! sensors.add_sensor(SensorType::Temperature, 0x48)?;
//!
//! // Read and publish sensor data
//! let reading = sensors.read(SensorType::Temperature)?;
//! node.publish_sensor_data(reading)?;
//! Ok(())
//! }
//! ```
//!
//! ### CoAP Server
//!
//! ```rust,ignore
//! use aingle_minimal::{CoapServer, CoapConfig};
//!
//! async fn run() -> Result<(), Box<dyn std::error::Error>> {
//! let config = CoapConfig::default();
//! let server = CoapServer::new(config).await?;
//!
//! // Register resource handlers
//! server.register_resource("/temperature", |req| {
//! // Handle GET /temperature
//! Ok("23.5".into())
//! });
//!
//! server.run().await?;
//! Ok(())
//! }
//! ```
//!
//! ### Power Management
//!
//! ```rust,ignore
//! use aingle_minimal::{PowerManager, PowerProfile, BatteryInfo};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut power = PowerManager::new();
//!
//! // Check battery and adjust power mode
//! let battery = power.battery_info()?;
//! if battery.percentage < 20.0 {
//! power.set_profile(PowerProfile::PowerSave)?;
//! }
//!
//! // Sleep when idle
//! power.sleep(std::time::Duration::from_secs(10))?;
//! Ok(())
//! }
//! ```
//!
//! ### Smart Agent (Edge AI)
//!
//! ```rust,ignore
//! use aingle_minimal::{SmartNode, SmartNodeConfig, SensorAdapter};
//!
//! let config = SmartNodeConfig::default();
//! let mut smart_node = SmartNode::new(config)?;
//!
//! // Agent learns from sensor patterns
//! let adapter = SensorAdapter::new();
//! smart_node.attach_sensor(adapter);
//!
//! // Run agent loop
//! loop {
//! smart_node.step()?;
//! smol::Timer::after(std::time::Duration::from_secs(1)).await;
//! }
//! ```
//!
//! ## Memory Budget
//!
//! | Component | Budget |
//! |-----------|--------|
//! | Runtime | 128KB |
//! | Crypto | 64KB |
//! | Network | 128KB |
//! | Storage | 128KB |
//! | App | 64KB |
//! | **Total** | **512KB** |
//!
//! ## Feature Flags
//!
//! | Feature | Description | Dependencies |
//! |---------|-------------|--------------|
//! | `coap` | CoAP server and client (default) | coap-lite |
//! | `sqlite` | SQLite storage backend | rusqlite |
//! | `rocksdb` | RocksDB storage backend (faster) | rocksdb |
//! | `webrtc` | WebRTC transport for browsers | webrtc, bytes |
//! | `ble` | Bluetooth LE for Desktop (macOS/Linux/Windows) | btleplug, uuid |
//! | `ble-esp32` | Bluetooth LE for ESP32 devices | esp32-nimble |
//! | `hw_wallet` | Hardware wallet support (Ledger/Trezor) | ledger-transport-hid |
//! | `ai_memory` | Ineru memory system for agents | ineru |
//! | `smart_agents` | Kaneru agents integration | kaneru |
//! | `no_std` | Compile without standard library | - |
//!
//! ## Platform Support
//!
//! | Platform | Target | BLE Feature |
//! |----------|--------|-------------|
//! | macOS | x86_64-apple-darwin, aarch64-apple-darwin | `ble` |
//! | Linux | x86_64-unknown-linux-gnu | `ble` |
//! | Windows | x86_64-pc-windows-msvc | `ble` |
//! | ESP32 | xtensa-esp32-espidf | `ble-esp32` |
//! | ESP32-C3 | riscv32imc-esp-espidf | `ble-esp32` |
//! | ESP32-S3 | xtensa-esp32s3-espidf | `ble-esp32` |
//! | Raspberry Pi Pico | thumbv6m-none-eabi | - |
//!
//! ## ESP32 Setup (ble-esp32 feature)
//!
//! To compile for ESP32 with Bluetooth LE support:
//!
//! ### 1. Install ESP-IDF Toolchain
//! ```bash
//! # Install espup (ESP Rust toolchain installer)
//! cargo install espup
//! espup install
//!
//! # Source the environment
//! . $HOME/export-esp.sh
//! ```
//!
//! ### 2. Create sdkconfig.defaults
//! ```text
//! CONFIG_BT_ENABLED=y
//! CONFIG_BT_BLE_ENABLED=y
//! CONFIG_BT_BLUEDROID_ENABLED=n
//! CONFIG_BT_NIMBLE_ENABLED=y
//! CONFIG_BT_NIMBLE_NVS_PERSIST=y
//! ```
//!
//! ### 3. Build for ESP32
//! ```bash
//! cargo build --target xtensa-esp32-espidf --features ble-esp32
//! ```
extern crate alloc;
// REST API server for SDK integration
// Storage - trait is always available
// Storage backends (feature-gated)
// Storage factory for dynamic backend selection
// Re-export storage types
pub use StorageBackendType;
pub use DynamicStorage;
pub use ;
// Re-exports
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use IoTMemory;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use *;
pub use ;
pub use ;
pub use ;
/// Version information for the crate.
///
/// # Examples
///
/// ```
/// # use aingle_minimal::VERSION;
/// println!("AIngle Minimal version: {}", VERSION);
/// ```
pub const VERSION: &str = env!;
/// Minimum supported Rust version.
///
/// This crate requires at least Rust 1.85 to compile.
pub const MSRV: &str = "1.85";
/// Target memory budget in bytes (512KB).
///
/// This is the design goal for the node's total memory footprint,
/// making it suitable for resource-constrained IoT devices.
///
/// See [`Config::memory_limit`](crate::Config::memory_limit) to configure
/// the actual memory limit for a node.
pub const MEMORY_BUDGET: usize = 512 * 1024; // 512KB
/// Environment variable for configuring publish interval.
///
/// Set this to a number of milliseconds to override the default publish interval.
///
/// # Examples
///
/// ```bash
/// # Set publish interval to 1 second
/// export AINGLE_PUBLISH_INTERVAL_MS=1000
/// ```
pub const ENV_PUBLISH_INTERVAL: &str = "AINGLE_PUBLISH_INTERVAL_MS";
/// Environment variable for enabling IoT mode.
///
/// When set (to any value), the node will use [`Config::iot_mode()`] as its base
/// configuration instead of the default.
///
/// # Examples
///
/// ```bash
/// # Enable IoT mode
/// export AINGLE_IOT_MODE=1
/// ```
pub const ENV_IOT_MODE: &str = "AINGLE_IOT_MODE";