Expand description
Convenience class for managing the MQTT connection
§Examples
use mqtt_manager::*;
use std::time::Duration;
async fn handle_msg_a(pubdata: Publish) {
println!("Received msg A: {:?}", pubdata.payload);
}
async fn handle_msg_b(pubdata: Publish) {
println!("Received msg A: {:?}", pubdata.payload);
}
#[tokio::main]
async fn main() {
let mut mgr = MqttManager::new("mqtt://localhost:1883/override_client_id");
mgr.subscribe("msg/a", 0, make_callback!(handle_msg_a)).await;
mgr.subscribe("msg/b", 0, make_callback!(handle_msg_b)).await;
mgr.publish("msg/a", "test", 0).await;
loop {
tokio::select! {
_ = mgr.process() => (),
_ = tokio::signal::ctrl_c() => {
mgr.disconnect().await;
break;
}
}
}
}
Macros§
- make_
callback - A macro to turn an async fn into a callback to be passed to
MqttManager::subscribe
Structs§
- Mqtt
Manager - The main MQTT manager struct
- Publish
- Publish packet
Type Aliases§
- Callback
Fn - Type for subscription callbacks. See
crate::make_callback