Compare commits
1 Commits
1.0.1
...
8b5a462fc4
| Author | SHA1 | Date | |
|---|---|---|---|
| 8b5a462fc4 |
15
central_backend/Cargo.lock
generated
15
central_backend/Cargo.lock
generated
@@ -492,9 +492,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.90"
|
version = "1.0.89"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "37bf3594c4c988a53154954629820791dde498571819ae4ca50ca811e060cc95"
|
checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "asn1"
|
name = "asn1"
|
||||||
@@ -670,7 +670,6 @@ dependencies = [
|
|||||||
"bincode",
|
"bincode",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
"dotenvy",
|
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"foreign-types-shared",
|
"foreign-types-shared",
|
||||||
"fs4",
|
"fs4",
|
||||||
@@ -998,12 +997,6 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dotenvy"
|
|
||||||
version = "0.15.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "encode_unicode"
|
name = "encode_unicode"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
@@ -2305,9 +2298,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.129"
|
version = "1.0.131"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6dbcf9b78a125ee667ae19388837dd12294b858d101fdd393cb9d5501ef09eb2"
|
checksum = "67d42a0bd4ac281beff598909bb56a86acaf979b84483e1c79c10dcaf98f8cf3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ edition = "2021"
|
|||||||
log = "0.4.22"
|
log = "0.4.22"
|
||||||
env_logger = "0.11.5"
|
env_logger = "0.11.5"
|
||||||
lazy_static = "1.5.0"
|
lazy_static = "1.5.0"
|
||||||
dotenvy = "0.15.7"
|
|
||||||
clap = { version = "4.5.20", features = ["derive", "env"] }
|
clap = { version = "4.5.20", features = ["derive", "env"] }
|
||||||
anyhow = "1.0.89"
|
anyhow = "1.0.89"
|
||||||
thiserror = "1.0.64"
|
thiserror = "1.0.64"
|
||||||
|
|||||||
@@ -39,12 +39,8 @@ pub enum ConsumptionBackend {
|
|||||||
/// Fronius inverter consumption
|
/// Fronius inverter consumption
|
||||||
Fronius {
|
Fronius {
|
||||||
/// The origin of the domain where the webserver of the Fronius Symo can be reached
|
/// The origin of the domain where the webserver of the Fronius Symo can be reached
|
||||||
#[clap(short, long, env)]
|
#[clap(short, long, env = "FRONIUS_ORIG")]
|
||||||
fronius_orig: String,
|
origin: String,
|
||||||
|
|
||||||
/// Use cURL instead of reqwest to perform request
|
|
||||||
#[clap(short, long)]
|
|
||||||
curl: bool,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ pub enum ConsumptionError {
|
|||||||
NonExistentFile,
|
NonExistentFile,
|
||||||
#[error("The file that should contain the consumption has an invalid content!")]
|
#[error("The file that should contain the consumption has an invalid content!")]
|
||||||
FileInvalidContent(#[source] ParseIntError),
|
FileInvalidContent(#[source] ParseIntError),
|
||||||
#[error("Failed to execute cURL request!")]
|
|
||||||
CurlReqFailed,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type EnergyConsumption = i32;
|
pub type EnergyConsumption = i32;
|
||||||
@@ -65,21 +63,9 @@ pub async fn get_curr_consumption() -> anyhow::Result<EnergyConsumption> {
|
|||||||
.map_err(ConsumptionError::FileInvalidContent)?)
|
.map_err(ConsumptionError::FileInvalidContent)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsumptionBackend::Fronius { fronius_orig, curl } => {
|
ConsumptionBackend::Fronius { origin } => {
|
||||||
let url = format!("{fronius_orig}/solar_api/v1/GetPowerFlowRealtimeData.fcgi");
|
let url = format!("{origin}/solar_api/v1/GetPowerFlowRealtimeData.fcgi");
|
||||||
|
let response = reqwest::get(url).await?.json::<FroniusResponse>().await?;
|
||||||
let response = match curl {
|
|
||||||
false => reqwest::get(url).await?.json::<FroniusResponse>().await?,
|
|
||||||
true => {
|
|
||||||
let res = std::process::Command::new("curl").arg(url).output()?;
|
|
||||||
|
|
||||||
if !res.status.success() {
|
|
||||||
return Err(ConsumptionError::CurlReqFailed.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
serde_json::from_slice::<FroniusResponse>(&res.stdout)?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(response.body.data.site.grid_production as i32)
|
Ok(response.body.data.site.grid_production as i32)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ FRONIUS_ORIG=http://10.0.0.10
|
|||||||
Run the following command to check if the configuration is working:
|
Run the following command to check if the configuration is working:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo -u central central_backend -c /home/central/config.yaml fronius -c
|
sudo -u central central_backend -c /home/central/config.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create systemd unit file
|
### Create systemd unit file
|
||||||
@@ -109,7 +109,7 @@ Type=simple
|
|||||||
User=central
|
User=central
|
||||||
Group=central
|
Group=central
|
||||||
WorkingDirectory=/home/central
|
WorkingDirectory=/home/central
|
||||||
ExecStart=/usr/local/bin/central_backend -c /home/central/config.yaml fronius -c
|
ExecStart=/usr/local/bin/central_backend -c /home/central/config.yaml
|
||||||
Restart=always
|
Restart=always
|
||||||
Environment=USER=central
|
Environment=USER=central
|
||||||
HOME=/home/central
|
HOME=/home/central
|
||||||
|
|||||||
Reference in New Issue
Block a user