allow startup with initial board mode and nearly no pin configs
This commit is contained in:
@@ -114,11 +114,9 @@ fn get_timezones(
|
||||
fn get_live_moisture(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.lock().unwrap();
|
||||
let config = board.get_config().unwrap();
|
||||
|
||||
let mut board = BOARD_ACCESS.lock().expect("Should never fail");
|
||||
let plant_state = Vec::from_iter(
|
||||
(0..PLANT_COUNT).map(|i| PlantState::read_hardware_state(i, &mut board, &config.plants[i])),
|
||||
(0..PLANT_COUNT).map(|i| PlantState::read_hardware_state(i, &mut board)),
|
||||
);
|
||||
let a = Vec::from_iter(
|
||||
plant_state
|
||||
@@ -159,11 +157,8 @@ fn get_live_moisture(
|
||||
fn get_config(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.lock().unwrap();
|
||||
let json = match board.get_config() {
|
||||
Ok(config) => serde_json::to_string(&config)?,
|
||||
Err(_) => serde_json::to_string(&PlantControllerConfig::default())?,
|
||||
};
|
||||
let board = BOARD_ACCESS.lock().expect("Should never fail");
|
||||
let json = serde_json::to_string(&board.config)?;
|
||||
anyhow::Ok(Some(json))
|
||||
}
|
||||
|
||||
@@ -193,7 +188,7 @@ fn get_backup_config(
|
||||
fn backup_info(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.lock().unwrap();
|
||||
let mut board = BOARD_ACCESS.lock().expect("Should never fail");
|
||||
let header = board.get_backup_info();
|
||||
let json = match header {
|
||||
Ok(h) => {
|
||||
@@ -222,7 +217,9 @@ fn set_config(
|
||||
let all = read_up_to_bytes_from_request(request, Some(3072))?;
|
||||
let config: PlantControllerConfig = serde_json::from_slice(&all)?;
|
||||
let mut board = BOARD_ACCESS.lock().unwrap();
|
||||
board.set_config(&config)?;
|
||||
board.esp.set_config(&config)?;
|
||||
|
||||
board.config = config;
|
||||
anyhow::Ok(Some("saved".to_owned()))
|
||||
}
|
||||
|
||||
@@ -268,12 +265,11 @@ 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 tank_info = determine_tank_state(&mut board);
|
||||
//should be multsampled
|
||||
let water_temp = board.water_temperature_c();
|
||||
Ok(Some(serde_json::to_string(
|
||||
&tank_info.as_mqtt_info(&config.tank, &water_temp),
|
||||
&tank_info.as_mqtt_info(&board.config.tank, &water_temp),
|
||||
)?))
|
||||
}
|
||||
|
||||
@@ -302,8 +298,8 @@ fn wifi_scan(
|
||||
fn list_files(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let board = BOARD_ACCESS.lock().unwrap();
|
||||
let result = board.list_files();
|
||||
let board = BOARD_ACCESS.lock().expect("It should be possible to lock the board for exclusive fs access");
|
||||
let result = board.esp.list_files();
|
||||
let file_list_json = serde_json::to_string(&result)?;
|
||||
anyhow::Ok(Some(file_list_json))
|
||||
}
|
||||
@@ -493,6 +489,7 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
||||
let file_handle = BOARD_ACCESS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.esp
|
||||
.get_file_handle(&filename, false);
|
||||
match file_handle {
|
||||
Ok(mut file_handle) => {
|
||||
@@ -529,7 +526,7 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
||||
.fn_handler("/file", Method::Post, move |mut request| {
|
||||
let filename = query_param(request.uri(), "filename").unwrap();
|
||||
let lock = BOARD_ACCESS.lock().unwrap();
|
||||
let file_handle = lock.get_file_handle(&filename, true);
|
||||
let file_handle = lock.esp.get_file_handle(&filename, true);
|
||||
match file_handle {
|
||||
//TODO get free filesystem size, check against during write if not to large
|
||||
Ok(mut file_handle) => {
|
||||
@@ -573,7 +570,7 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
||||
let filename = query_param(request.uri(), "filename").unwrap();
|
||||
let copy = filename.clone();
|
||||
let board = BOARD_ACCESS.lock().unwrap();
|
||||
match board.delete_file(&filename) {
|
||||
match board.esp.delete_file(&filename) {
|
||||
Ok(_) => {
|
||||
let info = format!("Deleted file {copy}");
|
||||
cors_response(request, 200, &info)?;
|
||||
|
Reference in New Issue
Block a user