Skip to content

Commit

Permalink
Better handle err on publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordy F committed Nov 19, 2024
1 parent e499813 commit 896fddc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl RunArgs {

task::spawn(async move {
let mut interval = time::interval(Duration::from_millis(1000));
let mut last_output_value: u8 = 0;
let mut last_output_value: Option<u8> = None;
loop {
interval.tick().await;

Expand All @@ -56,10 +56,10 @@ impl RunArgs {
.clamp(0.0, 100.0)
.round() as u8;

if last_output_value != output {
if last_output_value != Some(output) {
debug!("Emitting new output value: {}", output);
last_output_value = output;
if let Err(e) = client

match client
.publish(
output_topic.clone(),
QoS::AtLeastOnce,
Expand All @@ -68,7 +68,8 @@ impl RunArgs {
)
.await
{
error!("Failed to publish to MQTT topic: {}", e);
Err(e) => error!("Failed to publish to MQTT topic: {}", e),
Ok(_) => last_output_value = Some(output),
}
}
}
Expand Down

0 comments on commit 896fddc

Please sign in to comment.