Skip to content

Commit

Permalink
Improve MQTT documentation, example config
Browse files Browse the repository at this point in the history
Also print an error message when the configuration isn't present but the `mqtt` subcommand is used. Without this, the program just exits without any messsages.
  • Loading branch information
Kevin David authored and QuantumEntangledAndy committed Dec 11, 2022
1 parent b801444 commit c19bba9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceRoot}/target/debug/${workspaceRootFolderName}",
"args": ["mqtt", "--config", "target/config.toml"],
"cwd": "${workspaceRoot}",
"sourceLanguages": [
"rust"
],
"env": {
"RUST_LOG": "debug"
}
}
]}
4 changes: 4 additions & 0 deletions sample_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ name = "driveway"
username = "admin"
password = "12345678"
address = "192.168.1.187:9000"
# mqtt.broker_addr = "192.168.1.122"
# mqtt.port = 1883
# mqtt.credentials = ["mqtt_user", "mqtt_password"]

# If you use a battery camera: **Instead** of an `address` supply the uid
# as follows
# uid = "ABCD01234567890EFG"
Expand Down
1 change: 0 additions & 1 deletion src/mqtt/cmdline.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use structopt::StructOpt;

/// The reboot command will reboot the camera
#[derive(StructOpt, Debug)]
pub struct Opt {}
15 changes: 10 additions & 5 deletions src/mqtt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use log::*;
///
/// # Neolink Reboot
/// # Neolink MQTT
///
/// This module handles the reboot subcommand
///
/// The subcommand attepts to reboot the camera.
/// Handles incoming and outgoing MQTT messages
///
/// # Usage
///
/// ```bash
/// neolink reboot --config=config.toml CameraName
/// neolink mqtt --config=config.toml
/// ```
///
use std::sync::Arc;
Expand All @@ -34,11 +32,14 @@ pub(crate) fn main(_: Opt, config: Config) -> Result<()> {
let app = App::new();
let arc_app = Arc::new(app);

let mut mqtt_count: u8 = 0;

let _ = crossbeam::scope(|s| {
for camera_config in &config.cameras {
if let Some(mqtt_config) = camera_config.mqtt.as_ref() {
let loop_arc_app = arc_app.clone();
info!("{}: Setting up mqtt", camera_config.name);
mqtt_count = mqtt_count + 1;
s.spawn(move |_| {
while loop_arc_app.running("app") {
let _ = listen_on_camera(camera_config, mqtt_config, loop_arc_app.clone());
Expand All @@ -48,6 +49,10 @@ pub(crate) fn main(_: Opt, config: Config) -> Result<()> {
}
});

if mqtt_count == 0 {
error!("MQTT command run, but no cameras configured with MQTT settings. Exiting.");
}

Ok(())
}

Expand Down

0 comments on commit c19bba9

Please sign in to comment.