#智能家居 #涂鸦 #智慧生活

rust-tuyapi

本软件包是 codetheweb 开发的 NodeJS 实现的 Tuya API 的 Rust 版本。

19 个版本

0.9.0 2023年7月18日
0.8.3 2023年3月12日
0.8.2 2022年8月26日
0.8.1 2022年1月16日
0.4.1 2020年11月9日

#1282 in 解析器实现


用于 rust-tuya-mqtt

自定义许可

45KB
970

rust-tuyapi

Build Status

Rust 实现的 Tuya API,用于与 Tuya/Smart Life 设备通信。

致谢

@codetheweb,感谢其对协议的反向工程。

先决条件

您需要知道 Tuya 设备的密钥和 ID。根据我的经验,找到这些信息的最简单方法是:在逐步添加 Tuya 灯泡的指南中解释。


lib.rs:

Rust Tuyapi

此库可用于与 Tuya/智能家居设备交互。它使用 Tuya 协议版本 3.1 和 3.3 发送和接收设备消息。

示例

此示例展示如何打开墙壁插座。

// The dps value is device specific, this socket turns on with key "1"
let mut dps = HashMap::new();
dps.insert("1".to_string(), json!(true));
let current_time = SystemTime::now()
    .duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() as u32;

// Create the payload to be sent, this will be serialized to the JSON format
let payload = Payload::Struct(PayloadStruct{
       dev_id: "123456789abcdef".to_string(),
       gw_id: Some("123456789abcdef".to_string()),
       uid: None,
       t: Some(current_time),
       dp_id: None,
       dps: Some(dps),
       });
// Create a TuyaDevice, this is the type used to set/get status to/from a Tuya compatible
// device.
let tuya_device = TuyaDevice::create("ver3.3", Some("fedcba987654321"),
    IpAddr::from_str("192.168.0.123").unwrap())?;

// Set the payload state on the Tuya device, an error here will contain
// the error message received from the device.
tuya_device.set(payload, 0)?;

依赖关系

~4.5–8.5MB
~193K SLoC