first commit
This commit is contained in:
parent
49e20e4f17
commit
75addb10ee
@ -85,7 +85,11 @@ void MQTTClient::publish(const std::string &topic, const std::string &payload, i
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
client_->publish(topic, payload.data(), payload.size(), qos, false)->wait_for(std::chrono::milliseconds(500));
|
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)
|
catch (const mqtt::exception &e)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -29,7 +29,7 @@ static void send_heartbeat()
|
|||||||
msg["type"] = 0;
|
msg["type"] = 0;
|
||||||
|
|
||||||
mqtt_client->publish(g_app_config.mqtt.topics.heartbeat_up, msg.dump());
|
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 回调定义
|
// MQTT 回调定义
|
||||||
@ -51,6 +51,7 @@ static void on_mqtt_disconnected()
|
|||||||
static void on_mqtt_message_received(const std::string &topic, const std::string &message)
|
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] Received message on topic [" + topic + "], len = " + std::to_string(message.size()));
|
||||||
|
LOG_INFO("[MQTT] Message content: " + message); // 打印实际内容
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user