Skip to content

Commit

Permalink
Add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lptr committed Aug 10, 2024
1 parent 72ca48f commit 1fbb807
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/kernel/mqtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ impl Mqtt {
}

pub async fn publish(&self, topic: &str, payload: Value) -> Result<MessageId> {
log::info!("Publishing message to topic: {:?}", topic);
let topic = format!("{}/{}", self.topic_root, topic);
self.mqtt
let message_id = self.mqtt
.lock()
.await
.publish(
Expand All @@ -87,17 +88,22 @@ impl Mqtt {
payload.to_string().as_bytes(),
)
.await
.map_err(anyhow::Error::from)
.map_err(anyhow::Error::from)?;
log::info!("Published message to topic {:?} with ID: {}", topic, message_id);
Ok(message_id)
}

pub async fn subscribe(&self, topic: &str) -> Result<MessageId> {
log::info!("Subscribing to topic: {:?}", topic);
let topic = format!("{}/{}", self.topic_root, topic);
self.mqtt
let message_id = self.mqtt
.lock()
.await
.subscribe(&topic, QoS::AtMostOnce)
.await
.map_err(anyhow::Error::from)
.map_err(anyhow::Error::from)?;
log::info!("Subscribed to topic: {:?} with message ID {}", topic, message_id);
Ok(message_id)
}
}

Expand Down

0 comments on commit 1fbb807

Please sign in to comment.