| Crates.io | tasmota-mqtt-client |
| lib.rs | tasmota-mqtt-client |
| version | 0.1.0 |
| created_at | 2024-10-30 18:30:31.848624+00 |
| updated_at | 2024-10-30 18:30:31.848624+00 |
| description | Rust library for interacting with tasmota devices over MQTT |
| homepage | |
| repository | https://github.com/icewind1991/tasmota-mqtt-client |
| max_upload_size | |
| id | 1428966 |
| size | 56,134 |
Rust library for interacting with tasmota devices over MQTT
use std::pin::pin;
use tasmota_mqtt_client::{DeviceUpdate, Result, TasmotaClient};
use tokio::join;
use tokio_stream::StreamExt;
#[tokio::main]
async fn main() -> Result<()> {
let client = TasmotaClient::connect(
"mqtt.example.com",
1883,
Some(("mqtt_username", "mqtt_password")),
)
.await?;
let mut discovery = pin!(client.devices());
while let Some(update) = discovery.next().await {
match update {
DeviceUpdate::Added(device) => {
let (ip, name) = join!(client.device_ip(&device), client.device_name(&device));
println!("discovered {}({device}) with ip {}", name?, ip?);
}
DeviceUpdate::Removed(device) => {
println!("{device} has gone offline");
}
}
}
Ok(())
}