From 8bb0f1d001d9bc36c68379e817ad7ab5947cede1 Mon Sep 17 00:00:00 2001 From: cxh Date: Tue, 9 Sep 2025 10:25:16 +0800 Subject: [PATCH] first commit --- src/mqtt_client.cpp | 4 ++-- src/mqtt_client_wrapper.cpp | 28 +++++----------------------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/mqtt_client.cpp b/src/mqtt_client.cpp index 3b30ada..36966a7 100644 --- a/src/mqtt_client.cpp +++ b/src/mqtt_client.cpp @@ -103,11 +103,11 @@ void MQTTClient::subscribe(const std::string &topic, int qos) try { client_->subscribe(topic, qos)->wait(); - LOG_INFO("[MQTTClient] Subscribed to topic: " + topic); + LOG_INFO("[MQTT] Subscribed to topic: " + topic); } catch (const mqtt::exception &e) { - LOG_ERROR("[MQTTClient] Subscribe failed: " + std::string(e.what())); + LOG_ERROR("[MQTT] Subscribe failed: " + std::string(e.what())); if (!connected_) startReconnect(); } diff --git a/src/mqtt_client_wrapper.cpp b/src/mqtt_client_wrapper.cpp index d0f9b31..117d2be 100644 --- a/src/mqtt_client_wrapper.cpp +++ b/src/mqtt_client_wrapper.cpp @@ -30,36 +30,18 @@ static void on_mqtt_message_received(const std::string &topic, const std::string { if (topic == g_app_config.mqtt.topics.video_down) { - LOG_INFO("[MQTT] Step 1: parsing json"); + // 处理 video_down auto j = nlohmann::json::parse(message); - LOG_INFO("[MQTT] Step 2: checking data field"); - if (!j.contains("data")) + if (!j.contains("data") || !j["data"].contains("status")) { - LOG_WARN("[MQTT] missing data"); - return; - } - if (!j["data"].contains("status")) - { - LOG_WARN("[MQTT] missing status"); + LOG_WARN("[MQTT] video_down JSON missing data.status"); return; } int status = j["data"]["status"].get(); - LOG_INFO("[MQTT] Step 3: got status=" + std::to_string(status)); - // 处理 video_down - // auto j = nlohmann::json::parse(message); - - // if (!j.contains("data") || !j["data"].contains("status")) - // { - // LOG_WARN("[MQTT] video_down JSON missing data.status"); - // return; - // } - - // int status = j["data"]["status"].get(); - - if (status == 1) + if (status == 0) { // 启动推流:挂载本地配置中 enabled 的摄像头 for (const auto &cam : g_app_config.cameras) @@ -74,7 +56,7 @@ static void on_mqtt_message_received(const std::string &topic, const std::string } } } - else if (status == 0) + else if (status == 1) { // 停止推流:卸载本地配置中 enabled 的摄像头 for (const auto &cam : g_app_config.cameras)