Skip to content

Commit

Permalink
Add authtentication to MQTT
Browse files Browse the repository at this point in the history
  • Loading branch information
cblomart committed May 7, 2016
1 parent 5d54c01 commit 8171a93
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions zwaymqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var zway_password string
var zway_home string
var zway_refresh int
var mqtt_server string
var mqtt_username string
var mqtt_password string
var debug bool
var profile string

Expand Down Expand Up @@ -322,6 +324,8 @@ func init() {
flag.StringVar(&zway_password,"p","","Z-Way passsword")
flag.StringVar(&zway_home,"h","razberry","mqtt topic root")
flag.StringVar(&mqtt_server,"m","localhost:1883","MQTT server")
flag.StringVar(&mqtt_username,"mu","","MQTT username")
flag.StringVar(&mqtt_password,"mp","","MQTT password")
flag.IntVar(&zway_refresh,"r",30,"Z-Way refresh rate in seconds")
flag.BoolVar(&debug,"v",false,"Show debug messages")
flag.StringVar(&profile,"profile","","Profile execution (cpu/mem/all")
Expand Down Expand Up @@ -807,6 +811,10 @@ func main() {
opts.AddBroker("tcp://"+mqtt_server)
opts.SetClientID("ZWayMQTT")
opts.SetDefaultPublishHandler(f)
if len(mqtt_username) > 0 && len(mqtt_password) > 0 {
opts.SetUsername(mqtt_username)
opts.SetPassword(mqtt_password)
}

//Connect
mqtt := MQTT.NewClient(opts)
Expand Down

0 comments on commit 8171a93

Please sign in to comment.