File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,12 @@ pub fn run(config: &Configuration) {
100
100
# TLS key file (optional)
101
101
tls_key="{{ mqtt.tls_key }}"
102
102
103
+ # Reconnect interval.
104
+ #
105
+ # This defines the reconnection interval to the MQTT broker in case of
106
+ # network issues.
107
+ reconnect_interval="{{ integration.mqtt.reconnect_interval }}"
108
+
103
109
104
110
# Backend configuration.
105
111
[backend]
Original file line number Diff line number Diff line change @@ -66,6 +66,8 @@ pub struct Mqtt {
66
66
pub ca_cert : String ,
67
67
pub tls_cert : String ,
68
68
pub tls_key : String ,
69
+ #[ serde( with = "humantime_serde" ) ]
70
+ pub reconnect_interval : Duration ,
69
71
}
70
72
71
73
impl Default for Mqtt {
@@ -83,6 +85,7 @@ impl Default for Mqtt {
83
85
ca_cert : "" . into ( ) ,
84
86
tls_cert : "" . into ( ) ,
85
87
tls_key : "" . into ( ) ,
88
+ reconnect_interval : Duration :: from_secs ( 1 ) ,
86
89
}
87
90
}
88
91
}
Original file line number Diff line number Diff line change 1
1
use std:: fs:: File ;
2
2
use std:: io:: { BufReader , Cursor } ;
3
3
use std:: sync:: Arc ;
4
- use std:: time:: Duration ;
5
4
6
5
use anyhow:: { Context , Result } ;
7
6
use chirpstack_api:: gw;
@@ -210,6 +209,7 @@ pub async fn setup(conf: &Configuration) -> Result<()> {
210
209
tokio:: spawn ( {
211
210
let on_mqtt_connected = conf. callbacks . on_mqtt_connected . clone ( ) ;
212
211
let on_mqtt_connection_error = conf. callbacks . on_mqtt_connection_error . clone ( ) ;
212
+ let reconnect_interval = conf. mqtt . reconnect_interval . clone ( ) ;
213
213
214
214
async move {
215
215
info ! ( "Starting MQTT event loop" ) ;
@@ -238,7 +238,7 @@ pub async fn setup(conf: &Configuration) -> Result<()> {
238
238
}
239
239
} else {
240
240
error ! ( "Connection error, code: {:?}" , v. code) ;
241
- sleep ( Duration :: from_secs ( 1 ) ) . await
241
+ sleep ( reconnect_interval ) . await
242
242
}
243
243
}
244
244
_ => { }
@@ -248,7 +248,7 @@ pub async fn setup(conf: &Configuration) -> Result<()> {
248
248
commands:: exec_callback ( & on_mqtt_connection_error) . await ;
249
249
250
250
error ! ( "MQTT error, error: {}" , e) ;
251
- sleep ( Duration :: from_secs ( 1 ) ) . await
251
+ sleep ( reconnect_interval ) . await
252
252
}
253
253
}
254
254
}
You can’t perform that action at this time.
0 commit comments