Skip to content

Commit

Permalink
Blink PiTInfo LED on message publish
Browse files Browse the repository at this point in the history
  • Loading branch information
angristan committed Mar 24, 2024
1 parent 4b1d5d6 commit b22d7f0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -10,6 +10,7 @@
async-stream = "0.3.5"
bincode = "1.3.3"
futures-util = "0.3.30"
rppal = "0.17.1"
rumqttc = "0.24.0"
serde = { version = "1.0.197", features = ["derive"] }
serialport = "4.3.0"
Expand Down
22 changes: 19 additions & 3 deletions src/mqtt/publish.rs
@@ -1,7 +1,11 @@
use crate::teleinfo::parser::TeleinfoFrame;
use aimeqtt::client::Client;
use rppal::gpio::Gpio;
use std::thread;
use std::time::Duration;
use tokio::task;

use crate::teleinfo::parser::TeleinfoFrame;
const GPIO_PITINFO_GREEN_LED: u8 = 4;

pub fn publish_teleinfo(client: &Client, value: TeleinfoFrame) {
let client_clone = (*client).clone();
Expand All @@ -10,8 +14,20 @@ pub fn publish_teleinfo(client: &Client, value: TeleinfoFrame) {
client_clone.publish(format!("teleinfo/{}", value.adco), value.to_string());

match publish_res {
Ok(_) => println!("Published"),
Err(e) => println!("Error: {:?}", e),
Ok(_) => {
println!("Published MQTT message");

let mut pin = Gpio::new()
.unwrap()
.get(GPIO_PITINFO_GREEN_LED)
.unwrap()
.into_output();

pin.set_high();
thread::sleep(Duration::from_millis(10));
pin.set_low();
}
Err(e) => eprintln!("Error: {:?}", e),
}
});
}

0 comments on commit b22d7f0

Please sign in to comment.