| Crates.io | kasa-core |
| lib.rs | kasa-core |
| version | 0.6.0 |
| created_at | 2026-01-11 01:00:13.322532+00 |
| updated_at | 2026-01-19 22:24:00.001629+00 |
| description | Core library for communicating with TP-Link Kasa smart devices |
| homepage | |
| repository | https://github.com/cmackenzie1/kasa-rs |
| max_upload_size | |
| id | 2035033 |
| size | 234,089 |
Core library for communicating with TP-Link Kasa smart home devices.
This crate implements the TP-Link Smart Home Protocol, which uses an XOR autokey cipher for encryption over TCP/UDP port 9999.
[dependencies]
kasa-core = "0.1.0"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
use kasa_core::{commands, send_command, discover, DEFAULT_PORT, DEFAULT_TIMEOUT, DEFAULT_DISCOVERY_TIMEOUT};
#[tokio::main]
async fn main() -> std::io::Result<()> {
// Discover devices on the local network
let devices = discover(DEFAULT_DISCOVERY_TIMEOUT).await?;
for device in &devices {
println!("Found: {} ({}) at {}", device.alias, device.model, device.ip);
}
// Send a command to a specific device
let response = send_command(
"192.168.1.100",
DEFAULT_PORT,
DEFAULT_TIMEOUT,
commands::INFO,
).await?;
println!("{}", response);
// Turn on the relay
send_command(
"192.168.1.100",
DEFAULT_PORT,
DEFAULT_TIMEOUT,
commands::RELAY_ON,
).await?;
Ok(())
}
The commands module provides constants for common operations:
| Command | Description |
|---|---|
INFO |
Get system information |
RELAY_ON |
Turn relay on |
RELAY_OFF |
Turn relay off |
ENERGY |
Get real-time energy readings |
LED_ON |
Turn LED indicator on |
LED_OFF |
Turn LED indicator off |
TIME |
Get device time |
SCHEDULE |
Get schedule rules |
COUNTDOWN |
Get countdown rules |
ANTITHEFT |
Get anti-theft rules |
CLOUDINFO |
Get cloud connection info |
WLANSCAN |
Scan for wireless networks |
REBOOT |
Reboot the device |
RESET |
Factory reset the device |
ENERGY_RESET |
Reset energy meter statistics |
RUNTIME_RESET |
Reset runtime statistics |
The following devices have been tested, but others using the same protocol should work:
MIT