mqtt
This commit is contained in:
parent
88ff6f8b16
commit
b38fa77a83
@ -1,14 +1,16 @@
|
||||
// app_config.hpp
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "logger.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
@ -39,8 +41,8 @@ struct VehicleMQTTTopics
|
||||
|
||||
void fill_with_veh_id(const std::string& vehId)
|
||||
{
|
||||
heartbeat_up = "/kun/vehicle/video/heartbeat/" + vehId;
|
||||
video_down = "/kun/vehicle/video/push/" + vehId;
|
||||
heartbeat_up = "/kun/vehicle/video/status/" + vehId;
|
||||
video_down = "/kun/vehicle/video/request/" + vehId;
|
||||
}
|
||||
};
|
||||
|
||||
@ -96,9 +98,8 @@ struct AppConfig
|
||||
cam.bitrate = c.value("bitrate", 2000000);
|
||||
cam.enabled = c.value("enabled", false);
|
||||
cfg.cameras.push_back(cam);
|
||||
LOG_INFO("[Config] Loaded camera: " + cam.name +
|
||||
" (" + cam.device + "), enabled=" + std::to_string(cam.enabled) +
|
||||
", bitrate=" + std::to_string(cam.bitrate));
|
||||
LOG_INFO("[Config] Loaded camera: " + cam.name + " (" + cam.device +
|
||||
"), enabled=" + std::to_string(cam.enabled) + ", bitrate=" + std::to_string(cam.bitrate));
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,13 +121,10 @@ struct AppConfig
|
||||
cfg.mqtt.keep_alive = m.value("mqtt_heart_threshold", 2000);
|
||||
cfg.mqtt.topics.fill_with_veh_id(cfg.mqtt.vehicle_id);
|
||||
|
||||
LOG_INFO("[Config] Loaded MQTT server: " + cfg.mqtt.server_ip +
|
||||
":" + std::to_string(cfg.mqtt.server_port));
|
||||
LOG_INFO("[Config] Loaded MQTT server: " + cfg.mqtt.server_ip + ":" + std::to_string(cfg.mqtt.server_port));
|
||||
LOG_INFO("[Config] MQTT client ID: " + cfg.mqtt.client_id);
|
||||
LOG_INFO("[Config] MQTT Credentials - username: " + cfg.mqtt.username +
|
||||
", password: " + cfg.mqtt.password);
|
||||
LOG_INFO("[Config] MQTT Topics: " + cfg.mqtt.topics.heartbeat_up + ", " +
|
||||
cfg.mqtt.topics.video_down);
|
||||
LOG_INFO("[Config] MQTT Credentials - username: " + cfg.mqtt.username + ", password: " + cfg.mqtt.password);
|
||||
LOG_INFO("[Config] MQTT Topics: " + cfg.mqtt.topics.heartbeat_up + ", " + cfg.mqtt.topics.video_down);
|
||||
LOG_INFO("[Config] MQTT keepAlive: " + std::to_string(cfg.mqtt.keep_alive));
|
||||
|
||||
return cfg;
|
||||
@ -158,8 +156,7 @@ inline std::string get_executable_dir()
|
||||
inline std::string get_executable_dir_file_path(const std::string& filename)
|
||||
{
|
||||
std::string dir = get_executable_dir();
|
||||
if (dir.back() != '/')
|
||||
dir += '/';
|
||||
if (dir.back() != '/') dir += '/';
|
||||
return dir + filename;
|
||||
}
|
||||
|
||||
|
||||
@ -58,12 +58,16 @@ static void send_heartbeat()
|
||||
|
||||
// 发布心跳
|
||||
mqtt_client->publish(g_app_config.mqtt.topics.heartbeat_up, hb.dump(), 0);
|
||||
LOG_INFO("[MQTT] Sent video heartbeat (" + std::to_string(running_count) + "/" + std::to_string(total) +
|
||||
" running): " + hb.dump());
|
||||
// LOG_INFO("[MQTT] Sent video heartbeat (" + std::to_string(running_count) + "/" + std::to_string(total) +
|
||||
// " running): " + hb.dump());
|
||||
}
|
||||
|
||||
// MQTT 回调
|
||||
static void on_mqtt_connected() { LOG_INFO("[MQTT] Connected to broker: " + g_app_config.mqtt.server_ip); }
|
||||
static void on_mqtt_connected()
|
||||
{
|
||||
LOG_INFO("[MQTT] Connected to broker: " + g_app_config.mqtt.server_ip);
|
||||
mqtt_client->subscribe(g_app_config.mqtt.topics.video_down)
|
||||
}
|
||||
|
||||
static void on_mqtt_disconnected() { LOG_WARN("[MQTT] Disconnected from broker: " + g_app_config.mqtt.server_ip); }
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user