Mqtt logging
Some checks failed
CI / Test (1.22) (push) Failing after -23m38s
CI / Test (1.23) (push) Failing after -23m28s
CI / Build (push) Successful in -25m46s
CI / Lint (push) Successful in -25m30s

This commit is contained in:
2025-12-30 00:19:49 +02:00
parent eb788f903a
commit 7b2390cbf6
2 changed files with 4 additions and 1 deletions

View File

@@ -82,16 +82,18 @@ func NewMQTTTarget(cfg config.MQTTConfig, waManager WhatsAppManager) (*MQTTTarge
if cfg.Subscribe {
// Subscribe to send command topic for all accounts
topic := fmt.Sprintf("%s/+/send", cfg.TopicPrefix)
logging.Info("Starting MQTT subscription", "topic", topic, "qos", cfg.QoS)
if token := client.Subscribe(topic, byte(cfg.QoS), target.handleSendMessage); token.Wait() && token.Error() != nil {
logging.Error("Failed to subscribe to MQTT topic", "topic", topic, "error", token.Error())
} else {
logging.Info("Subscribed to MQTT send topic", "topic", topic)
logging.Info("Successfully subscribed to MQTT send topic", "topic", topic)
}
}
})
// Create and connect the client
client := mqtt.NewClient(opts)
logging.Info("Starting MQTT connection", "broker", cfg.Broker, "client_id", cfg.ClientID)
if token := client.Connect(); token.Wait() && token.Error() != nil {
return nil, fmt.Errorf("failed to connect to MQTT broker: %w", token.Error())
}