Print out ClientID

This commit is contained in:
2026-02-02 14:13:17 +07:00
parent 7f298edf60
commit c2ce10fe15

View File

@@ -54,6 +54,7 @@ func main() {
opts.SetUsername(mqttUser)
opts.SetPassword(mqttPass)
opts.SetClientID(fmt.Sprintf("mqtt_presence_redis_go_%s", randomString()))
// clientID variable removed; use opts.ClientID directly
// Handlers
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 {
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