config updates + adjustable timeout for pli
This commit is contained in:
parent
ab45b37497
commit
af67a1e678
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2256,7 +2256,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tesla-charge-controller"
|
||||
version = "0.1.17"
|
||||
version = "0.1.18"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"chrono",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "tesla-charge-controller"
|
||||
version = "0.1.17"
|
||||
version = "0.1.18"
|
||||
edition = "2021"
|
||||
license = "MITNFA"
|
||||
description = "Controls Tesla charge rate based on solar charge data"
|
||||
|
|
|
@ -4,8 +4,9 @@ use crate::types::Coords;
|
|||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Config {
|
||||
pub tesla_watch_interval: u64,
|
||||
pub pl_watch_interval: u64,
|
||||
pub tesla_watch_interval_seconds: u64,
|
||||
pub pl_watch_interval_seconds: u64,
|
||||
pub pl_timeout_milliseconds: u64,
|
||||
pub coords: Coords,
|
||||
pub serial_port: String,
|
||||
pub baud_rate: u32,
|
||||
|
@ -14,8 +15,9 @@ pub struct Config {
|
|||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
tesla_watch_interval: 120,
|
||||
pl_watch_interval: 30,
|
||||
tesla_watch_interval_seconds: 120,
|
||||
pl_watch_interval_seconds: 30,
|
||||
pl_timeout_milliseconds: 250,
|
||||
coords: Coords {
|
||||
latitude: 0.,
|
||||
longitude: 0.,
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -63,12 +63,16 @@ async fn main() {
|
|||
let (pli_requests, pli_receiver) = async_channel::unbounded();
|
||||
|
||||
// try to spawn the pli loop
|
||||
let pl_state = match Pli::new(config.serial_port.clone(), config.baud_rate) {
|
||||
let pl_state = match Pli::new(
|
||||
config.serial_port.clone(),
|
||||
config.baud_rate,
|
||||
config.pl_timeout_milliseconds,
|
||||
) {
|
||||
Ok(mut pli) => {
|
||||
let pl_state = pli.state.clone();
|
||||
tokio::task::spawn(async move {
|
||||
let mut interval = tokio::time::interval(
|
||||
std::time::Duration::from_secs(config.pl_watch_interval),
|
||||
std::time::Duration::from_secs(config.pl_watch_interval_seconds),
|
||||
);
|
||||
loop {
|
||||
tokio::select! {
|
||||
|
@ -99,7 +103,7 @@ async fn main() {
|
|||
// spawn the api loop
|
||||
tokio::task::spawn(async move {
|
||||
let mut interval = tokio::time::interval(std::time::Duration::from_secs(
|
||||
config.tesla_watch_interval,
|
||||
config.tesla_watch_interval_seconds,
|
||||
));
|
||||
loop {
|
||||
// await either the next interval OR a message from the other thread
|
||||
|
|
|
@ -123,9 +123,13 @@ pub enum PliRequest {
|
|||
}
|
||||
|
||||
impl Pli {
|
||||
pub fn new(serial_port: String, baud_rate: u32) -> Result<Self, serialport::Error> {
|
||||
pub fn new(
|
||||
serial_port: String,
|
||||
baud_rate: u32,
|
||||
timeout: u64,
|
||||
) -> Result<Self, serialport::Error> {
|
||||
let port = serialport::new(serial_port, baud_rate)
|
||||
.timeout(Duration::from_millis(250))
|
||||
.timeout(Duration::from_millis(timeout))
|
||||
.open()?;
|
||||
|
||||
describe_gauge!("pl_battery_voltage", "Battery voltage");
|
||||
|
|
Loading…
Reference in a new issue