Add control/preset command to mqtt

This commit is contained in:
Daniel Kaiser committed 2023-05-24 19:12:24 +02:00
1 parent aee14bb411
commit 27dc4c2bca
3 files changed
+26

No files matched your search

+1
View File
@@ -190,6 +190,7 @@ Control messages:
- `/control/reboot` Reboot the camera - `/control/reboot` Reboot the camera
- `/control/ptz [up|down|left|right|in|out]` (amount) Control the PTZ - `/control/ptz [up|down|left|right|in|out]` (amount) Control the PTZ
movements, amount defaults to 32.0 movements, amount defaults to 32.0
- `/control/preset [id]` Move to PTZ preset `id`
- `/control/pir [on|off]` - `/control/pir [on|off]`
Status Messages: Status Messages:
+9
View File
@@ -30,6 +30,7 @@ pub(crate) enum Messages {
PIROff, PIROff,
PIRQuery, PIRQuery,
Ptz(Direction), Ptz(Direction),
Preset(i8),
} }
#[derive(Debug, Copy, Clone)] #[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(), _ => "UNKNOWN COMMAND".to_string(),
}; };
if let Some(replier) = replier { if let Some(replier) = replier {
+16
View File
@@ -14,6 +14,7 @@
/// - `/control/ir [on|off|auto]` Turn IR lights on/off or automatically via light detection /// - `/control/ir [on|off|auto]` Turn IR lights on/off or automatically via light detection
/// - `/control/reboot` Reboot the camera /// - `/control/reboot` Reboot the camera
/// - `/control/ptz` [up|down|left|right|in|out] (amount) Control the PTZ movements, amount defaults to 32.0 /// - `/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: /// Status Messages:
/// ///
@@ -325,6 +326,21 @@ async fn handle_mqtt_message(
error!("No PTZ Direction given. Please add up/down/left/right/in/out"); 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 { MqttReplyRef {
topic: "control/pir", topic: "control/pir",
message: "on", message: "on",