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