feat: add webhooks with basic json to send to
This commit is contained in:
parent
18aa3dfaa8
commit
1b0284b00b
7 changed files with 1432 additions and 10 deletions
16
src/main.rs
16
src/main.rs
|
|
@ -1,4 +1,5 @@
|
|||
mod gpio;
|
||||
mod webhook;
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
|
|
@ -7,24 +8,29 @@ use tracing::{error, info};
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// Initialize logging
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
// Initialize GPIO monitor
|
||||
const DEFAULT_GPIO_PIN: u8 = 17;
|
||||
let gpio_pin = std::env::var("GPIO_PIN")
|
||||
.ok()
|
||||
.and_then(|v| v.parse().ok())
|
||||
.unwrap_or(DEFAULT_GPIO_PIN);
|
||||
|
||||
let webhook_notifier = webhook::WebhookNotifier::new()?;
|
||||
let mut gpio_monitor = gpio::GpioMonitor::new(gpio_pin, Duration::from_millis(100))?;
|
||||
|
||||
// Simple callback function that just logs the event
|
||||
let callback = |event: gpio::CircuitEvent| {
|
||||
let callback = move |event: gpio::CircuitEvent| {
|
||||
info!("Circuit state changed: {:?}", event);
|
||||
|
||||
// Clone the webhook notifier for the async block
|
||||
let notifier = webhook_notifier.clone();
|
||||
|
||||
// Spawn a new task to send webhooks
|
||||
tokio::spawn(async move {
|
||||
notifier.notify_all("circuit_state_change", event).await;
|
||||
});
|
||||
};
|
||||
|
||||
// Start GPIO monitoring
|
||||
if let Err(e) = gpio_monitor.monitor(callback).await {
|
||||
error!("GPIO monitoring error: {}", e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue