Compare commits
4
Commits
b7273c1b1c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79db6107fd | ||
|
|
20a2a304e3 | ||
|
|
2072ca744c | ||
|
|
d4e1d53433 |
@@ -4,6 +4,7 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.45"
|
||||
rppal = "0.22.1"
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = "1.0.150"
|
||||
|
||||
+5
-1
@@ -1,7 +1,11 @@
|
||||
{
|
||||
"database": "./VEDirect.db",
|
||||
"device_name_voltage": "0xA10C-HQ2535PVZGE",
|
||||
"mode": "auto",
|
||||
"test_duration_seconds": 1,
|
||||
"time_off": "23:30",
|
||||
"time_on": "7:30",
|
||||
"time_use": true,
|
||||
"voltage_off": 23.0,
|
||||
"voltage_recover": 24.0
|
||||
"voltage_recover": 25.0
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 6.0 MiB After Width: | Height: | Size: 4.1 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 567 KiB |
+61
-2
@@ -7,6 +7,7 @@ use std::fs::File;
|
||||
use std::path::Path;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use chrono;
|
||||
|
||||
// Gpio uses BCM pin numbering. BCM GPIO 23 is tied to physical pin 16.
|
||||
const GPIO_SWITCH: u8 = 24;
|
||||
@@ -17,7 +18,11 @@ const GPIO_SWITCH: u8 = 24;
|
||||
struct Config{
|
||||
database: String,
|
||||
device_name_voltage: String,
|
||||
mode: String,
|
||||
test_duration_seconds: u64,
|
||||
time_on: String,
|
||||
time_off: String,
|
||||
time_use: bool,
|
||||
voltage_off: f32,
|
||||
voltage_recover: f32,
|
||||
}
|
||||
@@ -45,8 +50,14 @@ fn main () {
|
||||
pin_switch_off();
|
||||
return;
|
||||
},
|
||||
"status" => { println!("Inverter status: {}" , if pin_status() == 0 { "off" } else { "on" }); std::process::exit(0); },
|
||||
"test" => pin_test(config_file_path),
|
||||
"status" => {
|
||||
println!("Inverter status: {}" , if pin_status() == 0 { "off" } else { "on" });
|
||||
return;
|
||||
},
|
||||
"test" => {
|
||||
pin_test(config_file_path);
|
||||
return;
|
||||
},
|
||||
"config" => {
|
||||
if args.len() > n + 1 { config_file_path = args[n + 1].as_str(); }
|
||||
},
|
||||
@@ -54,10 +65,41 @@ fn main () {
|
||||
}
|
||||
}
|
||||
|
||||
// read and parse configuration file
|
||||
let config: Config = read_config(&config_file_path);
|
||||
|
||||
match config.mode.as_str() {
|
||||
"auto" => {
|
||||
println!("Running in automatic mode");
|
||||
let pin_status_cur = pin_status();
|
||||
let voltage = get_current_voltage(&config);
|
||||
|
||||
// turn inverter off based on time of day settings
|
||||
if config.time_use {
|
||||
let time_off = chrono::NaiveTime::parse_from_str(&config.time_off, "%H:%M").unwrap();
|
||||
let time_on = chrono::NaiveTime::parse_from_str(&config.time_on, "%H:%M").unwrap();
|
||||
let time_now = chrono::Local::now().time();
|
||||
|
||||
if time_off > time_on { // switch off at the same day
|
||||
if time_now < time_on || time_now > time_off {
|
||||
if pin_status() > 0 {
|
||||
println!("Off-time!");
|
||||
pin_switch_off();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if time_off < time_on { // switch off the next day
|
||||
if time_now < time_on && time_now > time_off {
|
||||
if pin_status() > 0 {
|
||||
println!("Off-time!");
|
||||
pin_switch_off();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if voltage < config.voltage_off && pin_status_cur > 0 {
|
||||
println!("Low voltage!");
|
||||
pin_switch_off();
|
||||
@@ -71,6 +113,23 @@ fn main () {
|
||||
let pin_status_text = if pin_status_cur == 0 { "off" } else { "on" };
|
||||
println!("No change in inverter status. Current status: {}", pin_status_text);
|
||||
}
|
||||
},
|
||||
"on" => {
|
||||
println!("Running in manual mode ON");
|
||||
if pin_status() == 0 {
|
||||
pin_switch_on();
|
||||
}
|
||||
return;
|
||||
},
|
||||
"off" => {
|
||||
println!("Running in manual mode OFF");
|
||||
if pin_status() > 0 {
|
||||
pin_switch_off();
|
||||
}
|
||||
return;
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
|
||||
//end program with OK status
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user