Add a mqtt command for waking up from idle
The command is `control/wakeup (mins)`
This commit is contained in:
2 files changed
+37
-4
No files matched your search
@@ -220,6 +220,8 @@ Control messages:
|
||||
- `/control/ptz/assign [id] [name]` Set the current PTZ position to a preset ID
|
||||
and name
|
||||
- `/control/pir [on|off]`
|
||||
- `control/wakeup (mins)` For cameras that are using `idle_disconnect` this will
|
||||
force a wakeup for at least the given minutes
|
||||
|
||||
Status Messages:
|
||||
|
||||
|
||||
+35
-4
@@ -64,7 +64,7 @@ use std::collections::{HashMap, HashSet};
|
||||
use tokio::{
|
||||
sync::mpsc::channel as mpsc,
|
||||
task::JoinSet,
|
||||
time::{interval, sleep, Duration, MissedTickBehavior},
|
||||
time::{interval, sleep, sleep_until, Duration, Instant, MissedTickBehavior},
|
||||
};
|
||||
use tokio_stream::{wrappers::IntervalStream, StreamExt};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
@@ -573,12 +573,15 @@ async fn handle_mqtt_message(
|
||||
match msg.as_ref() {
|
||||
MqttReplyRef {
|
||||
topic: _,
|
||||
message: "OK",
|
||||
message: message @ "OK",
|
||||
}
|
||||
| MqttReplyRef {
|
||||
topic: _,
|
||||
message: "FAIL",
|
||||
} => {
|
||||
message: message @ "FAIL",
|
||||
}
|
||||
| MqttReplyRef { topic: _, message }
|
||||
if message.starts_with("FAIL:") || message.starts_with("OK:") =>
|
||||
{
|
||||
// Do nothing for the success/fail replies
|
||||
}
|
||||
MqttReplyRef {
|
||||
@@ -957,6 +960,34 @@ async fn handle_mqtt_message(
|
||||
.await
|
||||
.with_context(|| "Failed to publish pir off")?;
|
||||
}
|
||||
MqttReplyRef {
|
||||
topic: "control/wakeup",
|
||||
message,
|
||||
} => {
|
||||
let reply = match message.parse::<u64>() {
|
||||
Ok(secs) => {
|
||||
let wake_time = Instant::now() + Duration::from_secs(secs * 60);
|
||||
if let Ok(permit) = camera.permit().await {
|
||||
tokio::task::spawn(async move {
|
||||
sleep_until(wake_time).await;
|
||||
drop(permit);
|
||||
});
|
||||
"OK"
|
||||
} else {
|
||||
"FAIL: Camera shutting down"
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Failed to parse minutes: {:?}", e);
|
||||
format!("FAIL: {e:?}")
|
||||
}
|
||||
};
|
||||
|
||||
mqtt.send_message("control/wakeup", &reply, false)
|
||||
.await
|
||||
.with_context(|| "Failed to publish wakeup")?;
|
||||
}
|
||||
MqttReplyRef {
|
||||
topic: "query/battery",
|
||||
..
|
||||
|
||||
Reference in new issue
Block a user