fix mppt to not self destruct, log output

This commit is contained in:
2025-02-19 22:01:26 +01:00
parent aad1dbd458
commit 936c52e0e7
4 changed files with 218 additions and 241 deletions

View File

@@ -207,6 +207,13 @@ fn get_battery_state(
anyhow::Ok(Some(battery_json))
}
fn get_log(
_request: &mut Request<&mut EspHttpConnection>,
) -> Result<Option<std::string::String>, anyhow::Error> {
let output = crate::log::get_log();
anyhow::Ok(Some(serde_json::to_string(&output)?))
}
fn get_version_web(
_request: &mut Request<&mut EspHttpConnection>,
) -> Result<Option<std::string::String>, anyhow::Error> {
@@ -354,6 +361,11 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
handle_error_to500(request, get_version_web)
})
.unwrap();
server
.fn_handler("/log", Method::Get, |request| {
handle_error_to500(request, get_log)
})
.unwrap();
server
.fn_handler("/battery", Method::Get, |request| {
handle_error_to500(request, get_battery_state)