From 2b0a0edf7771d25c329af1596d04c5d5da26c03c Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Fri, 19 May 2023 10:30:38 +0700 Subject: [PATCH] Add the cellular discovery option --- README.md | 9 +++++++++ crates/core/src/bc_protocol.rs | 19 +++++++++++-------- crates/core/src/bc_protocol/resolution.rs | 4 ++++ sample_config.toml | 2 ++ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3d50ad0..948b186 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,15 @@ In the `[[cameras]]` section of the toml. Possible values are `local`, `remote`, `map`, `relay` later values implictly enable prior methods. +#### Cellular + +Cellular cameras should select `"cellular"` which only enables `map` and +`relay` since `local` and `remote` will always fail + +```toml +discovery = "cellular" +``` + ### MQTT To use mqtt you will to adjust your config file as such: diff --git a/crates/core/src/bc_protocol.rs b/crates/core/src/bc_protocol.rs index d76487f..9b76be5 100644 --- a/crates/core/src/bc_protocol.rs +++ b/crates/core/src/bc_protocol.rs @@ -139,14 +139,16 @@ impl BcCamera { } } } - info!("{}: Trying TCP discovery", options.name); - for socket in sockets.drain(..) { - let channel_id: u8 = options.channel_id; - if let Ok(addr) = Discovery::check_tcp(socket, channel_id).await.map(|_| { - info!("{}: TCP Discovery success at {:?}", options.name, &socket); - socket - }) { - return Ok(CameraLocation::Tcp(addr)); + if !sockets.is_empty() { + info!("{}: Trying TCP discovery", options.name); + for socket in sockets.drain(..) { + let channel_id: u8 = options.channel_id; + if let Ok(addr) = Discovery::check_tcp(socket, channel_id).await.map(|_| { + info!("{}: TCP Discovery success at {:?}", options.name, &socket); + socket + }) { + return Ok(CameraLocation::Tcp(addr)); + } } } } @@ -176,6 +178,7 @@ impl BcCamera { DiscoveryMethods::Remote => (true, true, false, false), DiscoveryMethods::Map => (true, true, true, false), DiscoveryMethods::Relay => (true, true, true, true), + DiscoveryMethods::Cellular => (false, false, true, true), DiscoveryMethods::Debug => (false, false, false, true), }; diff --git a/crates/core/src/bc_protocol/resolution.rs b/crates/core/src/bc_protocol/resolution.rs index f442209..32643c1 100644 --- a/crates/core/src/bc_protocol/resolution.rs +++ b/crates/core/src/bc_protocol/resolution.rs @@ -38,6 +38,10 @@ pub enum DiscoveryMethods { /// **This also enabled `Local`, `Map` and `Remote` discovery** #[serde(alias = "relay")] Relay, + /// Cellular camera only support relay and map, by choosing this option + /// only those are tried + #[serde(alias = "cellular")] + Cellular, #[doc(hidden)] #[serde(alias = "debug")] /// Used for debugging it is set to whatever the dev is currently testing diff --git a/sample_config.toml b/sample_config.toml index 4fb6735..da37fb6 100644 --- a/sample_config.toml +++ b/sample_config.toml @@ -61,6 +61,8 @@ address = "192.168.1.187:9000" # "remote" # Register our local ip address with reolink but only permit same network connections (useful if broadcast is not possible) # "local" # Do not contact reolink servers at all. Rely soley on local UDP broadcast based discovery # +# "cellular" # Cellular camera only support Relay and Map to speed up connecting to them this option will skip the local/remote +# # discovery = "relay" # Certain types of camera emit status messages (such as battery levels)