Skip to content

Commit 72ca5e5

Browse files
Add visitor to mqtt
1 parent 13081f7 commit 72ca5e5

File tree

17 files changed

+400
-140
lines changed

17 files changed

+400
-140
lines changed

Cargo.lock

Lines changed: 3 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,20 @@ Status Messages:
243243
pir status
244244
- `/status/motion` Contains the motion detection alarm status. `on` for motion
245245
and `off` for still, only published when `enable_moton` is true in the config
246+
- `/status/visitor` Contains the visitor detection status, which occurs when a
247+
doorbell is pressed.
248+
- `/status/ai` Contains the ai detection status, which occurs when a
249+
the camera's internal ai detects something. The value is `person/car/other`
250+
- `/status/ai/person` Contains the ai detection status of the last person,
251+
which occurs when a the camera's internal ai detects a person.
252+
- `/status/ai/car` Contains the ai detection status of the last car, which
253+
occurs when a the camera's internal ai detects a car.
254+
- `/status/ai/other` Contains the ai detection status from the camera, which
255+
occurs when a the camera's internal ai detects something.
256+
257+
(This is a placeholder until I can fiquire out everything that the camera
258+
can detect. If you have list for me please open an issue with it, I don't
259+
have a cam with AI to check myself)
246260
- `/status/ptz/preset` Sent in reply to a `/query/ptz/preset` an XML encoded
247261
version of the PTZ presets
248262
- `/status/preview` a base64 encoded camera image updated every 2s. Not
@@ -325,6 +339,14 @@ enable_motion = false # motion detection
325339
# (limited battery drain since it
326340
# is a passive listening connection)
327341
#
342+
enable_visitor = false # visitor press for doorbell camera
343+
# (limited battery drain since it
344+
# is a passive listening connection)
345+
#
346+
enable_ai = false # report detected ai by the camera
347+
# (limited battery drain since it
348+
# is a passive listening connection)
349+
#
328350
enable_light = false # flood lights only available on some camera
329351
# (limited battery drain since it
330352
# is a passive listening connection)

crates/core/src/bc/de.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ fn bc_modern_msg<'a>(
9090
E::add_context(input, ctx, E::from_error_kind(input, kind))
9191
}
9292

93-
let ext_len = match header.payload_offset {
94-
Some(off) => off,
95-
_ => 0, // If missing payload_offset treat all as payload
96-
};
93+
// If missing payload_offset treat all as payload
94+
let ext_len = header.payload_offset.unwrap_or_default();
9795

9896
let (buf, ext_buf) = take(ext_len)(buf)?;
9997
let payload_len = header.body_len - ext_len;

crates/core/src/bc/model.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ pub struct BcMeta {
194194
/// When sending a command it is set to `0`. The reply from the camera can be
195195
/// - `200` for OK
196196
/// - `400` for bad request
197+
///
197198
/// A malformed packet will return a `400` code
198199
pub response_code: u16,
199200
/// A message ID is used to match replies with requests. The camera will parrot back
@@ -213,14 +214,6 @@ pub struct BcMeta {
213214
pub class: u16,
214215
}
215216

216-
/// The components of the Baichuan header that must be filled out after the body is serialized, or
217-
/// is needed for the deserialization of the body (strictly part of the wire format of the message)
218-
#[derive(Debug, PartialEq, Eq)]
219-
pub(super) struct BcSendInfo {
220-
pub body_len: u32,
221-
pub payload_offset: Option<u32>,
222-
}
223-
224217
#[derive(Debug)]
225218
pub(crate) struct BcContext {
226219
pub(crate) credentials: Credentials,

crates/core/src/bc/xml.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,18 +633,29 @@ pub struct AlarmEvent {
633633
/// The channel the event occured on. Usually zero unless from an NVR
634634
#[serde(rename = "channelId")]
635635
pub channel_id: u8,
636-
/// Motion status. Known values are `"MD"` or `"none"`
636+
/// Motion status. Known values are `"MD"` or `"none"` or `"visitor"`
637637
pub status: String,
638638
/// AI status. Known values are `"people"` or `"none"`
639-
#[serde(rename = "AItype", skip_serializing_if = "Option::is_none")]
640-
pub ai_type: Option<String>,
639+
#[serde(
640+
rename = "AItype",
641+
default = "ai_type_default",
642+
skip_serializing_if = "ai_type_skip"
643+
)]
644+
pub ai_type: String,
641645
/// The recording status. Known values `0` or `1`
642646
pub recording: i32,
643647
/// The timestamp associated with the recording. `0` if not recording
644648
#[serde(rename = "timeStamp")]
645649
pub timeStamp: i32,
646650
}
647651

652+
fn ai_type_default() -> String {
653+
"none".to_string()
654+
}
655+
fn ai_type_skip(value: &String) -> bool {
656+
value == "none"
657+
}
658+
648659
/// The Ptz messages used to move the camera
649660
#[derive(PartialEq, Default, Debug, Deserialize, Serialize)]
650661
pub struct PtzControl {

crates/core/src/bc_protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub use credentials::*;
4747
pub use errors::Error;
4848
pub use ledstate::LightState;
4949
pub use login::MaxEncryption;
50-
pub use motion::{MotionData, MotionStatus};
50+
pub use motion::{AiKind, MotionData, MotionEvents};
5151
pub use pirstate::PirState;
5252
pub use ptz::Direction;
5353
pub use pushinfo::PhoneType;

crates/core/src/bc_protocol/connection/bcsub.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ pub struct BcStream<'a> {
2020
rx: &'a mut ReceiverStream<Result<Bc>>,
2121
}
2222

23-
impl<'a> Unpin for BcStream<'a> {}
23+
impl Unpin for BcStream<'_> {}
2424

25-
impl<'a> Stream for BcStream<'a> {
25+
impl Stream for BcStream<'_> {
2626
type Item = Result<Bc>;
2727

2828
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Result<Bc>>> {

0 commit comments

Comments
 (0)