diff --git a/README.md b/README.md index d2a37e1..56d4549 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,8 @@ Query Messages: - `/query/battery` Request that the camera reports its battery level - `/query/pir` Request that the camera reports its pir status - `/query/ptz/preset` Request that the camera reports its PTZ presets +- `/query/preview` Request that the camera post a base64 encoded jpeg + of the stream to `/status/preview` now, ignoring the timer ### Controlling RTSP from MQTT diff --git a/src/mqtt/mod.rs b/src/mqtt/mod.rs index fa1f178..c932f10 100644 --- a/src/mqtt/mod.rs +++ b/src/mqtt/mod.rs @@ -31,6 +31,8 @@ //! `/query/battery` Request that the camera reports its battery level //! `/query/pir` Request that the camera reports its pir status //! `/query/ptz/preset` Request that the camera reports the PTZ presets +//! `/query/preview` Request that the camera post a base64 encoded jpeg +//! of the stream to `/status/preview` //! //! //! # Usage @@ -1052,6 +1054,41 @@ async fn handle_mqtt_message( .await .with_context(|| "Failed to publish ptz query")?; } + MqttReplyRef { + topic: "query/preview", + .. + } => { + let res = camera + .run_task(|cam| { + Box::pin(async move { + let data = cam.get_snapshot().await?; + AnyResult::Ok(data) + }) + }) + .await; + let reply = match res { + Err(e) => { + error!("Failed to get snapshot: {:?}", e); + "FAIL" + } + Ok(bytes) => { + if let Err(e) = mqtt + .send_message("status/preview", BASE64.encode(image).as_str(), true) + .await + .with_context(|| format!("{}: Failed to publish preview", camera_name)) + { + error!("Failed to send preview: {e:?}"); + "FAIL" + } else { + "OK" + } + } + } + .to_string(); + mqtt.send_message("query/preview", &reply, false) + .await + .with_context(|| "Failed to publish preview query")?; + } _ => {} } Ok(())