config
This commit is contained in:
@ -8,6 +8,7 @@ import "strings"
|
||||
import MQTT "github.com/eclipse/paho.mqtt.golang"
|
||||
import "github.com/google/uuid"
|
||||
import "crypto/tls"
|
||||
import "udi/config"
|
||||
|
||||
type Message struct {
|
||||
Topic string
|
||||
@ -71,7 +72,7 @@ func outputDispatcher(client MQTT.Client) {
|
||||
}
|
||||
|
||||
func StartMqttClient() {
|
||||
broker := os.Getenv("MQTT_BROKER")
|
||||
broker := config.Config.Mqtt.Broker
|
||||
if broker == "" {
|
||||
log.Fatal("No broker given, set env var MQTT_BROKER")
|
||||
}
|
||||
@ -88,19 +89,19 @@ func StartMqttClient() {
|
||||
SetReconnectingHandler(onReconnecting).
|
||||
SetConnectRetry(true)
|
||||
|
||||
username := os.Getenv("MQTT_USERNAME")
|
||||
username := config.Config.Mqtt.Username
|
||||
if username != "" {
|
||||
opts.SetUsername(username)
|
||||
}
|
||||
|
||||
password := os.Getenv("MQTT_PASSWORD")
|
||||
password := config.Config.Mqtt.Password
|
||||
if password != "" {
|
||||
opts.SetPassword(password)
|
||||
}
|
||||
|
||||
enableTls := os.Getenv("MQTT_ENABLE_TLS")
|
||||
enableTls := config.Config.Mqtt.TlsEnable
|
||||
if enableTls == "true" {
|
||||
log.Println("Enableing TLS connection")
|
||||
log.Println("Enabling TLS connection")
|
||||
tlsConfig := &tls.Config {
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
|
Reference in New Issue
Block a user