Skip to content

Commit

Permalink
Allow custom MQTT Client ID (#1128)
Browse files Browse the repository at this point in the history
  • Loading branch information
blenni authored and naltatis committed Jun 11, 2021
1 parent fe2f5f6 commit cb3c9fe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ func configureDatabase(conf server.InfluxConfig, loadPoints []core.LoadPointAPI,
// setup mqtt
func configureMQTT(conf mqttConfig) error {
log := util.NewLogger("mqtt")
clientID := mqtt.ClientID()
clientID := conf.ClientID
if clientID == "" {
clientID = mqtt.ClientID()
}

var err error
mqtt.Instance, err = mqtt.RegisteredClient(log, conf.Broker, conf.User, conf.Password, clientID, 1)
Expand Down
1 change: 1 addition & 0 deletions provider/mqtt/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Config struct {
Broker string
User string
Password string
ClientID string
}

// Client encapsulates mqtt publish/subscribe functions
Expand Down
2 changes: 1 addition & 1 deletion provider/mqtt/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func RegisteredClient(log *util.Logger, broker, user, password, clientID string,
client, err := registry.Get(key)

if err != nil {
if client, err = NewClient(log, broker, user, password, ClientID(), qos); err == nil {
if client, err = NewClient(log, broker, user, password, clientID, qos); err == nil {
registry.Add(key, client)
}
}
Expand Down

0 comments on commit cb3c9fe

Please sign in to comment.