first commit

This commit is contained in:
cxh 2025-09-09 10:25:16 +08:00
parent 0791ad07a0
commit 8bb0f1d001
2 changed files with 7 additions and 25 deletions

View File

@ -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();
}

View File

@ -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<int>();
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<int>();
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)