Skip to content

Commit

Permalink
Make MQTT Port configurable
Browse files Browse the repository at this point in the history
Implements issue #12.
  • Loading branch information
DennisOSRM committed Nov 5, 2023
1 parent 6c6421f commit 6fe78e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct Cli {
mqtt_broker_host: String,
mqtt_username: Option<String>,
mqtt_password: Option<String>,
#[clap(default_value = "1883")]
mqtt_broker_port: u16,
}

static REQUEST_DELAY: u64 = 30_500;
Expand Down Expand Up @@ -56,6 +58,7 @@ fn main() {
&cli.mqtt_broker_host,
&cli.mqtt_username,
&cli.mqtt_password,
cli.mqtt_broker_port,
);

loop {
Expand Down
9 changes: 7 additions & 2 deletions src/mqtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ pub struct Mqtt {
}

impl Mqtt {
pub fn new(host: &str, username: &Option<String>, password: &Option<String>) -> Self {
let mut mqttoptions = MqttOptions::new("hms800wt2-mqtt-publisher", host, 1883);
pub fn new(
host: &str,
username: &Option<String>,
password: &Option<String>,
port: u16,
) -> Self {
let mut mqttoptions = MqttOptions::new("hms800wt2-mqtt-publisher", host, port);
mqttoptions.set_keep_alive(Duration::from_secs(5));

//parse the mqtt authentication options
Expand Down

0 comments on commit 6fe78e6

Please sign in to comment.