-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
186 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,12 @@ | ||
use crate::teleinfo::parser::TeleinfoFrame; | ||
use aimeqtt::client::Client; | ||
use rppal::gpio::Gpio; | ||
use std::thread; | ||
use std::time::Duration; | ||
use tokio::task; | ||
use aimeqtt::client::{Client, ClientError}; | ||
use tracing::{event, instrument, Level}; | ||
|
||
const GPIO_PITINFO_GREEN_LED: u8 = 4; | ||
#[instrument(skip(client))] | ||
pub async fn publish_teleinfo(client: &Client, value: &TeleinfoFrame) -> Result<(), ClientError> { | ||
event!(Level::INFO, "Publishing teleinfo frame to MQTT"); | ||
|
||
pub fn publish_teleinfo(client: &Client, value: TeleinfoFrame) { | ||
let client_clone = (*client).clone(); | ||
task::spawn(async move { | ||
let publish_res = client_clone | ||
.publish(format!("teleinfo/{}", value.adco), value.to_string()) | ||
.await; | ||
|
||
match publish_res { | ||
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), | ||
} | ||
}); | ||
client | ||
.publish(format!("teleinfo/{}", value.adco), value.to_string()) | ||
.await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters