huawei-dongle-api
A robust async Rust client library for interacting with Huawei LTE dongles and routers.
This library provides a type-safe, async interface to the XML-based API used by Huawei HiLink devices such as the E3372, E5577, B525 and many others. It handles authentication, session management, and CSRF token rotation automatically.
Features
- Async/await - Built on tokio for efficient async I/O
- Automatic retry - Configurable retry logic with exponential backoff
- Session management - Automatic CSRF token handling and refresh
- Type safety - Strongly typed requests and responses with enums
- Error handling - Comprehensive error types with automatic recovery
- Device compatibility - Handles quirks across different firmware versions
- Strong types - Enums for all API values (connection status, network types, etc.)
Installation
Add this to your Cargo.toml:
[]
= "0.2"
= { = "1", = ["full"] }
Quick Start
use ;
async
Configuration
The client can be configured with custom settings:
use ;
use Duration;
let config = builder
.base_url
.timeout
.max_retries
.retry_delay
.build?;
let client = new?;
Authentication
Most endpoints require authentication. The library handles this automatically, retrying with fresh tokens when needed:
// Login (only needed for password-protected operations)
client.auth.login.await?;
// Access protected endpoints
use ;
let request = new;
let sms_list = client.sms.list.await?;
// Logout when done
client.auth.logout.await?;
Examples
Monitoring Connection Status
let status = client.monitoring.status.await?;
println!;
println!;
println!;
if status.is_connected
SMS Management
use ;
// Get SMS count
let count = client.sms.count.await?;
println!;
// List messages
let request = new;
let messages = client.sms.list.await?;
for msg in &messages.messages.messages
// Delete a message
client.sms.delete.await?;
Network Configuration
// Get current network mode
let net_mode = client.network.get_mode.await?;
println!;
// Switch network mode (for IP rotation)
use NetworkModeRequest;
let request = lte_only;
client.network.set_mode.await?;
DHCP Configuration
// Get current DHCP settings
let settings = client.dhcp.settings.await?;
println!;
// Change gateway IP
use DhcpSettingsRequest;
use ;
let new_settings = new;
client.dhcp.set_settings.await?;
Error Handling
The library provides comprehensive error handling with automatic recovery:
match client.monitoring.status.await
Supported Devices
This library has been tested with:
- Huawei E3372h-320
- Huawei E5577
- Huawei B525
It should work with any Huawei HiLink device that uses the same XML API.
Thread Safety
The client is thread-safe and can be shared across multiple tasks:
use Arc;
let client = new;
let client2 = client.clone;
spawn;
Used In Production
This library powers the mobile proxy infrastructure at Scraping Fish API, a high-performance web scraping API service.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.