Skip to content

Commit

Permalink
Merge pull request schollz#138 from sjcliffe/master
Browse files Browse the repository at this point in the history
support for existing mqtt server configuration.
  • Loading branch information
schollz authored Jan 9, 2017
2 parents 569eb4b + bc25330 commit 769aacd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 8 additions & 3 deletions mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ import (
var adminClient *MQTT.Client

func setupMqtt() {
updateMosquittoConfig()
server := "tcp://" + RuntimeArgs.MqttServer

opts := MQTT.NewClientOptions().AddBroker(server).SetClientID(RandStringBytesMaskImprSrc(5)).SetUsername(RuntimeArgs.MqttAdmin).SetPassword(RuntimeArgs.MqttAdminPassword).SetCleanSession(true)
opts := MQTT.NewClientOptions()

if RuntimeArgs.MqttExisting {
opts.AddBroker(server).SetClientID(RandStringBytesMaskImprSrc(5)).SetCleanSession(true)
} else {
updateMosquittoConfig()
opts.AddBroker(server).SetClientID(RandStringBytesMaskImprSrc(5)).SetUsername(RuntimeArgs.MqttAdmin).SetPassword(RuntimeArgs.MqttAdminPassword).SetCleanSession(true)
}

opts.OnConnect = func(c *MQTT.Client) {
if token := c.Subscribe("#", 1, messageReceived); token.Wait() && token.Error() != nil {
Expand Down
9 changes: 8 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var RuntimeArgs struct {
Dump string
Message string
Mqtt bool
MqttExisting bool
Svm bool
RandomForests bool
Filtering bool
Expand Down Expand Up @@ -103,7 +104,13 @@ Options:`)
RuntimeArgs.Mqtt = true
setupMqtt()
} else {
RuntimeArgs.Mqtt = false
if len(RuntimeArgs.MqttServer) > 0 {
RuntimeArgs.Mqtt = true
RuntimeArgs.MqttExisting = true
setupMqtt()
} else {
RuntimeArgs.Mqtt = false
}
}

// Check whether random forests are used
Expand Down

0 comments on commit 769aacd

Please sign in to comment.