adust pcb to new 3.3 software improvements
This commit is contained in:
2050
rust/src/webserver/bootstrap-grid.css
vendored
Normal file
2050
rust/src/webserver/bootstrap-grid.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,9 @@ use std::{
|
||||
sync::{atomic::AtomicBool, Arc},
|
||||
};
|
||||
|
||||
use crate::{espota::OtaUpdate, map_range_moisture, plant_hal::FileInfo, BOARD_ACCESS};
|
||||
use crate::{
|
||||
espota::OtaUpdate, get_version, map_range_moisture, plant_hal::FileInfo, BOARD_ACCESS,
|
||||
};
|
||||
use anyhow::bail;
|
||||
use chrono::DateTime;
|
||||
use core::result::Result::Ok;
|
||||
@@ -29,12 +31,6 @@ struct FileList {
|
||||
file: Vec<FileInfo>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
struct VersionInfo<'a> {
|
||||
git_hash: &'a str,
|
||||
build_time: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
struct LoadData<'a> {
|
||||
rtc: &'a str,
|
||||
@@ -158,17 +154,19 @@ fn set_config(
|
||||
anyhow::Ok(Some("saved".to_owned()))
|
||||
}
|
||||
|
||||
fn get_version(
|
||||
fn get_battery_state(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let branch = env!("VERGEN_GIT_BRANCH").to_owned();
|
||||
let hash = &env!("VERGEN_GIT_SHA")[0..8];
|
||||
|
||||
let version_info: VersionInfo<'_> = VersionInfo {
|
||||
git_hash: &(branch + "@" + hash),
|
||||
build_time: env!("VERGEN_BUILD_TIMESTAMP"),
|
||||
};
|
||||
anyhow::Ok(Some(serde_json::to_string(&version_info)?))
|
||||
let mut board = BOARD_ACCESS.lock().unwrap();
|
||||
let battery_state = board.get_battery_state();
|
||||
let battery_json = serde_json::to_string(&battery_state)?;
|
||||
anyhow::Ok(Some(battery_json))
|
||||
}
|
||||
|
||||
fn get_version_web(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
anyhow::Ok(Some(serde_json::to_string(&get_version())?))
|
||||
}
|
||||
|
||||
fn pump_test(
|
||||
@@ -296,10 +294,14 @@ pub fn httpd(_reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
||||
Box::new(EspHttpServer::new(&server_config).unwrap());
|
||||
server
|
||||
.fn_handler("/version", Method::Get, |request| {
|
||||
handle_error_to500(request, get_version)
|
||||
handle_error_to500(request, get_version_web)
|
||||
})
|
||||
.unwrap();
|
||||
server
|
||||
.fn_handler("/battery", Method::Get, |request| {
|
||||
handle_error_to500(request, get_battery_state)
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
server
|
||||
.fn_handler("/time", Method::Get, |request| {
|
||||
handle_error_to500(request, get_data)
|
||||
@@ -505,13 +507,13 @@ pub fn httpd(_reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
||||
})
|
||||
.unwrap();
|
||||
server
|
||||
.fn_handler("/bootstrap-grid.css", Method::Get, |request| {
|
||||
request
|
||||
.into_ok_response()?
|
||||
.write(include_bytes!("bootstrap-grid.css"))?;
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
.fn_handler("/bootstrap-grid.css", Method::Get, |request| {
|
||||
request
|
||||
.into_ok_response()?
|
||||
.write(include_bytes!("bootstrap-grid.css"))?;
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
server
|
||||
}
|
||||
|
||||
@@ -522,7 +524,7 @@ fn cors_response(
|
||||
) -> Result<(), anyhow::Error> {
|
||||
let headers = [
|
||||
("Access-Control-Allow-Origin", "*"),
|
||||
("Access-Control-Allow-Headers", "*")
|
||||
("Access-Control-Allow-Headers", "*"),
|
||||
];
|
||||
let mut response = request.into_response(status, None, &headers)?;
|
||||
response.write(body.as_bytes())?;
|
||||
|
Reference in New Issue
Block a user