add config for agent

This commit is contained in:
csehviktor
2025-07-03 06:08:41 +02:00
parent c83e5c86e0
commit dbbc673efe
2 changed files with 33 additions and 0 deletions

6
agent/config.toml Normal file
View File

@@ -0,0 +1,6 @@
send_interval_seconds = 5
[mqtt]
agent = "agent-1"
host = "0.0.0.0"
port = 1883

27
agent/src/config.rs Normal file
View File

@@ -0,0 +1,27 @@
use serde::{Deserialize, Serialize};
const CONFIG_PATH: &str = if cfg!(debug_assertions) {
"agent/config.toml"
} else {
"config.toml"
};
#[derive(Serialize, Deserialize)]
pub struct MqttConfig {
pub agent: String,
pub host: String,
pub port: u16,
}
#[derive(Serialize, Deserialize)]
pub struct Config {
pub send_interval_seconds: u64,
pub mqtt: MqttConfig,
}
pub fn load_config() -> anyhow::Result<Config> {
let file = std::fs::read_to_string(CONFIG_PATH)?;
let config: Config = toml::from_str(&file)?;
Ok(config)
}