diff --git a/agent/config.toml b/agent/config.toml new file mode 100644 index 0000000..993df97 --- /dev/null +++ b/agent/config.toml @@ -0,0 +1,6 @@ +send_interval_seconds = 5 + +[mqtt] +agent = "agent-1" +host = "0.0.0.0" +port = 1883 diff --git a/agent/src/config.rs b/agent/src/config.rs new file mode 100644 index 0000000..c789412 --- /dev/null +++ b/agent/src/config.rs @@ -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 { + let file = std::fs::read_to_string(CONFIG_PATH)?; + let config: Config = toml::from_str(&file)?; + + Ok(config) +}