Add renogy bp

This commit is contained in:
KenwoodFox
2026-06-15 15:06:21 -04:00
parent ee02bf99cf
commit 49618f0c0a
10 changed files with 576 additions and 1 deletions

View File

@@ -7,6 +7,16 @@ pub struct Config {
pub poll_interval_s: f64,
pub thermal_alarm_temp_c: f64,
pub influx: Option<InfluxConfig>,
pub renogy: RenogyConfig,
}
#[derive(Debug, Clone)]
pub struct RenogyConfig {
pub serial_path: Option<String>,
pub slave_address: u8,
pub baud_rate: u32,
pub poll_interval_s: f64,
pub timeout_ms: u64,
}
#[derive(Debug, Clone)]
@@ -29,6 +39,31 @@ impl Default for Config {
poll_interval_s: 2.0,
thermal_alarm_temp_c: 80.0,
influx: InfluxConfig::from_env(),
renogy: RenogyConfig::from_env(),
}
}
}
impl RenogyConfig {
pub fn from_env() -> Self {
Self {
serial_path: std::env::var("TOWERD_RENOGY_SERIAL").ok(),
slave_address: std::env::var("TOWERD_RENOGY_SLAVE")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(crate::renogy::registers::SLAVE_ADDRESS_DEFAULT),
baud_rate: std::env::var("TOWERD_RENOGY_BAUD")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(crate::renogy::registers::BAUD_RATE),
poll_interval_s: std::env::var("TOWERD_RENOGY_INTERVAL_S")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(10.0),
timeout_ms: std::env::var("TOWERD_RENOGY_TIMEOUT_MS")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(1000),
}
}
}