Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ log_level=4
# Set this to true when the endpoint is not using TLS.
insecure=true

# Timeout.
#
# This determines the maximum amount of time connecting to the API may take.
# You may increase the timeout if the context deadline exceeded.
timeout="2s"

# MQTT integration configuration.
#
Expand Down
5 changes: 5 additions & 0 deletions cmd/chirpstack-simulator/cmd/configfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ log_level={{ .General.LogLevel }}
# Set this to true when the endpoint is not using TLS.
insecure={{ .ApplicationServer.API.Insecure }}

# Timeout.
#
# This determines the maximum amount of time connecting to the API may take.
# You may increase the timeout if the context deadline exceeded.
timeout="{{ .ApplicationServer.API.Timeout }}"

# MQTT integration configuration.
#
Expand Down
2 changes: 2 additions & 0 deletions cmd/chirpstack-simulator/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"io/ioutil"
"time"

"github.com/brocaar/chirpstack-simulator/internal/config"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -39,6 +40,7 @@ func init() {
viper.BindPFlag("general.log_level", rootCmd.PersistentFlags().Lookup("log-level"))

viper.SetDefault("application_server.api.server", "127.0.0.1:8080")
viper.SetDefault("application_server.api.timeout", 1*time.Second)
viper.SetDefault("application_server.integration.mqtt.server", "tcp://127.0.0.1:1883")
viper.SetDefault("network_server.gateway.backend.mqtt.server", "tcp://127.0.0.1:1883")
viper.SetDefault("prometheus.bind", "0.0.0.0:9000")
Expand Down
4 changes: 2 additions & 2 deletions internal/as/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package as
import (
"context"
"crypto/tls"
"time"

mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/pkg/errors"
Expand Down Expand Up @@ -40,6 +39,7 @@ func Setup(c config.Config) error {
log.WithFields(log.Fields{
"server": conf.API.Server,
"insecure": conf.API.Insecure,
"timeout": conf.API.Timeout,
}).Info("as: connecting api client")

dialOpts := []grpc.DialOption{
Expand All @@ -53,7 +53,7 @@ func Setup(c config.Config) error {
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
ctx, cancel := context.WithTimeout(context.Background(), conf.API.Timeout)
defer cancel()

conn, err := grpc.DialContext(ctx, conf.API.Server, dialOpts...)
Expand Down
7 changes: 4 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ type Config struct {

ApplicationServer struct {
API struct {
JWTToken string `mapstructure:"jwt_token"`
Server string `mapstructure:"server"`
Insecure bool `mapstructure:"insecure"`
JWTToken string `mapstructure:"jwt_token"`
Server string `mapstructure:"server"`
Insecure bool `mapstructure:"insecure"`
Timeout time.Duration `mapstructure:"timeout"`
} `mapstructure:"api"`

Integration struct {
Expand Down