This commit is contained in:
cxh 2025-12-30 09:19:59 +08:00
parent c382b0a3f4
commit d1de25f32c

View File

@ -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<std::string>();
}
else if (m["veh_id"].is_number_integer())
{
cfg.mqtt.vehicle_id = std::to_string(m["veh_id"].get<int>());
}
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);