allow parsing config with missing keys, added nightlamp config stuff, added nightlamp testing,
This commit is contained in:
@@ -54,6 +54,11 @@ pub struct WebBackupHeader{
|
||||
size: usize
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct NightLampCommand {
|
||||
active: bool
|
||||
}
|
||||
|
||||
fn write_time(
|
||||
request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
@@ -236,6 +241,16 @@ fn pump_test(
|
||||
anyhow::Ok(None)
|
||||
}
|
||||
|
||||
fn night_lamp_test(
|
||||
request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let actual_data = read_up_to_bytes_from_request(request, None)?;
|
||||
let light_command: NightLampCommand = serde_json::from_slice(&actual_data)?;
|
||||
let mut board = BOARD_ACCESS.lock().unwrap();
|
||||
board.light(light_command.active)?;
|
||||
anyhow::Ok(None)
|
||||
}
|
||||
|
||||
fn wifi_scan(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
@@ -399,6 +414,11 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
||||
handle_error_to500(request, pump_test)
|
||||
})
|
||||
.unwrap();
|
||||
server
|
||||
.fn_handler("/lamptest", Method::Post, |request| {
|
||||
handle_error_to500(request, night_lamp_test)
|
||||
})
|
||||
.unwrap();
|
||||
server
|
||||
.fn_handler("/boardtest", Method::Post, move |_| {
|
||||
BOARD_ACCESS.lock().unwrap().test()
|
||||
|
Reference in New Issue
Block a user