Add CLI args for broker address and port
This commit is contained in:
17
src/main.rs
17
src/main.rs
@@ -1,13 +1,26 @@
|
||||
use clap::Parser;
|
||||
use rumqttc::{AsyncClient, Event, MqttOptions, Packet, QoS};
|
||||
use std::time::Duration;
|
||||
use tokio::time::sleep;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
#[arg(default_value = "localhost")]
|
||||
broker: String,
|
||||
|
||||
#[arg(default_value_t = 1883)]
|
||||
port: u16,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args = Args::parse();
|
||||
|
||||
let mut mqttoptions = MqttOptions::new(
|
||||
"mqtt-publisher",
|
||||
"localhost",
|
||||
1883,
|
||||
args.broker,
|
||||
args.port,
|
||||
);
|
||||
mqttoptions.set_keep_alive(Duration::from_secs(30));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user