added solar ina handling, adjusted website
This commit is contained in:
@@ -40,6 +40,13 @@ struct Moistures {
|
||||
moisture_b: Vec<std::string::String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
struct SolarState {
|
||||
mppt_voltage: f32,
|
||||
mppt_current: f32,
|
||||
is_day: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct SetTime<'a> {
|
||||
time: &'a str,
|
||||
@@ -218,6 +225,18 @@ fn set_config(
|
||||
anyhow::Ok(Some("saved".to_owned()))
|
||||
}
|
||||
|
||||
fn get_solar_state(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.lock().expect("board access");
|
||||
let state = SolarState {
|
||||
mppt_voltage: board.board_hal.get_mptt_voltage()?.as_volts() as f32,
|
||||
mppt_current: board.board_hal.get_mptt_current()?.as_amperes() as f32,
|
||||
is_day: board.board_hal.is_day(),
|
||||
};
|
||||
anyhow::Ok(Some(serde_json::to_string(&state)?))
|
||||
}
|
||||
|
||||
fn get_battery_state(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
@@ -383,6 +402,11 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
||||
handle_error_to500(request, get_battery_state)
|
||||
})
|
||||
.unwrap();
|
||||
server
|
||||
.fn_handler("/solar", Method::Get, |request| {
|
||||
handle_error_to500(request, get_solar_state)
|
||||
})
|
||||
.unwrap();
|
||||
server
|
||||
.fn_handler("/time", Method::Get, |request| {
|
||||
handle_error_to500(request, get_time)
|
||||
|
||||
Reference in New Issue
Block a user