Skip to main content

alarm_remote_control/
alarm_remote_control.rs

1use dvrip_rs::{Alarm, Authentication, Connection, DVRIPCam};
2use std::time::Duration;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let args: Vec<String> = std::env::args().collect();
7    if args.len() < 4 {
8        println!("Usage: {} <IP> <Username> <Password>", args[0]);
9        return Ok(());
10    }
11
12    let ip = &args[1];
13    let user = &args[2];
14    let pass = &args[3];
15
16    let mut cam = DVRIPCam::new(ip);
17
18    cam.connect(Duration::from_secs(5)).await?;
19    cam.login(user, pass).await?;
20
21    println!("Attempting to trigger the device's remote alarm/siren output...");
22
23    match cam.set_remote_alarm(true).await {
24        Ok(true) => println!("Alarm activated! Check your device."),
25        Ok(false) => println!("Command sent but device returned failure."),
26        Err(e) => eprintln!("Error sending command: {}", e),
27    }
28
29    println!("Waiting 5 seconds before deactivating...");
30    tokio::time::sleep(Duration::from_secs(5)).await;
31
32    println!("Deactivating alarm...");
33    let _ = cam.set_remote_alarm(false).await;
34
35    cam.close().await?;
36    println!("Done.");
37
38    Ok(())
39}