From d1de25f32c9d65d729d5581f7ddfb2c6b093b66d Mon Sep 17 00:00:00 2001 From: cxh Date: Tue, 30 Dec 2025 09:19:59 +0800 Subject: [PATCH] 1 --- include/app_config.hpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/include/app_config.hpp b/include/app_config.hpp index f914431..5a041e2 100644 --- a/include/app_config.hpp +++ b/include/app_config.hpp @@ -117,7 +117,25 @@ struct AppConfig } auto& m = j["mqtt_server"]; - cfg.mqtt.vehicle_id = std::to_string(m.value("veh_id", 0)); + if (m.contains("veh_id")) + { + if (m["veh_id"].is_string()) + { + cfg.mqtt.vehicle_id = m["veh_id"].get(); + } + else if (m["veh_id"].is_number_integer()) + { + cfg.mqtt.vehicle_id = std::to_string(m["veh_id"].get()); + } + else + { + throw std::runtime_error("mqtt_server.veh_id must be string or integer"); + } + } + else + { + throw std::runtime_error("mqtt_server.veh_id missing"); + } cfg.mqtt.server_ip = m.value("address", ""); cfg.mqtt.server_port = m.value("port", 1883); cfg.mqtt.need_username_pwd = m.value("need_username_pwd", true);