Skip to content

Commit

Permalink
Add keep_alive_interval config option for mqtt.
Browse files Browse the repository at this point in the history
Closes #54.
  • Loading branch information
brocaar committed Mar 19, 2024
1 parent 4d9c211 commit 57c9b87
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
lrwn_filters = { version = "4.7", features = ["serde"] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
humantime-serde = "1.1"
log = "0.4"
simple_logger = "4.3"
syslog = "6.1"
Expand Down
6 changes: 6 additions & 0 deletions src/cmd/configfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ pub fn run(config: &Configuration) {
# a random id will be generated by ChirpStack.
client_id="{{ mqtt.client_id }}"
# Keep alive interval.
#
# This defines the maximum time that that should pass without communication
# between the client and server.
keep_alive_interval="{{ integration.mqtt.keep_alive_interval }}"
# CA certificate file (optional)
#
# Use this when setting up a secure connection (when server uses ssl://...)
Expand Down
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::fs;
use std::time::Duration;

use anyhow::Result;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -52,6 +53,8 @@ pub struct Mqtt {
pub qos: u8,
pub clean_session: bool,
pub client_id: String,
#[serde(with = "humantime_serde")]
pub keep_alive_interval: Duration,
pub ca_cert: String,
pub tls_cert: String,
pub tls_key: String,
Expand All @@ -68,6 +71,7 @@ impl Default for Mqtt {
qos: 0,
clean_session: false,
client_id: "".into(),
keep_alive_interval: Duration::from_secs(30),
ca_cert: "".into(),
tls_cert: "".into(),
tls_key: "".into(),
Expand Down
1 change: 1 addition & 0 deletions src/mqtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ pub async fn setup(conf: &Configuration) -> Result<()> {

mqtt_opts.set_last_will(lwt_msg);
mqtt_opts.set_clean_start(conf.mqtt.clean_session);
mqtt_opts.set_keep_alive(conf.mqtt.keep_alive_interval);
if !conf.mqtt.username.is_empty() || !conf.mqtt.password.is_empty() {
mqtt_opts.set_credentials(&conf.mqtt.username, &conf.mqtt.password);
}
Expand Down

0 comments on commit 57c9b87

Please sign in to comment.