Skip to content

Commit f92ce5a

Browse files
Make MQTT keepalive interval configurable. (#176)
1 parent ddc8d59 commit f92ce5a

File tree

5 files changed

+9
-1
lines changed

5 files changed

+9
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ serve: build
4444
./build/chirpstack-gateway-bridge
4545

4646
run-compose-test:
47-
docker-compose run --rm gatewaybridge make test
47+
docker-compose run --rm chirpstack-gateway-bridge make test

cmd/chirpstack-gateway-bridge/cmd/configfile.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ marshaler="{{ .Integration.Marshaler }}"
224224
# Command topic template.
225225
command_topic_template="{{ .Integration.MQTT.CommandTopicTemplate }}"
226226
227+
# Keep alive will set the amount of time (in seconds) that the client should
228+
# wait before sending a PING request to the broker. This will allow the client
229+
# to know that a connection has not been lost with the server.
230+
keep_alive="{{ .Integration.MQTT.KeepAlive }}"
231+
227232
# Maximum interval that will be waited between reconnection attempts when connection is lost.
228233
# Valid units are 'ms', 's', 'm', 'h'. Note that these values can be combined, e.g. '24h30m15s'.
229234
max_reconnect_interval="{{ .Integration.MQTT.MaxReconnectInterval }}"

cmd/chirpstack-gateway-bridge/cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func init() {
5858

5959
viper.SetDefault("integration.mqtt.event_topic_template", "gateway/{{ .GatewayID }}/event/{{ .EventType }}")
6060
viper.SetDefault("integration.mqtt.command_topic_template", "gateway/{{ .GatewayID }}/command/#")
61+
viper.SetDefault("integration.mqtt.keep_alive", 30*time.Second)
6162
viper.SetDefault("integration.mqtt.max_reconnect_interval", time.Minute)
6263

6364
viper.SetDefault("integration.mqtt.auth.generic.servers", []string{"tcp://127.0.0.1:1883"})

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type Config struct {
5858
MQTT struct {
5959
EventTopicTemplate string `mapstructure:"event_topic_template"`
6060
CommandTopicTemplate string `mapstructure:"command_topic_template"`
61+
KeepAlive time.Duration `mapstructure:"keep_alive"`
6162
MaxReconnectInterval time.Duration `mapstructure:"max_reconnect_interval"`
6263
TerminateOnConnectError bool `mapstructure:"terminate_on_connect_error"`
6364

internal/integration/mqtt/backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func NewBackend(conf config.Config) (*Backend, error) {
128128
b.clientOpts.SetAutoReconnect(true) // this is required for buffering messages in case offline!
129129
b.clientOpts.SetOnConnectHandler(b.onConnected)
130130
b.clientOpts.SetConnectionLostHandler(b.onConnectionLost)
131+
b.clientOpts.SetKeepAlive(conf.Integration.MQTT.KeepAlive)
131132
b.clientOpts.SetMaxReconnectInterval(conf.Integration.MQTT.MaxReconnectInterval)
132133

133134
if err = b.auth.Init(b.clientOpts); err != nil {

0 commit comments

Comments
 (0)