add password and user to mqtt login
This commit is contained in:
parent
83e3765247
commit
21aa735d51
1 changed files with 11 additions and 2 deletions
|
|
@ -26,13 +26,22 @@ func getMQTTClient() mqtt.Client {
|
|||
if mqttPort == "" {
|
||||
panic("MQTT_PORT environment variable not set")
|
||||
}
|
||||
mqttUsername := os.Getenv("MQTT_USERNAME")
|
||||
if mqttUsername == "" {
|
||||
panic("MQTT_USERNAME environment variable not set")
|
||||
}
|
||||
mqttPassword := os.Getenv("MQTT_PASSWORD")
|
||||
if mqttPassword == "" {
|
||||
panic("MQTT_PASSWORD environment variable not set")
|
||||
}
|
||||
|
||||
brokerURL := "tcp://" + mqttHost + ":" + mqttPort
|
||||
slog.Info("Connecting to MQTT", "broker", brokerURL)
|
||||
|
||||
opts := mqtt.NewClientOptions().
|
||||
AddBroker(brokerURL).
|
||||
SetClientID("event-proxy")
|
||||
SetClientID("event-proxy").
|
||||
SetUsername(mqttUsername).
|
||||
SetPassword(mqttPassword)
|
||||
|
||||
client := mqtt.NewClient(opts)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue