This commit is contained in:
2025-10-04 01:24:00 +02:00
parent 27b18df78e
commit 0ddf6a6886
30 changed files with 2863 additions and 81 deletions

View File

@@ -118,7 +118,7 @@ where
let mut offset = 0_usize;
let mut chunk = 0;
loop {
let mut buf = [0_u8; 1024];
let mut buf = [0_u8; 4096];
let to_write = conn.read(&mut buf).await?;
if to_write == 0 {
info!("file request for {} finished", filename);

View File

@@ -1,3 +1,4 @@
use core::str::FromStr;
use crate::fat_error::{FatError, FatResult};
use crate::hal::{esp_time, PLANT_COUNT};
use crate::log::LogMessage;
@@ -8,9 +9,9 @@ use alloc::format;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use chrono_tz::Tz;
use core::str::FromStr;
use edge_http::io::server::Connection;
use embedded_io_async::{Read, Write};
use log::info;
use serde::Serialize;
#[derive(Serialize, Debug)]
@@ -139,7 +140,24 @@ pub(crate) async fn get_time<T, const N: usize>(
) -> FatResult<Option<String>> {
let mut board = BOARD_ACCESS.get().await.lock().await;
let conf = board.board_hal.get_config();
let tz = Tz::from_str(conf.timezone.as_ref().unwrap().as_str()).unwrap();
let tz:Tz = match conf.timezone.as_ref(){
None => {
Tz::UTC
}
Some(tz_string) => {
match Tz::from_str(tz_string) {
Ok(tz) => {
tz
}
Err(err) => {
info!("failed parsing timezone {}", err);
Tz::UTC
}
}
}
};
let native = esp_time().await.with_timezone(&tz).to_rfc3339();
let rtc = match board.board_hal.get_rtc_module().get_rtc_time().await {

View File

@@ -36,7 +36,7 @@ use edge_nal_embassy::{Tcp, TcpBuffers};
use embassy_net::Stack;
use embassy_time::Instant;
use embedded_io_async::{Read, Write};
use log::info;
use log::{error, info};
use crate::webserver::ota::ota_operations;
// fn ota(
// request: &mut Request<&mut EspHttpConnection>,
@@ -109,7 +109,11 @@ impl Handler for HTTPRequestRouter {
let status = if path.starts_with(prefix) {
file_operations(conn, method, &path, &prefix).await?
} else if path == "/ota" {
ota_operations(conn,method).await?
ota_operations(conn,method).await.map_err(|e| {
error!("Error handling ota: {}", e);
e
}
)?
} else {
match method {
Method::Get => match path {

View File

@@ -1,5 +1,3 @@
use alloc::borrow::ToOwned;
use alloc::format;
use edge_http::io::server::Connection;
use edge_http::Method;
use embedded_io_async::{Read, Write};
@@ -31,6 +29,9 @@ where
Method::Post => {
let mut offset = 0_usize;
let mut chunk = 0;
// Erase only a single 4K block right before writing into it.
// The first block will be erased when offset == 0 below.
loop {
let mut buf = [0_u8; 1024];
let to_write = conn.read(&mut buf).await?;
@@ -42,6 +43,11 @@ where
} else {
let mut board = BOARD_ACCESS.get().await.lock().await;
board.board_hal.progress(chunk as u32).await;
// Erase next block if we are at a 4K boundary (including the first block at offset 0)
if offset % 4096 >= offset+to_write % 4096 {
info!("erasing block {} during write between {} with size {}", offset / 4096, offset, to_write);
board.board_hal.get_esp().ota_erase(offset as u32).await?;
}
board
.board_hal
.get_esp()

View File

@@ -108,5 +108,5 @@ where
board.board_hal.get_esp().save_config(all).await?;
info!("Wrote config config {:?} with size {}", config, length);
board.board_hal.set_config(config);
Ok(Some("saved".to_string()))
Ok(Some("Ok".to_string()))
}