tuya-rs
Tuya v3.3 local protocol implementation in Rust.
Provides UDP device discovery, TCP connection, packet encoding/decoding, and AES-ECB encryption for communicating with Tuya-based IoT devices on the local network.
Part of the robottino-rs workspace.
Usage
Discover devices on the network
use discovery;
use Duration;
let devices = discover?;
for dev in &devices
No credentials needed — devices broadcast their ID and IP via UDP every ~5 seconds. The local_key must be obtained separately (via cloud API or tinytuya).
Connect and send commands
use ;
let config = DeviceConfig ;
let mut conn = connect?;
let response = conn.send?;
println!;
Cloud API: get the local key
With the cloud feature, you can obtain the local_key via Tuya's OEM Mobile API:
use ;
let creds = OemCredentials ;
let mut api = new;
let _session = api.login?;
let homes = api.list_homes?;
let devices = api.list_devices?;
println!;
The OEM credentials must be extracted from the Android APK — see the workspace README for details. The xplorer-rs crate provides pre-filled credentials for the X-Plorer app via xplorer_oem_credentials().
Features
| Flag | Description |
|---|---|
| (default) | UDP device discovery, TCP packet codec, AES-128-ECB encryption, CRC32 validation |
cloud |
OEM Mobile API client: login flow, device/home listing, HMAC-SHA256 request signing, AWS STS credentials for map storage |
Modules
discovery— UDP broadcast listener: find devices on the local network (ports 6666/6667)connection—DeviceConfig,TuyaConnection(TCP),TuyaPacketencode/decode,TuyaCommandenumcrypto— AES-128-ECB with PKCS7 padding, hex encodingapi(cloud) — OEM Mobile API: login, device listing, device control (publish_dps,device_info), AWS4 pre-signed URL generationsigning(cloud) — HMAC-SHA256 request signing with Tuya's custom sign string format