Add control/preset command to mqtt
This commit is contained in:
1 parent
aee14bb411
commit
27dc4c2bca
3 files changed
+26
No files matched your search
@@ -190,6 +190,7 @@ Control messages:
|
||||
- `/control/reboot` Reboot the camera
|
||||
- `/control/ptz [up|down|left|right|in|out]` (amount) Control the PTZ
|
||||
movements, amount defaults to 32.0
|
||||
- `/control/preset [id]` Move to PTZ preset `id`
|
||||
- `/control/pir [on|off]`
|
||||
|
||||
Status Messages:
|
||||
|
||||
@@ -30,6 +30,7 @@ pub(crate) enum Messages {
|
||||
PIROff,
|
||||
PIRQuery,
|
||||
Ptz(Direction),
|
||||
Preset(i8),
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
@@ -449,6 +450,14 @@ impl<'a> MessageHandler<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
Messages::Preset(id) => {
|
||||
if let Err(e) = self.camera.set_ptz_preset(id, None).await {
|
||||
error = Some(format!("Failed to send PTZ preset: {:?}", e));
|
||||
"FAIL".to_string()
|
||||
} else {
|
||||
"OK".to_string()
|
||||
}
|
||||
}
|
||||
_ => "UNKNOWN COMMAND".to_string(),
|
||||
};
|
||||
if let Some(replier) = replier {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
/// - `/control/ir [on|off|auto]` Turn IR lights on/off or automatically via light detection
|
||||
/// - `/control/reboot` Reboot the camera
|
||||
/// - `/control/ptz` [up|down|left|right|in|out] (amount) Control the PTZ movements, amount defaults to 32.0
|
||||
/// - `/control/preset` [id] Move the camera to a known preset
|
||||
///
|
||||
/// Status Messages:
|
||||
///
|
||||
@@ -325,6 +326,21 @@ async fn handle_mqtt_message(
|
||||
error!("No PTZ Direction given. Please add up/down/left/right/in/out");
|
||||
}
|
||||
}
|
||||
MqttReplyRef {
|
||||
topic: "control/preset",
|
||||
message,
|
||||
} => {
|
||||
if let Ok(id) = message.parse::<i8>() {
|
||||
reply = Some(
|
||||
event_cam_sender
|
||||
.send_message_with_reply(Messages::Preset(id))
|
||||
.await
|
||||
.with_context(|| "Failed to send PTZ preset")?,
|
||||
);
|
||||
} else {
|
||||
error!("PTZ preset was not a valid number");
|
||||
}
|
||||
}
|
||||
MqttReplyRef {
|
||||
topic: "control/pir",
|
||||
message: "on",
|
||||
|
||||
Reference in new issue
Block a user