dockerize event proxy go app
This commit is contained in:
parent
aa5a4eda05
commit
83e3765247
5 changed files with 63 additions and 8 deletions
|
|
@ -18,9 +18,20 @@ type App struct {
|
|||
}
|
||||
|
||||
func getMQTTClient() mqtt.Client {
|
||||
// TODO: get port and host from env vars
|
||||
mqttHost := os.Getenv("MQTT_HOST")
|
||||
if mqttHost == "" {
|
||||
panic("MQTT_HOST environment variable not set")
|
||||
}
|
||||
mqttPort := os.Getenv("MQTT_PORT")
|
||||
if mqttPort == "" {
|
||||
panic("MQTT_PORT environment variable not set")
|
||||
}
|
||||
|
||||
brokerURL := "tcp://" + mqttHost + ":" + mqttPort
|
||||
slog.Info("Connecting to MQTT", "broker", brokerURL)
|
||||
|
||||
opts := mqtt.NewClientOptions().
|
||||
AddBroker("tcp://localhost:5883").
|
||||
AddBroker(brokerURL).
|
||||
SetClientID("event-proxy")
|
||||
|
||||
client := mqtt.NewClient(opts)
|
||||
|
|
@ -29,11 +40,6 @@ func getMQTTClient() mqtt.Client {
|
|||
panic(token.Error())
|
||||
}
|
||||
return client
|
||||
|
||||
// // Publish a message
|
||||
// token := client.Publish("homeassistant/sensor/bws/node1/state1", 0, false, `{"temp": 23.5, "humidity": 45, "pressure": 1013}`)
|
||||
// token.Wait()
|
||||
// client.Disconnect(250)
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue