Skip to content

Commit 57c9b87

Browse files
committed
Add keep_alive_interval config option for mqtt.
Closes #54.
1 parent 4d9c211 commit 57c9b87

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
lrwn_filters = { version = "4.7", features = ["serde"] }
2323
serde_json = "1.0"
2424
serde = { version = "1.0", features = ["derive"] }
25+
humantime-serde = "1.1"
2526
log = "0.4"
2627
simple_logger = "4.3"
2728
syslog = "6.1"

src/cmd/configfile.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ pub fn run(config: &Configuration) {
8181
# a random id will be generated by ChirpStack.
8282
client_id="{{ mqtt.client_id }}"
8383
84+
# Keep alive interval.
85+
#
86+
# This defines the maximum time that that should pass without communication
87+
# between the client and server.
88+
keep_alive_interval="{{ integration.mqtt.keep_alive_interval }}"
89+
8490
# CA certificate file (optional)
8591
#
8692
# Use this when setting up a secure connection (when server uses ssl://...)

src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::HashMap;
22
use std::fs;
3+
use std::time::Duration;
34

45
use anyhow::Result;
56
use serde::{Deserialize, Serialize};
@@ -52,6 +53,8 @@ pub struct Mqtt {
5253
pub qos: u8,
5354
pub clean_session: bool,
5455
pub client_id: String,
56+
#[serde(with = "humantime_serde")]
57+
pub keep_alive_interval: Duration,
5558
pub ca_cert: String,
5659
pub tls_cert: String,
5760
pub tls_key: String,
@@ -68,6 +71,7 @@ impl Default for Mqtt {
6871
qos: 0,
6972
clean_session: false,
7073
client_id: "".into(),
74+
keep_alive_interval: Duration::from_secs(30),
7175
ca_cert: "".into(),
7276
tls_cert: "".into(),
7377
tls_key: "".into(),

src/mqtt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ pub async fn setup(conf: &Configuration) -> Result<()> {
141141

142142
mqtt_opts.set_last_will(lwt_msg);
143143
mqtt_opts.set_clean_start(conf.mqtt.clean_session);
144+
mqtt_opts.set_keep_alive(conf.mqtt.keep_alive_interval);
144145
if !conf.mqtt.username.is_empty() || !conf.mqtt.password.is_empty() {
145146
mqtt_opts.set_credentials(&conf.mqtt.username, &conf.mqtt.password);
146147
}

0 commit comments

Comments
 (0)