tank information web server api endpoint
This commit is contained in:
parent
55ba52b798
commit
53bd1f8cce
@ -1,7 +1,8 @@
|
|||||||
//offer ota and config mode
|
//offer ota and config mode
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
get_version, log::LogMessage, map_range_moisture, plant_hal::PLANT_COUNT, BOARD_ACCESS,
|
determine_tank_state, get_version, log::LogMessage, map_range_moisture, plant_hal::PLANT_COUNT,
|
||||||
|
BOARD_ACCESS,
|
||||||
};
|
};
|
||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
@ -240,6 +241,18 @@ fn pump_test(
|
|||||||
anyhow::Ok(None)
|
anyhow::Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn tank_info(
|
||||||
|
_request: &mut Request<&mut EspHttpConnection>,
|
||||||
|
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||||
|
let mut board = BOARD_ACCESS.lock().unwrap();
|
||||||
|
let config = board.get_config()?;
|
||||||
|
let tank_info = determine_tank_state(&mut board, &config);
|
||||||
|
let water_temp = board.water_temperature_c();
|
||||||
|
Ok(Some(serde_json::to_string(
|
||||||
|
&tank_info.as_mqtt_info(&config.tank, water_temp),
|
||||||
|
)?))
|
||||||
|
}
|
||||||
|
|
||||||
fn night_lamp_test(
|
fn night_lamp_test(
|
||||||
request: &mut Request<&mut EspHttpConnection>,
|
request: &mut Request<&mut EspHttpConnection>,
|
||||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||||
@ -407,6 +420,11 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
|||||||
handle_error_to500(request, write_time)
|
handle_error_to500(request, write_time)
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
server
|
||||||
|
.fn_handler("/tank", Method::Get, |request| {
|
||||||
|
handle_error_to500(request, tank_info)
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
server
|
server
|
||||||
.fn_handler("/pumptest", Method::Post, |request| {
|
.fn_handler("/pumptest", Method::Post, |request| {
|
||||||
handle_error_to500(request, pump_test)
|
handle_error_to500(request, pump_test)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user