Skip to main content

Crate nle_cloud_sdk

Crate nle_cloud_sdk 

Source
Expand description

§NLECloud SDK for Rust

An idiomatic, asynchronous, thread-safe Rust SDK for the NLECloud (新大陆物联网云平台) IoT platform.

§Overview

  • Async & Non-blocking: Built on tokio and reqwest (with rustls-tls).
  • Immutable Client: NleCloudClient configured via NleCloudClientBuilder.
  • Generic Envelope Unwrapping: Responses wrapped in upstream ResultMsg envelopes are automatically intercepted, mapping non-zero API statuses into SdkError::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:

ModuleCore MethodsDescription
api::authlogin, get_current_tokenUser authentication & token management
api::projectsget_projects, add_project, get_project_sensorsProject lifecycle & hierarchy queries
api::devicesget_devices, get_device_info, get_devices_statusDevice CRUD & online status checks
api::sensorsget_sensors, add_sensor_datas, get_sensor_datasSensor management & telemetry time-series
api::commandssend_cmdActuator 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.