From 75addb10ee22a8b01b9d5e487fdf7dc73d352e9a Mon Sep 17 00:00:00 2001 From: cxh Date: Tue, 9 Sep 2025 17:19:59 +0800 Subject: [PATCH] first commit --- src/mqtt_client.cpp | 6 +++++- src/mqtt_client_wrapper.cpp | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mqtt_client.cpp b/src/mqtt_client.cpp index 36966a7..aec988c 100644 --- a/src/mqtt_client.cpp +++ b/src/mqtt_client.cpp @@ -85,7 +85,11 @@ void MQTTClient::publish(const std::string &topic, const std::string &payload, i try { client_->publish(topic, payload.data(), payload.size(), qos, false)->wait_for(std::chrono::milliseconds(500)); - LOG_INFO("[MQTT] Published message to topic: " + topic); + // 如果 topic 不包含 "heartbeat",才打印日志 + if (topic.find("heartbeat") == std::string::npos) + { + LOG_INFO("[MQTT] Published message to topic: " + topic); + } } catch (const mqtt::exception &e) { diff --git a/src/mqtt_client_wrapper.cpp b/src/mqtt_client_wrapper.cpp index 86e3020..12892a3 100644 --- a/src/mqtt_client_wrapper.cpp +++ b/src/mqtt_client_wrapper.cpp @@ -29,7 +29,7 @@ static void send_heartbeat() msg["type"] = 0; mqtt_client->publish(g_app_config.mqtt.topics.heartbeat_up, msg.dump()); - LOG_INFO("[MQTT] Sent heartbeat: " + msg.dump()); + // LOG_INFO("[MQTT] Sent heartbeat: " + msg.dump()); } // MQTT 回调定义 @@ -51,6 +51,7 @@ static void on_mqtt_disconnected() static void on_mqtt_message_received(const std::string &topic, const std::string &message) { LOG_INFO("[MQTT] Received message on topic [" + topic + "], len = " + std::to_string(message.size())); + LOG_INFO("[MQTT] Message content: " + message); // 打印实际内容 try {