Expand description
§NLECloud SDK for Rust
An idiomatic, asynchronous, thread-safe Rust SDK for the NLECloud (新大陆物联网云平台) IoT platform.
§Overview
- Async & Non-blocking: Built on
tokioandreqwest(withrustls-tls). - Immutable Client:
NleCloudClientconfigured viaNleCloudClientBuilder. - Generic Envelope Unwrapping: Responses wrapped in upstream
ResultMsgenvelopes are automatically intercepted, mapping non-zero API statuses intoSdkError::Api. - Complete Model Coverage: Strongly typed structs matching all NLECloud DTOs,
including legacy PascalCase aliases (e.g.
DeviceInfoDTO) for easy migration.
§Modules & Core APIs
The client exposes operations across several domains:
| Module | Core Methods | Description |
|---|---|---|
api::auth | login, get_current_token | User authentication & token management |
api::projects | get_projects, add_project, get_project_sensors | Project lifecycle & hierarchy queries |
api::devices | get_devices, get_device_info, get_devices_status | Device CRUD & online status checks |
api::sensors | get_sensors, add_sensor_datas, get_sensor_datas | Sensor management & telemetry time-series |
api::commands | send_cmd | Actuator control & command dispatching |
§Quick Start
use nle_cloud_sdk::prelude::*;
#[tokio::main]
async fn main() -> Result<()> {
// 1. Build an unauthenticated client
let client = NleCloudClient::builder()
.base_url("http://api.nlecloud.com")
.build()?;
// 2. Authenticate
let login_res = client.login_with_credentials("your_account", "your_password", false).await?;
println!("Logged in! Token: {}", login_res.access_token);
// 3. Create an authenticated client clone
let auth_client = client.with_token(login_res.access_token);
// 4. Query sensors for a device
let sensors = auth_client.get_sensors(10367, None, None).await?;
println!("Sensors found: {}", sensors.len());
// 5. Dispatch an actuator command (e.g. Turn On = 1)
auth_client.send_cmd(10367, "nl_fan", &1, None).await?;
Ok(())
}Re-exports§
pub use client::DEFAULT_BASE_URL;pub use client::DEFAULT_TIMEOUT;pub use client::NleCloudClient;pub use client::NleCloudClientBuilder;pub use error::Result;pub use error::SdkError;pub use models::*;
Modules§
- api
- API extension traits and methods for
crate::client::NleCloudClient. - client
- Core HTTP client, configuration builder, and request execution logic.
- error
- Error types and Result alias for the NLECloud SDK.
- models
- Strongly typed Data Transfer Objects (DTOs) for the NLECloud RESTful API.
- prelude
- Convenient prelude module for re-exporting common types.
- utils
- Utility functions for datetime parsing and Serde serialization.