Mqtt logging
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user