Add new motion command to set PIR sensor ON or OFF on battery powered camera

tested on reolink argus pro
This commit is contained in:
Joris Bremond committed 2022-05-09 22:38:28 +02:00
1 parent a8aa52aec7
commit 9f1bcd6f55
8 files changed
+212

No files matched your search

+1
View File
@@ -20,5 +20,6 @@ pub enum Command {
Rtsp(super::rtsp::Opt),
StatusLight(super::statusled::Opt),
Reboot(super::reboot::Opt),
Motion(super::motion::Opt),
Talk(super::talk::Opt),
}
+4
View File
@@ -17,6 +17,7 @@ use validator::Validate;
mod cmdline;
mod config;
mod reboot;
mod motion;
mod rtsp;
mod statusled;
mod talk;
@@ -64,6 +65,9 @@ fn main() -> Result<()> {
Some(Command::Reboot(opts)) => {
reboot::main(opts, config)?;
}
Some(Command::Motion(opts)) => {
motion::main(opts, config)?;
}
Some(Command::Talk(opts)) => {
talk::main(opts, config)?;
}
+23
View File
@@ -0,0 +1,23 @@
use anyhow::{anyhow, Result};
use structopt::StructOpt;
fn onoff_parse(src: &str) -> Result<bool> {
match src {
"true" | "on" | "yes" => Ok(true),
"false" | "off" | "no" => Ok(false),
_ => Err(anyhow!(
"Could not understand {}, check your input, should be true/false, on/off or yes/no",
src
)),
}
}
/// The motion command will control the motion status off the camera
#[derive(StructOpt, Debug)]
pub struct Opt {
/// The name of the camera. Must be a name in the config
pub camera: String,
/// Whether to turn the PIR ON or OFF
#[structopt(parse(try_from_str = onoff_parse), name = "on|off")]
pub on: bool,
}
+34
View File
@@ -0,0 +1,34 @@
///
/// # Neolink Motion
///
/// This module handles the controls of the motion alarm
///
///
/// # Usage
///
/// ```bash
/// # To turn the motion on
/// neolink motion --config=config.toml CameraName on
/// # Or off
/// neolink motion --config=config.toml CameraName off
/// ```
///
use anyhow::{Context, Result};
mod cmdline;
use super::config::Config;
use crate::utils::find_and_connect;
pub(crate) use cmdline::Opt;
/// Entry point for the motion subcommand
///
/// Opt is the command line options
pub(crate) fn main(opt: Opt, config: Config) -> Result<()> {
let mut camera = find_and_connect(&config, &opt.camera)?;
camera
.motion_set(opt.on)
.context("Unable to set camera motion state")?;
Ok(())
}