Improve MQTT documentation, example config

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.
This commit is contained in:
Kevin David authored and Andrew King committed 2022-12-11 13:07:23 +07:00
1 parent b80144492e
commit c19bba9235
4 files changed
+32 -6

No files matched your search

+18
View File
@@ -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
View File
@@ -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"
-1
View File
@@ -1,5 +1,4 @@
use structopt::StructOpt;
/// The reboot command will reboot the camera
#[derive(StructOpt, Debug)]
pub struct Opt {}
+10 -5
View File
@@ -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;
@@ -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());
@@ -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(())
}