2 个不稳定版本
0.2.0 | 2024 年 4 月 17 日 |
---|---|
0.1.0 | 2023 年 3 月 15 日 |
#604 in 网络编程
每月 93 次下载
37KB
647 代码行
一个 CLI 工具和一个库,用于通过 WiFi 控制TP-Link HS110(和 HS100)智能插座
构建
cargobuild
使用示例
顶级命令
$ cargo run -q
TP-Link Kasa HS110 client
Usage: tplink-hs110 [OPTIONS] <HOST> <COMMAND>
Commands:
info Get smartplug system information
led Get and manage LED state
power Get and manage power state
cloudinfo Get cloud information
wifi Scan and list available wifi stations
reboot Reboot a smart plug (causes power interruption for connected devices)
factory-reset Reset device to factory settings
emeter Get energy meter readings (voltage, current, power)
help Print this message or the help of the given subcommand(s)
Arguments:
<HOST> Hostname or an IP address of the smartplug
Options:
-p, --port <NUMBER> TCP port number [default: 9999]
-h, --help Print help
一般信息
$ cargo run -q 192.168.0.155 info
{
"system": {
"get_sysinfo": {
"active_mode": "schedule",
"alias": "Bathroom",
"dev_name": "Wi-Fi Smart Plug With Energy Monitoring",
"deviceId": "700644160CBBBB3AC78D5DFB15345D6C191F906B",
"err_code": 0,
"feature": "TIM:ENE",
"fwId": "00000000000000000000000000000000",
"hwId": "75E20DA8182494D2E82677B52A0B2EB6",
"hw_ver": "1.0",
"icon_hash": "",
"latitude": 48.784857,
"led_off": 0,
"longitude": 34.184122,
"mac": "70:4F:57:58:C6:FA",
"model": "HS110(EU)",
"oemId": "3D301ECA121C0642C12E31CE2430347D",
"on_time": 2262647,
"relay_state": 1,
"rssi": -69,
"sw_ver": "1.2.6 Build 200727 Rel.120821",
"type": "IOT.SMARTPLUGSWITCH",
"updating": 0
}
}
}
LED 灯
$ cargo run -q 192.168.0.155 led --help
Get and manage LED state
Usage: tplink-hs110 <HOST> led [OPTIONS]
Options:
-1, --on Turn LED on
-0, --off Turn LED off
-h, --help Print help
$ cargo run -q 192.168.0.155 led
LED is ON
$ cargo run -q 192.168.0.155 led --off
Operation has succeeded
LED is OFF
$ cargo run -q 192.168.0.155 led --on
Operation has succeeded
LED is ON
电源状态
$ cargo run -q 192.168.0.155 power --help
Get and manage power state
Usage: tplink-hs110 <HOST> power [OPTIONS]
Options:
-1, --on Turn power on
-0, --off Turn power off
-h, --help Print help
$ cargo run -q 192.168.0.155 power
Power is OFF
$ cargo run -q 192.168.0.155 power --on
Operation has succeeded
Power is ON
$ cargo run -q 192.168.0.155 power --off
Operation has succeeded
Power is OFF
云信息
$ cargo run -q 192.168.0.122 cloudinfo
{
"binded": 1,
"cld_connection": 1,
"err_code": 0,
"fwDlPage": "",
"fwNotifyType": 0,
"illegalType": 0,
"server": "n-devs.tplinkcloud.com",
"stopConnect": 0,
"tcspInfo": "",
"tcspStatus": 1,
"username": "[email protected]"
}
扫描并列出附近的 Wi-Fi 接入点
$ cargo run -q 192.168.0.155 wifi --help
Scan and list available wifi stations
Usage: tplink-hs110 <HOST> wifi <COMMAND>
Commands:
scan Scan and list available wifi access points
list List available wifi access points without performing a scan
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
$ cargo run -q 192.168.0.155 wifi scan
[
{
"key_type": 3,
"ssid": "HomeKyiv"
},
{
"key_type": 3,
"ssid": "HUAWEI AX3"
},
{
"key_type": 3,
"ssid": "Keenetic-8785"
},
{
"key_type": 3,
"ssid": "Kyivstar-7C80"
},
{
"key_type": 2,
"ssid": "Kyivstar242"
},
{
"key_type": 3,
"ssid": "netis_2.4G_CC0EA8"
},
{
"key_type": 2,
"ssid": "TP-LINK_245"
},
{
"key_type": 3,
"ssid": "TP-Link_C1F3"
}
]
重启
$ cargo run -q 192.168.0.155 reboot --help
Reboot a smart plug (causes power interruption for connected devices)
Usage: tplink-hs110 <HOST> reboot [OPTIONS]
Options:
-d, --delay <NUMBER> Delay a reboot by NUMBER of seconds
-h, --help Print help
$ cargo run -q 192.168.0.155 reboot
Operation has succeeded
获取能量表读数
$ cargo run -q 192.168.0.155 emeter
{
"current": 0.027566,
"current_ma": 27.566,
"err_code": 0,
"power": 0.775979,
"power_mw": 775.9789999999999,
"total": 188.23,
"total_wh": 188230.0,
"voltage": 232.835569,
"voltage_mv": 232835.569
}
扩展命令列表
HS110/HS100 智能插座支持的完整命令列表可在 tplink-smarthome-commands.txt 中找到
目前库中只实现了这些命令的一小部分。
依赖项
~1.6–2.7MB
~51K SLoC