From d55540a6c054680cdcbf303986b57fc82f5292ef Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Fri, 13 Jan 2023 00:02:34 +0100 Subject: [PATCH] If connection is lost to the mqtt server, attempt to reconnect instead of panicking --- src/mqtt.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/mqtt.rs b/src/mqtt.rs index 00eb91e..f20f6c9 100644 --- a/src/mqtt.rs +++ b/src/mqtt.rs @@ -1,6 +1,6 @@ use async_trait::async_trait; use serde::{Serialize, Deserialize}; -use tracing::{error, debug}; +use tracing::{debug, warn}; use rumqttc::{Publish, Event, Incoming, EventLoop}; use tokio::sync::broadcast; @@ -39,13 +39,12 @@ impl Mqtt { }, Ok(..) => continue, Err(err) => { - error!("{}", err); - break + // Something has gone wrong + // We stay in the loop as that will attempt to reconnect + warn!("{}", err); }, } } - - todo!("Error in MQTT (most likely lost connection to mqtt server), we need to handle these errors!"); }); } }