add password and user to mqtt login

This commit is contained in:
Travis Shears 2025-12-25 13:30:13 +01:00
parent 83e3765247
commit 21aa735d51
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469

View file

@ -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)