Print out ClientID
This commit is contained in:
@@ -54,6 +54,7 @@ func main() {
|
|||||||
opts.SetUsername(mqttUser)
|
opts.SetUsername(mqttUser)
|
||||||
opts.SetPassword(mqttPass)
|
opts.SetPassword(mqttPass)
|
||||||
opts.SetClientID(fmt.Sprintf("mqtt_presence_redis_go_%s", randomString()))
|
opts.SetClientID(fmt.Sprintf("mqtt_presence_redis_go_%s", randomString()))
|
||||||
|
// clientID variable removed; use opts.ClientID directly
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
opts.SetDefaultPublishHandler(func(client mqtt.Client, msg mqtt.Message) {
|
opts.SetDefaultPublishHandler(func(client mqtt.Client, msg mqtt.Message) {
|
||||||
@@ -64,7 +65,7 @@ func main() {
|
|||||||
if token := c.Subscribe(mqttTopicPresence, 0, nil); token.Wait() && token.Error() != nil {
|
if token := c.Subscribe(mqttTopicPresence, 0, nil); token.Wait() && token.Error() != nil {
|
||||||
log.Fatalf("Failed to subscribe: %v", token.Error())
|
log.Fatalf("Failed to subscribe: %v", token.Error())
|
||||||
}
|
}
|
||||||
log.Printf("Connected to MQTT broker %s:%s, subscribed to %s", mqttHost, mqttPort, mqttTopicPresence)
|
log.Printf("Connected to MQTT broker %s:%s, subscribed to %s, client ID: %s", mqttHost, mqttPort, mqttTopicPresence, opts.ClientID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and start client
|
// Create and start client
|
||||||
|
|||||||
Reference in New Issue
Block a user