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) {
100100 # TLS key file (optional)
101101 tls_key="{{ mqtt.tls_key }}"
102102
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+
103109
104110# Backend configuration.
105111[backend]
Original file line number Diff line number Diff line change @@ -66,6 +66,8 @@ pub struct Mqtt {
6666 pub ca_cert : String ,
6767 pub tls_cert : String ,
6868 pub tls_key : String ,
69+ #[ serde( with = "humantime_serde" ) ]
70+ pub reconnect_interval : Duration ,
6971}
7072
7173impl Default for Mqtt {
@@ -83,6 +85,7 @@ impl Default for Mqtt {
8385 ca_cert : "" . into ( ) ,
8486 tls_cert : "" . into ( ) ,
8587 tls_key : "" . into ( ) ,
88+ reconnect_interval : Duration :: from_secs ( 1 ) ,
8689 }
8790 }
8891}
Original file line number Diff line number Diff line change 11use std:: fs:: File ;
22use std:: io:: { BufReader , Cursor } ;
33use std:: sync:: Arc ;
4- use std:: time:: Duration ;
54
65use anyhow:: { Context , Result } ;
76use chirpstack_api:: gw;
@@ -210,6 +209,7 @@ pub async fn setup(conf: &Configuration) -> Result<()> {
210209 tokio:: spawn ( {
211210 let on_mqtt_connected = conf. callbacks . on_mqtt_connected . clone ( ) ;
212211 let on_mqtt_connection_error = conf. callbacks . on_mqtt_connection_error . clone ( ) ;
212+ let reconnect_interval = conf. mqtt . reconnect_interval . clone ( ) ;
213213
214214 async move {
215215 info ! ( "Starting MQTT event loop" ) ;
@@ -238,7 +238,7 @@ pub async fn setup(conf: &Configuration) -> Result<()> {
238238 }
239239 } else {
240240 error ! ( "Connection error, code: {:?}" , v. code) ;
241- sleep ( Duration :: from_secs ( 1 ) ) . await
241+ sleep ( reconnect_interval ) . await
242242 }
243243 }
244244 _ => { }
@@ -248,7 +248,7 @@ pub async fn setup(conf: &Configuration) -> Result<()> {
248248 commands:: exec_callback ( & on_mqtt_connection_error) . await ;
249249
250250 error ! ( "MQTT error, error: {}" , e) ;
251- sleep ( Duration :: from_secs ( 1 ) ) . await
251+ sleep ( reconnect_interval ) . await
252252 }
253253 }
254254 }
You can’t perform that action at this time.
0 commit comments