tasmota-mqtt-client

Crates.iotasmota-mqtt-client
lib.rstasmota-mqtt-client
version0.1.0
sourcesrc
created_at2024-10-30 18:30:31.848624
updated_at2024-10-30 18:30:31.848624
descriptionRust library for interacting with tasmota devices over MQTT
homepage
repositoryhttps://github.com/icewind1991/tasmota-mqtt-client
max_upload_size
id1428966
size56,134
Robin Appelman (icewind1991)

documentation

README

tasmota-mqtt-client

Rust library for interacting with tasmota devices over MQTT

Supported features

  • Device discovery
  • Query device name
  • Query device ip
  • Backup device config

Example

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(())
}
Commit count: 19

cargo fmt