Files
pilot/test_mqtt.rs
2026-01-10 20:24:11 +01:00

19 lines
645 B
Rust

use rumqttc::{AsyncClient, MqttOptions, QoS};
use tokio::time::{timeout, Duration};
#[tokio::main]
async fn main() {
let mut mqttoptions = MqttOptions::new("test_client", "10.0.0.3", 1883);
mqttoptions.set_keep_alive(Duration::from_secs(60));
let (client, mut eventloop) = AsyncClient::new(mqttoptions, 10);
println!("Trying to connect to MQTT broker...");
match timeout(Duration::from_secs(10), eventloop.poll()).await {
Ok(Ok(event)) => println!("Connected! Event: {:?}", event),
Ok(Err(e)) => println!("Connection error: {:?}", e),
Err(_) => println!("Timeout waiting for connection"),
}
}