Add configurable mqtt port
This commit is contained in:
parent
041ad2f5a3
commit
0913422296
|
@ -1,5 +1,6 @@
|
|||
[mqtt]
|
||||
Host = "192.168.0.123"
|
||||
Port = 1883
|
||||
|
||||
[[targets]]
|
||||
Host = "192.168.0.222"
|
||||
|
|
5
main.go
5
main.go
|
@ -34,6 +34,7 @@ type targetConfig struct {
|
|||
type config struct {
|
||||
MQTT struct {
|
||||
Host string
|
||||
Port uint16
|
||||
}
|
||||
Targets []targetConfig
|
||||
}
|
||||
|
@ -206,7 +207,9 @@ func main() {
|
|||
conf, err := parseConfig(*configpath)
|
||||
check(err)
|
||||
|
||||
mqttOpts := mqtt.NewClientOptions().AddBroker(fmt.Sprintf("tcp://%s:1883", conf.MQTT.Host)).SetClientID("apc2mqtt")
|
||||
mqttOpts := mqtt.NewClientOptions().AddBroker(
|
||||
fmt.Sprintf("tcp://%s:%d", conf.MQTT.Host, conf.MQTT.Port),
|
||||
).SetClientID("apc2mqtt")
|
||||
mqttClient := mqtt.NewClient(mqttOpts)
|
||||
if token := mqttClient.Connect(); token.Wait() && token.Error() != nil {
|
||||
panic(token.Error())
|
||||
|
|
Loading…
Reference in New Issue