]> the.earth.li Git - mqttdeck.git/commitdiff
Add automatic MQTT reconnection
authorJonathan McDowell <noodles@earth.li>
Wed, 31 Jul 2024 08:22:09 +0000 (09:22 +0100)
committerJonathan McDowell <noodles@earth.li>
Wed, 31 Jul 2024 08:22:09 +0000 (09:22 +0100)
If the MQTT server goes away we want to try and reconnect automatically.

src/main.rs

index 89fc007fd70fcbe1948a9878da7e38a17ae71575..ad2abc2b2c368409ab368fb3327a89637061edc4 100644 (file)
@@ -8,6 +8,7 @@ use elgato_streamdeck::{list_devices, new_hidapi, AsyncStreamDeck, StreamDeckInp
 use ini::Ini;
 use paho_mqtt as mqtt;
 use std::process;
+use std::time::Duration;
 
 #[derive(Parser)]
 struct Args {
@@ -77,6 +78,7 @@ async fn main() {
         .user_name(&conf["MQTT"]["username"])
         .password(&conf["MQTT"]["password"])
         .will_message(lwt_msg)
+        .automatic_reconnect(Duration::new(2,0), Duration::new(60,0))
         .finalize();
 
     if let Err(err) = cli.connect(conn_opts).wait() {